sql語句中索引失效的幾種情況


sql語句中索引失效的幾種情況(默認uname是索引列)

  1. 模糊查詢中,like的前置%不會走索引
    eg:select * from user where uname like '%凡凡';
  2. where條件中的or語句:
    eg: select * from user where uname = '小明' or uname = '小紅';
    解決辦法:使用 union、union all 語句。
    eg:
    select * from user where uname = '小明'
    union all
    select * from user where uname = '小紅'
  3. where條件中的 in 和not in
    eg: select * from user where uname in ('小明','小紅','凡凡');
    解決辦法:若是連續值采用 between語句
    eg: select * from user where uname between '小明' and '小紅';
  4. where條件中的is null和is not null
    eg: select * from user where uname is null;
  5. where條件中"!="和"<"or">"
  6. 對索引列進行運算。這里運算包括+、-、*、/等運算。也包括使用函數。
    select * from temp where amount+count>10 此時索引不起作用。
    select * from temp where round(amount)>10 此時索引也不起作用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM