CREATE TABLE `teacher_card` (
`tcid` int(3) NOT NULL,
`tcdesc` varchar(20) NOT NULL,
PRIMARY KEY (`tcid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `teacher` (
`tid` int(3) NOT NULL,
`tname` varchar(20) NOT NULL,
`tcid` int(3) NOT NULL,
PRIMARY KEY (`tid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
tname索引:
alter table teacher add index a (tname)
执行 explain SELECT * FROM teacher WHERE tname = "张三" extra为空
执行 explain SELECT * FROM teacher WHERE tname = "张三" order by tcid
extra 为 Using index condition; Using filesort
我的疑问是:为什么第一条执行的时候不是Using index condition?
Using index condition是索引下推,你的查询并没有索引下推这一种操作,只是简单利用索引定位到tname="张三",然后就回表了。