代码优化总结

最近一个功能查询缓慢达到一分钟,于是设法优化,最终优化到8秒内。

总结:优化代码主要从这几个部分优化:

1.sql

2.代码

3.数据

4.索引

 

<!--[if !supportLists]-->1.      <!--[endif]-->通过sql explain 查看执行计划,哪些没有用到索引,哪部分sql执行缓慢,仔细定位

<!--[if !supportLists]-->2.      <!--[endif]-->优化sql尽量少用子查询,用join

<!--[if !supportLists]-->3.      <!--[endif]-->通过加索引来看是否速度加快

<!--[if !supportLists]-->4.      <!--[endif]-->如果不行再看是否是其他作用的代码拖累了这个查询

<!--[if !supportLists]-->5.      <!--[endif]-->如果没有以上问题,查看数据是否有产生垃圾数据,导致数据膨胀

<!--[if !supportLists]-->6.      <!--[endif]-->再查看代码看是什么原因导致产生垃圾数据

<!--[if !supportLists]-->7.      <!--[endif]-->Mysql left join不走索引的注意这个问题

猜你喜欢

转载自weihong01267.iteye.com/blog/2328699