啥时走

  • 判断(理解为集合操作),如<,<=,=,>,>=,BETWEEN,IN,以及某些时候的LIKE会走索引(!=不走)

啥时不走

  • !=
  • >/<修饰符后面的所有字段
  • like
    %在前面不走索引,在后面走索引
    所以A走索引、B不走索引
    A:select * from student where 'name' like '王%'
    B:select * from student where 'name' like '%小'
    索引列计算(如where age + 1 = 2)

所以需要注意什么?

  • 尽量不要用select *,因为不会走索引
  • 使用join代替子查询
  • 数据结果重复多的不适合当索引(如性别,都为男或女)

https://blog.csdn.net/liutong123987/article/details/79384395