MySQL:EXPLAIN中EXTRA字段显示结果与预期不符

MySQL版本:8.0.16

创建学生表student,包含编号、姓名、年龄三个字段

CREATE TABLE student (
    id INT NOT NULL AUTO_INCREMENT, 
    name VARCHAR(10) NOT NULL, 
    age INT NOT NULL,
    PRIMARY KEY (id),
    INDEX (name) 
);

插入测试数据

INSERT INTO student(name, age) VALUES('Tim', 18);
INSERT INTO student(name, age) VALUES('Jack', 25);

通过姓名查找学生

mysql> explain SELECT id, name, age FROM student WHERE name = 'Tim';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE student NULL ref name name 32 const 1 100.00 NULL

预期结果:Extra显示using index condition
实际结果:Extra显示NULL

先通过二级索引查找name,再通过聚簇索引查找age,此时应该发生了回表,但为何Extra字段显示NULL呢?

阅读 2.2k
1 个回答

Explain output columns

Column Meaning
id The SELECT identifier
select_type The SELECT type
table The table for the output row
partitions The matching partitions
type The join type
possible_keys The possible indexes to choose
key The index actually chosen
key_len The length of the chosen key
ref The columns compared to the index
rows Estimate of rows to be examined
filtered Percentage of rows filtered by table condition
Extra Additional information

这么多列有索引有关,你为啥只看 Extra 呢 ...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题