为什么Mysql EXPLAIN中的EXTRA为NULL?为什么 >= 是使用索引条件?

Jou*_*ney 6 mysql innodb explain

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
Run Code Online (Sandbox Code Playgroud)

有一个名为 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();
Run Code Online (Sandbox Code Playgroud)

我做了一些实验,一些如下

有一些实验

现在,我想知道;

(1)为什么explain select * from t where a >= 90000; 是额外的Using index condition?它有索引键,但没有索引过滤器和表过滤器,为什么是这样Using index condition

(2)为什么explain select * from t where a = 90000;是额外的NULL?是需要访问表,如果第一种情况是Using index condition,为什么第二个不能Using index condition

(3)为什么explain select a from t where a >= 90000;是额外的Using where; Using index?我知道它使用封面索引,所以额外有Using index;但为什么额外有Using where?这意味着服务器需要过滤数据?但是存储引擎已经返回正确,为什么服务器需要filer?

Dan*_* W. 0

您的第一个和最后一个查询使用WHERE与其他行的隐式比较,在这种情况下,它使用索引并将其显示在额外的字段(类型范围)中。

当您创建具有 0-1 结果的条件时,它可以直接访问它们(O(1) 查找)。不进行比较或排序,只需取一行,然后返回。