1.一般在Where语句后面使用了null会导致索引查询失效。例如(where name is null;) 用0代替
2.<>或!=也会导致索引失效,例如(where name<>13);用name>13 and name<13
3.or也会导致索引查询失效,select name from employ where id=1 union all select name from employ where id =2
4.in not in也尽量少用,同样会导致索引失效,可以改成betweende 形式
5.like同上面一样也会导致索引失效
6.尽量不要对where后面的字段进行表达式操作,例如:where age/2>13;应该改成where age >13*2的形式
7.where substring(name,1,3)='abc'没有where name like 'abc%'更高效,带有函数的操作比较慢
8.很多时候用 exists 代替 in 是一个好的选择:
select num from a where num in(select num from b) 用下面的语句替换: select num from a where exists(select 1 from b where num=a.num)