MySQL中explain可以查看內部執行計劃,他可以解釋的有SELECT
, DELETE
, INSERT
, REPLACE
,
和UPDATE
語句(在MySQL5.6.3後纔出現這麼多)。另外,這只是查詢執行計劃,並沒有執行。同時,使用explain時也可以使用EXTENDED
或者 PARTITIONS參數。
以下是使用執行計劃出現的格式:
Column | Meaning |
---|---|
id |
The SELECT identifier(事件ID) |
select_type |
The SELECT type(查詢類型) |
table |
The table for the output row(表名) |
partitions |
The matching partitions(符合的分區) |
type |
The join type(聯合查詢類型) |
possible_keys |
The possible indexes to choose(可能選取的索引) |
key |
The index actually chosen(真實的索引) |
key_len |
The length of the chosen key(所選索引的字段的長度) |
ref |
The columns compared to the index() |
rows |
Estimate of rows to be examined(被查詢的預估值) |
filtered |
Percentage of rows filtered by table condition(根據條件過濾的百分比) |
Extra |
Additional information(額外信息) |
1、select_type:
select_type Value |
Meaning |
---|---|
SIMPLE |
Simple SELECT (not
using UNION or
subqueries) |
PRIMARY |
Outermost SELECT |
UNION |
Second or later SELECT statement
in a UNION |
DEPENDENT UNION |
Second or later SELECT statement
in a UNION ,
dependent on outer query |
UNION RESULT |
Result of a UNION . |
SUBQUERY |
First SELECT in
subquery |
DEPENDENT SUBQUERY |
First SELECT in
subquery, dependent on outer query |
DERIVED |
Derived table SELECT (subquery
in FROM clause) |
MATERIALIZED |
Materialized subquery |
UNCACHEABLE SUBQUERY |
A subquery for which the result cannot be cached and must be re-evaluated for each row of the outer query |
UNCACHEABLE UNION |
The second or later select in a UNION that
belongs to an uncacheable subquery (seeUNCACHEABLE SUBQUERY ) |