Mysql无法使用范围查询列之后的其他索引列(以及5.6版本的ICP)

在 MySQL 5.6 版本之前,索引逻辑不包含 Index Condition Pushdown (ICP) 功能。复合索引的使用从第一列开始,确定范围后回表查询并应用剩余条件。5.6 版本引入 ICP 后,优化器在确定索引范围后,可以使用额外的索引列进行过滤,减少回表记录,提高查询效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mysql5.6版本之前没有加入index condition pushdown,所以索引逻辑还是这样的:

即便对于复合索引,从第一列开始先确定第一列索引范围,如果范围带=号,则对于=号情况,确定第二列索引范围加入索引结果集里,每列的处理方式都是一样的。

确定完索引范围后,则回表查询数据,再用剩下的where条件进行过滤判断。

mysql5.6后加入了ICP,对于确定完了索引范围后,会用剩下的where条件对索引范围再进行一次过滤,然后再回表,再用剩下的where条件进行过滤判断。(减少回表记录数量)。





The optimizer attempts to use additional key parts to determine the interval as long as the comparison operator is =, <=>, or IS NULL. If the operator is >, <, >=, <=, !=, <>, BETWEEN, or LIKE, the optimizer uses it but considers no more key parts.For the following expression, the optimizer uses = from the first comparison. It also uses >= from the second comparison but considers no further key parts and does not use the third comparison for interval construction: key_part1 = 'foo' AND key_part2 >= 10 AND key_part3 > 10 The single interval is: ('foo',10,-inf) < (key_part1,key_part2,key_part3) < ('foo',+inf,+inf)http://dev.mysql.com/doc/refman/5.5/en/range-optimization.html#range-access-multi-part

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值