如何避免索引失效
-
如果条件中有or,即使其中有条件带索引也不会使用
-
如果查询条件有到 like ‘%str’,%开头的 索引会失效
如果要挽救一部分索引可以使用索引覆盖,比如,select tname from user where tname like ‘%rechar%’;
- 复合索引,避免跨列或无序使用
符合索引 index_a_b_c(a, b, c)
如 select * from tname where a = 2 and c = 3 and b = '123';
-
不要在索引上做任何操作(计算,函数,类型转换)
-
复合索引不能使用不等于(!= <>),is null ,is not null, 否则自身及右侧的索引都会失效