- All——全表扫描
explain select * from student where name ='GG';
name字段无索引。
- index——全索引扫描
explain select age from student;
虽然没用上where条件查询,但age字段包含的列,会扫描索引树。
-
range——索引范围扫描,常见于'>=','between' 等操作符
explain select age from student where id > 10;
id是索引,只要查找索引的某个范围即可,通过索引找到具体的数据。
-
ref——非唯一性索引扫描,返回匹配某个单独值的所有行
explain select * from payment where customer_id = 10;
customer_id在payment表中是非唯一性索引。
-
eq_ref——唯一性索引扫描,常见主键或唯一性索引
explain select * from payment from phone = ‘17628288888’;
phone为唯一性索引,所以每个索引键,表中只有一条记录与之匹配。
-
const——表示通过一次索引就找到了结果,常出现于主键或唯一性索引
explain select * from student where id = 1;
如将主键如id置于where中,则MySQL就能将该查询转换为一个常量。
-
system——是const类型的特例,当查询的表只有一行的情况下使用system。
-
NULL——MySQL在优化过程中分解语句,执行时甚至不用访问表或索引
explain select 1 from dual where 1;
dual是一个虚拟的表,可以直接忽略。