SQL 哪些情况会使索引失效

 

1、前导like
-- 生效
explain select * from cartoon where `name` like '家里来了位道长大人%'
-- 不生效
explain select * from cartoon where `name` like '%555%'
2、”or”条件
3、“in”条件
4、”<>”条件
5、”between” 范围条件,可使用where xx>1 and xx<3 替代
6、is null 或者 is not null,判断为空
7、不能在索引上做任何操作(计算、函数、自动/手动类型转换)

 

posted @ 2021-06-22 22:31  雁书几封  阅读(659)  评论(0编辑  收藏  举报