【发布时间】:2020-10-08 19:16:06
【问题描述】:
mysql> CREATE TABLE `t` (
`id` int(11) NOT NULL,
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `a` (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB
有一个名为 t 的表,它有两个名为 a 和 b 的索引。 插入t 100000行数据
mysql> create procedure idata()
begin
declare i int;
set i=1;
while(i<=100000)do
insert into t values(i, i, i);
set i=i+1;
end while;
end;
Query OK, 0 rows affected (0.01 sec)
mysql> delimiter ;
mysql> call idata();
我做了一些实验,一些如下
现在,我想知道;
(1)为什么explain select * from t where a >= 90000; extra 是Using index condition?它有索引键,但它没有索引过滤器和表过滤器,那为什么是Using index condition?
(2)为什么explain select * from t where a = 90000; extra 是NULL?是需要访问表的,如果第一种情况是Using index condition,为什么第二种不能是Using index condition?
(3)为什么explain select a from t where a >= 90000; extra 是Using where; Using index?我知道它使用封面索引,所以额外有Using index;但为什么额外有Using where?这意味着服务器需要过滤数据?但是存储引擎已经返回正确,为什么服务器需要filer?
【问题讨论】:
-
关于覆盖索引的一些有用信息:stackoverflow.com/questions/609343/… 和关于解释“解释”的 MySQL 文档:dev.mysql.com/doc/refman/8.0/en/execution-plan-information.html