MySQL执行查询语句的方式称为访问方法或访问类型
对应执行计划的type列
const
常数级别,通过主键或唯一二级索引列与常数等值比较,定位一条记录
explain select * from single_table where id = 1438
explain select * from single_table where key2 = 41
ref
普通的二级索引列与常数等值查询
explain select * from single_table where key1 = 'abc'
采用二级索引执行查询时,每获取一条二级索引记录,就立刻执行回表操作,而不是将所有二级索引记录的主键值收集起来后再统一执行回表操作
ref_or_null
二级索引列的值与常数等值比较且查找对应该列为NULL的值
explain select * from single_table where key1 = 'abc' or key1 is null
多扫描一些值为NULL的二级索引记录
index_merge
使用索引合并的方式对s1表进行查询
explain select * from s1 where key1 = 'a' or key3 = 'a'
range
使用索引执行查询时,对应的扫描区间为若干个单点扫描区间或范围扫描区间
explain select * from single_table where key2 in (1438, 1638) or (key2 >= 38 and key2 <= 79)
不包括一个单点扫描区间和扫描区间(-oo,+oo)
index
直接遍历联合索引,扫描全部二级索引记录
explain select key_part1,key_part2,key_part3 from single_table where key_part2 = 'abc'
key_part2列不是联合索引idx_key_part的索引列中最左的列,无法使用ref或range访问方法来执行这个查询语句
all
全部扫描,直接扫描全部的聚集索引记录