8.8.2 EXPLAIN Output Format
EXPLAIN 語句提供資訊關於SELECT 語句的執行計畫:
EXPLAIN 返回SELECT 語句使用的每個表的行資訊, 它列出了MySQL 會讀取它們當處理語句時候的輸出的順序。
MySQL 解決所有的串連使用嵌套迴圈方法,這意味著MySQL 從第一個表讀取一條記錄,
在第2個表,第三個表,等等中找到匹配的行,
當所有的表被處理後,MySQL 輸出選擇的列。
當使用EXTENDED 關鍵字被使用,EXPLAIN 產生額外的資訊,可以通過執行
SHOW WARNINGS 語句在EXPLAIN語句後面,EXPLAIN EXTENDED 也顯示過濾的列。
注意:
你不能是用EXTENDED 和PARTITIONS 關鍵字一起使用在同樣的EXPLAIN 語句裡,
EXPLAIN Output Columns EXPLAIN 輸出格式
EXPLAIN Join Types EXPLAIN Join 類型
EXPLAIN Extra Information EXPALIN 額外的資訊
EXPLAIN Output Interpretation EXPLAIN 輸出解釋
解釋輸出資料行:
本節介紹瞭解釋EXPLAIN 產生的輸出資料行,稍後部分提供關於該類型和額外列的附加資訊。
EXPLAIN 每個輸出行提供了關於一個表的資訊, 每個行包含8.1中總結的值,
EXPLAIN 的輸出資料行,並在表中更詳細地描述。列名在表的第一列顯示;第二列提供了等效的屬性名稱,在輸出時顯示格式為JSON的使用
Column JSON Name Meaning
id select_id The SELECT identifier
select_type None The SELECT type
table table_name The table for the output row
partitions partitions The matching partitions
type access_type The join type
possible_keys possible_keys The possible indexes to choose
key key The index actually chosen
key_len key_length The length of the chosen key
ref ref The columns compared to the index
rows rows Estimate of rows to be examined
filtered filtered Percentage of rows filtered by table condition
Extra None Additional information
mysql> explain SELECT cpi.personName, ccd.clientSn, ccd.income, ccd.pay, ccd.accountBalance, ccd.createdTime, ccd.remark from
-> (select * from ClientCashDetail ccd_int where
-> 1 >
-> (SELECT count(clientSn) from ClientCashDetail
-> where clientSn= ccd_int.clientSn and ccd_int.createdTime < createdTime and createdTime < TIMESTAMP(@dated_time) )
-> and ccd_int.createdTime < TIMESTAMP(@dated_time)
-> ) ccd
-> RIGHT JOIN ClientPersonalInfo cpi on cpi.clientSn = ccd.clientSn
-> where ccd.clientSn in (SELECT clientSn from ClientPersonalInfo where personName in (
-> ‘蔡明’,
-> ‘苑秀鳳’,
-> ))-> ORDER BY cpi.personName, ccd.clientSn, ccd.createdTime DESC;
+—-+——————–+——————–+——–+—————+————-+———+——————-+——+———————————+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+——————–+——————–+——–+—————+————-+———+——————-+——+———————————+
| 1 | PRIMARY | cpi | ALL | PRIMARY | NULL | NULL | NULL | 937 | Using temporary; Using filesort |
| 1 | PRIMARY | ClientPersonalInfo | eq_ref | PRIMARY | PRIMARY | 4 | zjzc.cpi.clientSn | 1 | Using where |
| 1 | PRIMARY | | ref | | | 4 | zjzc.cpi.clientSn | 10 | NULL |
| 2 | DERIVED | ccd_int | ALL | NULL | NULL | NULL | NULL | 5999 | Using where |
| 3 | DEPENDENT SUBQUERY | ClientCashDetail | ALL | NULL | NULL | NULL | NULL | 5999 | Using where |
+—-+——————–+——————–+——–+—————+————-+———+——————-+——+———————————+
5 rows in set (0.11 sec)
注意:
JSON 的屬性是空的不顯示的在JSON 格式裡
id (JSON name: select_id) 第一列select ID
SELECT 標示符,這是查詢中SELECT 特定的順序的號碼。 該值可以為NULL,
如果行指向其它行的的union 結果,在這種情況下, 表列顯示一個值像