schedual定时任务执行报错 explain执行计划详解( 四 )

4. ref
当通过普通的二级索引列与常量进行等值匹配时,那么对该表的访问方法就是 ref,即使匹配到的值可能是多行,举例:
mysql> explain select * from t11 where a=100; ---- ------------- ------- ------------ ------ --------------- ------ --------- ------- ------ ---------- ------- | id | select_type | table | partitions | type | possible_keys | key| key_len | ref| rows | filtered | Extra | ---- ------------- ------- ------------ ------ --------------- ------ --------- ------- ------ ---------- ------- |1 | SIMPLE| t11| NULL| ref| a| a| 5| const |500 |100.00 | NULL| ---- ------------- ------- ------------ ------ --------------- ------ --------- ------- ------ ---------- ------- 5. ref_or_null
当对普通二级索引进行等值匹配查询,该索引列的值也可以是 NULL 值时,那么对该表的访问方法就可能是 ref_or_null,举例:
mysql> explain select * from t11 where a=100 or a is null; ---- ------------- ------- ------------ ------------- --------------- ------ --------- ------- ------ ---------- ----------------------- | id | select_type | table | partitions | type| possible_keys | key| key_len | ref| rows | filtered | Extra| ---- ------------- ------- ------------ ------------- --------------- ------ --------- ------- ------ ---------- ----------------------- |1 | SIMPLE| t11| NULL| ref_or_null | a| a| 5| const |501 |100.00 | Using index condition | ---- ------------- ------- ------------ ------------- --------------- ------ --------- ------- ------ ---------- ----------------------- 6. index_merge
一般情况下对于某个表的查询只能使用到一个索引,在某些场景下可以使用 Intersection、Union、Sort-Union 这三种索引合并的方式来执行查询,此时就显示为 index_merge,举例:
mysql> explain select * from t1 where a<50 or b=50; ---- ------------- ------- ------------ ------------- --------------- --------- --------- ------ ------ ---------- ---------------------------------------- | id | select_type | table | partitions | type| possible_keys | key| key_len | ref| rows | filtered | Extra| ---- ------------- ------- ------------ ------------- --------------- --------- --------- ------ ------ ---------- ---------------------------------------- |1 | SIMPLE| t1| NULL| index_merge | a,idx_b| a,idx_b | 5,5| NULL |50 |100.00 | Using sort_union(a,idx_b); Using where | ---- ------------- ------- ------------ ------------- --------------- --------- --------- ------ ------ ---------- ---------------------------------------- 7. unique_subquery
对一些包含 in 子查询的查询语句中,如果优化器无法使用 semi-join 或物化进行优化,最终将子查询转换为 EXISTS 子查询,而且子查询可以使用到主键或者唯一键进行等值匹配的话,那么该子查询执行计划的type列的值就是 unique_subquery 。举例:
mysql> explain select * from t1 where a in(select id from t2 where t1.a=t2.a) or b=100; ---- -------------------- ------- ------------ ----------------- --------------- --------- --------- ------ ------ ---------- ------------- | id | select_type| table | partitions | type| possible_keys | key| key_len | ref| rows | filtered | Extra| ---- -------------------- ------- ------------ ----------------- --------------- --------- --------- ------ ------ ---------- ------------- |1 | PRIMARY| t1| NULL| ALL| idx_b| NULL| NULL| NULL | 1000 |100.00 | Using where ||2 | DEPENDENT SUBQUERY | t2| NULL| unique_subquery | PRIMARY,a| PRIMARY | 4| func |1 |100.00 | Using where | ---- -------------------- ------- ------------ ----------------- --------------- --------- --------- ------ ------ ---------- ------------- 8. range
如果使用索引获取某些范围区间的记录,那么就可能使用到 range 访问方法 。举例:
mysql> explain select * from t1 where a<50 and a>20; ---- ------------- ------- ------------ ------- --------------- ------ --------- ------ ------ ---------- ----------------------- | id | select_type | table | partitions | type| possible_keys | key| key_len | ref| rows | filtered | Extra| ---- ------------- ------- ------------ ------- --------------- ------ --------- ------ ------ ---------- ----------------------- |1 | SIMPLE| t1| NULL| range | a| a| 5| NULL |29 |100.00 | Using index condition | ---- ------------- ------- ------------ ------- --------------- ------ --------- ------ ------ ---------- ----------------------- mysql> explain select * from t1 where a in(1,2,3); ---- ------------- ------- ------------ ------- --------------- ------ --------- ------ ------ ---------- ----------------------- | id | select_type | table | partitions | type| possible_keys | key| key_len | ref| rows | filtered | Extra| ---- ------------- ------- ------------ ------- --------------- ------ --------- ------ ------ ---------- ----------------------- |1 | SIMPLE| t1| NULL| range | a| a| 5| NULL |3 |100.00 | Using index condition | ---- ------------- ------- ------------ ------- --------------- ------ --------- ------ ------ ---------- -----------------------

推荐阅读