执行计划字段概要说明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 结果是要去重的,内部创建了一个 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| ---- ------------- ------- ------------ ------ --------------- ------ --------- ----------- ------ ---------- -------------
推荐阅读
- Win10游戏全屏任务栏无法隐藏的三种解决方法
- 小编教你在oppoa3中打开全屏多任务的方法介绍。
- 小编分享车到哪APP发布任务的操作方法。
- iPhone手机快手任务中心在哪里
- 如何打开任务管理器 打开任务管理器方法
- 血盟荣耀荣誉之路是什么,传奇之路任务奖励
- 奥拉星怎么接任务,《奥拉星手游》晶石获取方法介绍
- 造梦3任务怎么做,我的深圳造梦记
- 天猫精灵怎么设置定时关机 天猫精灵怎样设置定时关机
- 崩坏3驱魔任务能刷什么碎片,每日驱魔选择建议