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)