索引失效

索引失效可能原因:

  1、当查询条件字段类型与sql类型不匹配。

    例如:a.x 字段类型为varchar类型

       错误:select *from a where a.x = 123

         正确:select *from a where a.x = '123'

  2、当所查询数据量大于该表数据量30%时,索引失效。

  3、当在索引列进行运算操作时,包括+、-、*、/、!、not in、not exist函数等,索引失效,此时可对该运算建立索引,CREATE INDEX index_name ON table_name (sum(num))

    例如:select *from a where a.x-1=9

  4、当模糊查询时,like '%_',百分号在前时索引失效,此时会使用全表扫描。要想达到目的,可用翻转函数 reverse()先对字段进行翻转,然后使用 like '__%'

  5、未完待续

 

原文地址:https://www.cnblogs.com/lansetuerqi/p/5395468.html