using index mysql_mysql using index condition?

Without ICP, the storage engine traverses the index to locate rows in the base table and returns them to the MySQL server which evaluates theWHEREcondition for the rows.With ICP enabled, and if parts of theWHEREcondition can be evaluated by using only columns from the index, the MySQL server pushes this part of theWHEREcondition down to the storage engine.

当explain的extra出现using index condition时,确实是由engine来进行where条件的筛选;

而没出现using index condition时,where中非索引条件是由server层来做的筛选。

问题1:什么条件下会形成push down优化?

回答:看了下官方文档,只给出了联合索引的例子,联合索引很好理解;此外我自己尝试了下用一个单个二级索引和一个非索引条件,也会用到index condition。

猜测一下,ICP是mysql5.6后新加的新特性,应该是发现之前在server层进行条件筛选太慢了导致的。因为mysql是边读边发,当engine层数据量很大时,会分多次发给server处理,而如果在engine进行条件筛选,可以减少发给server的数据量和发送次数。所以如果不存在使用临时表进行排序、连接查询等在engine不方便的操作时,应该都会用到ICPICP can reduce the number of times the storage engine must access the base table and the number of times the MySQL server must access the storage engine.

问题2:select * from table_f where id = ? 是不是push down?

回答:如果id是主键或者二级索引,不会用到push down。直接从索引树获取数据。

问题3: sql语句执行流程

回答:server层将解析优化后的执行计划作为参数调用engine封装好的接口获取数据,再根据where中的条件过滤数据返回给client;如果extra中出现了using index condition,则过滤数据由engine来做。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值