Mysql引起索引失效的原因总结,mysql索引失效总结
http://blog.csdn.net/hehexiaoxia/article/details/54312130
在数据库中做查询等操作,经常发现查询很慢,但是已经在列上建了索引,最后经过研究发现,很多种情况引起了索引失效。
下面就对遇到的引起索引失效的原因做一下总结(不包括索引本身无效的情况),欢迎博友们补充。
1、对单字段建了索引,where条件多字段。
例:建了以下索引:
查询语句:
[html] view plain copy- select * from template t where t.logicdb_id = 4 and t.sync_status = 1
例:建了以下索引:
查询语句:
[html] view plain copy- select * from template t where t.sync_status = 4
4、类型错误,如字段类型为varchar,where条件用number。
例:template_id字段是varchar类型。
错误写法:select * from template t where t.template_id = 1
正确写法:select * from template t where t.template_id = '1'
5、对索引应用内部函数,这种情况下应该建立基于函数的索引。
例:
[html] view plain copy- select * from template t where ROUND(t.logicdb_id) = 1
6、查询表的效率要比应用索引查询快的时候。
7、is null 索引失效;is not null Betree索引生效。导致的原因,个人认为应该是,mysql没有在null写进索引。还要看应用的数据库而定。
查看评论
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。