![](http://static.javashuo.com/static/loading.gif)
一、若是條件中有or,即便其中有條件帶索引也不會使用(這也是爲何儘可能少使用or的緣由)
![](http://static.javashuo.com/static/loading.gif)
注意:要想使用or,又想讓索引生效,只能將or條件中的每一個列都加上索引優化
二、對於多列索引,不是使用的第一部分,則不會使用索引
三、like查詢的是以%開頭
![](http://static.javashuo.com/static/loading.gif)
四、若是列類型是字符串,那必定要在條件中將數據使用引號引發來,不然不會走索引
![](http://static.javashuo.com/static/loading.gif)
五、若是MySQL內部優化器優化後估計使用全表掃描比使用索引塊,則不使用索引
查看索引使用的狀況:spa
SHOW STATUS3d
![](http://static.javashuo.com/static/loading.gif)
注意:
handler_read_key:這個值越高越好,越高表示使用索引查詢到的次數
handler_read_rnd_next:這個值越高,說明查詢低效
參考博客:blog
https://www.cnblogs.com/itsharehome索引