索引失效的情况总结

  • A、B两列均存在索引,但 select * from T where A=B;不会走索引,因为全表扫描更快。
  • 存在null值,索引列可空,则不会给其建索引,索引值少于表count值,执行计划会去扫全表,比如 select * from T where id is not null;
  • 反查询,索引定位困难,执行计划更倾向于全表扫描。比如 <>、not in、not exists。
  • 条件包含了函数不会走索引,因为索引在建立时和计算后不同,无法定位索引。 比如 select * from T where upper(name) = "SSS"; 这时可以优化为 select * from T where name = 'sss';
  • 隐式类型转换,比如 select * from T where id = '123';

以上参考:https://mp.weixin.qq.com/s/JJcDr6jNs7I-RTjUzTAt7g

posted @ 2021-04-05 23:55  smallzhen  阅读(89)  评论(0编辑  收藏  举报