
執行計劃字段概要說明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驅魔任務能刷什么碎片,每日驅魔選擇建議
