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


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


执行计划字段概要说明id查询语句中每出现一个 SELECT 关键字,MySQL 就会为它分配一个唯一的 id 值 。也有例外,比如优化器对子查询做了 semi-join 优化时,和关联查询一样两个查询的 id 是一样的:
mysql> explain select * from t1 where a in (select b from t2 where t2.b=100); ---- ------------- ------- ------------ ------ --------------- ------ --------- ------- ------ ---------- -------------------------------------------------------------------- | id | select_type | table | partitions | type | possible_keys | key| key_len | ref| rows | filtered | Extra| ---- ------------- ------- ------------ ------ --------------- ------ --------- ------- ------ ---------- -------------------------------------------------------------------- |1 | SIMPLE| t1| NULL| ref| a| a| 5| const |1 |100.00 | NULL||1 | SIMPLE| t2| NULL| ALL| NULL| NULL | NULL| NULL|1 |100.00 | Using where; FirstMatch(t1); Using join buffer (Block Nested Loop) | ---- ------------- ------- ------------ ------ --------------- ------ --------- ------- ------ ---------- -------------------------------------------------------------------- 另外一个比较特殊的是 id 为 NULL,比如:
mysql> explain select * from t1 union select * from t2; ---- -------------- ------------ ------------ ------ --------------- ------ --------- ------ ------ ---------- ----------------- | id | select_type| table| partitions | type | possible_keys | key| key_len | ref| rows | filtered | Extra| ---- -------------- ------------ ------------ ------ --------------- ------ --------- ------ ------ ---------- ----------------- |1 | PRIMARY| t1| NULL| ALL| NULL| NULL | NULL| NULL | 1000 |100.00 | NULL||2 | UNION| t2| NULL| ALL| NULL| NULL | NULL| NULL |1 |100.00 | NULL|| NULL | UNION RESULT | | NULL| ALL| NULL| NULL | NULL| NULL | NULL |NULL | Using temporary | ---- -------------- ------------ ------------ ------ --------------- ------ --------- ------ ------ ---------- ----------------- 这是因为 union 结果是要去重的,内部创建了一个 名字的临时表,把查询 1 和查询 2 的结果集都合并到这个临时表中,利用唯一键进行去重,这种情况下查询 id 就为 NULL 。
select_type表示查询的类型,
1. SIMPLE
查询语句中不包含 UNION 或者子查询的查询都算作是 SIMPLE 类型,比方说下边这个单表查询的 select_type 的值就是 SIMPLE:
mysql> explain select * from t1 where b=1 order by a; ---- ------------- ------- ------------ ------ --------------- ------- --------- ------- ------ ---------- --------------------------------------- | id | select_type | table | partitions | type | possible_keys | key| key_len | ref| rows | filtered | Extra| ---- ------------- ------- ------------ ------ --------------- ------- --------- ------- ------ ---------- --------------------------------------- |1 | SIMPLE| t1| NULL| ref| idx_b| idx_b | 5| const |1 |100.00 | Using index condition; Using filesort | ---- ------------- ------- ------------ ------ --------------- ------- --------- ------- ------ ---------- --------------------------------------- 关联查询也是 SIMPLE 类型:
mysql> explain select * from t1 join t2 on t1.a=t2.a; ---- ------------- ------- ------------ ------ --------------- ------ --------- ----------- ------ ---------- ------------- | id | select_type | table | partitions | type | possible_keys | key| key_len | ref| rows | filtered | Extra| ---- ------------- ------- ------------ ------ --------------- ------ --------- ----------- ------ ---------- ------------- |1 | SIMPLE| t2| NULL| ALL| a| NULL | NULL| NULL|1 |100.00 | Using where ||1 | SIMPLE| t1| NULL| ref| a| a| 5| hucq.t2.a |1 |100.00 | NULL| ---- ------------- ------- ------------ ------ --------------- ------ --------- ----------- ------ ---------- -------------

推荐阅读