MySQL 索引下推:
当进行索引查询时,首先根据索引来查找记录,然后再根据where条件来过滤记录;在支持ICP优化后,MySQL会在取出索引的同时,判断是否可以进行where条件过滤再进行索引查询,也就是说提前执行where的部分过滤操作。
explain 查询MySQL索引字段时,extra字段说明
Using where;Using index
Using index :没有进行全表扫描;
Using where : 使用了过滤;
如果是在有索引的情况下(该列有索引),那么它的作用和Using index condition
是相似的;
其他情况:
- 有索引参加、需要过滤
- 没有索引参数、需要过滤
Using index condition
使用了索引下推;使用了索引,并且对所以进行了过滤。
网友理解:
首先 mysql server
和 storage engine
是两个组件:
- server 负责 sql的parse, 执行;
- storage engine 去真正的 做 数据/index的 读取/写入.
以前是这样: server 命令 storage engine 按 index 把相应的 数据 从 数据表读出, 传给server, server来按 where条件 做选择;
现在 ICP则是在 可能的情况下, 让storage engine 根据index 做判断, 如果不符合 条件 则无须 读 数据表. 这样 节省了disk IO.
小结: 他们应该类似于一种可以相互转换的存在。Using index是索引覆盖,如果需要用到过滤,那么就会显示Using where;Using index,如果在过滤的同时又用到了索引下推,那就会变成Using index condition
。
参考地址:
MySQL 执行计划(Using where,Using index 和 Using index condition)
MySQL - ‘Using index condition’ vs ‘Using where; Using index’