Optimization 为什么解释显示“使用索引条件”?
我在马里亚布学习使用索引条件 这是针对Centos7和运行Mariadb 10.2的 这是我的SQL 创建索引Optimization 为什么解释显示“使用索引条件”?,optimization,mariadb,Optimization,Mariadb,我在马里亚布学习使用索引条件 这是针对Centos7和运行Mariadb 10.2的 这是我的SQL 创建索引 create index ixnn_product__updated_at on product (updated_at); 说明 explain extended select * from product where updated_at BETWEEN '2018-06-10 00:00:00' AND '2019-06-10 23:59:59' explain ex
create index ixnn_product__updated_at
on product (updated_at);
说明
explain extended
select * from product
where updated_at BETWEEN '2018-06-10 00:00:00' AND '2019-06-10 23:59:59'
explain extended
select updated_at from product
where updated_at BETWEEN '2018-06-10 00:00:00' AND '2019-06-10 23:59:59'
结果
id: 1
select_type: SIMPLE
table: product
type: range
possible_keys: ixnn_product__updated_at
key: ixnn_product__updated_at
key_len: 5
ref: NULL
rows: 2431232
filtered: 100.00
Extra: Using index condition
id: 1
select_type: SIMPLE
table: product
type: range
possible_keys: ixnn_product__updated_at
key: ixnn_product__updated_at
key_len: 5
ref: NULL
rows: 2431232
filtered: 100.00
Extra: Using where; Using index
我期望额外使用索引,但我看到了使用索引的条件
所以我增加了测试
说明
explain extended
select * from product
where updated_at BETWEEN '2018-06-10 00:00:00' AND '2019-06-10 23:59:59'
explain extended
select updated_at from product
where updated_at BETWEEN '2018-06-10 00:00:00' AND '2019-06-10 23:59:59'
结果
id: 1
select_type: SIMPLE
table: product
type: range
possible_keys: ixnn_product__updated_at
key: ixnn_product__updated_at
key_len: 5
ref: NULL
rows: 2431232
filtered: 100.00
Extra: Using index condition
id: 1
select_type: SIMPLE
table: product
type: range
possible_keys: ixnn_product__updated_at
key: ixnn_product__updated_at
key_len: 5
ref: NULL
rows: 2431232
filtered: 100.00
Extra: Using where; Using index
为什么会发生这种情况?使用索引条件和使用索引是不相关的优化。不幸的是,名字如此接近
使用索引条件可以通过其其他名称进行研究:ICP或索引条件下推。这是一种比以前引擎(例如InnoDB)将行传递回处理程序的加速。在您的情况下,使用ICP,发动机根据更新的_进行测试
使用索引意味着索引正在覆盖。这意味着表中需要的所有列都存在于正在使用的索引中。这意味着查询可以完全在索引的BTree中执行,而无需进入数据的BTree。您的第一次选择需要所有列*;您的第二个只需要在更新时更新,因此它涵盖了
5.3将ICP添加到MariaDB中;请访问5.6中的Mysql。谢谢您的回答。我认为第一个问题不是ICP。因为没有其他where条件。@hoyeonUm-我同意这似乎是“错误的”。请提供EXPLAIN FORMAT=JSON SELECT。。。如果它可用并且@RickJames-EXPLAIN FORMAT=JSON第一个查询结果索引条件:product.updated_在'2018-06-10 00:00:00'和'2019-06-10 23:59:59'之间,第二个查询结果附加_条件:product.updated_在'2018-06-10 00:00:00'和'2019-06-10 23:59:59'之间,使用_index:true不幸的是,优化器跟踪不支持。从10.4.3开始。