EXPLAIN执行计划中type字段分为以下几种(性能从最好到最差):
1、type = NULL,MYSQL不用访问表或者索引就直接能到结果。
eg: explain select * from trader_quota_match t WHERE t.match_hour IS NULL;
2、type = const/system,单表中最多只有一条匹配行,查询起来非常迅速。
eg: explain select * from trader_quota_match t WHERE t.id = 1587774022257610753;
3、type = eq_ref,相对于ref来说就是使用的是唯一索引,对于每个索引键值,只有唯一的一条匹配记录。
eg: 略
4、type = ref,使用非唯一性索引或者唯一索引的前缀扫描,返回匹配某个单独值的记录行。
eg: explain select * FROM `trader_quota_match` t WHERE t.policy_code = '123';
5、type = range ,索引范围扫描,常见于<、<=、>、>=、between等操作符
eg: EXPLAIN SELECT t.* FROM trader_quota_match t WHERE t.match_hour <= 1
6、type = index,索引全扫描,MySQL遍历整个索引来查找匹配的行。
eg: EXPLAIN SELECT t1.policy_code,t1.policy_name FROM trader_quota_match t1,system_open_policy t2 WHERE t1.policy_code = t2.code
7、type = ALL,全表扫描,MySQL扫描全表来找到匹配的行。
eg: explain select * FROM `trader_quota_match` t WHERE t.policy_name = '123';