create table employee
(
eid int auto_increment,
ename varchar(32),
age int,
salary float,
mid int,
PRIMARY KEY(eid),
KEY(ename, age)
);
create table manager
(
mid int,
mname varchar(32),
PRIMARY KEY(mid)
);
1.type为all,表示扫描全表
EXPLAIN SELECT * FROM employee;
2.type为index,表示扫描全索引
EXPLAIN SELECT id FROM employee;
3.type为const,表示查询结果为一个常量
EXPLAIN SELECT * FROM employee WHERE id = 5;
4.type为range,表示扫描一个范围。常见于BETWEEN AND、<、>,IN等查询
EXPLAIN SELECT * FROM employee WHERE id BETWEEN 10 AND 20;
5.type为eq_ref,表示唯一索引扫描
EXPLAIN SELECT * FROM employee, manager WHERE employee.mid = manager.mid;
6.type为ref,表示非唯一索引扫描。组合索引最左匹配
EXPLAIN SELECT * FROM employee WHERE ename = "lisi";