MySQL的執行計劃

MySQL中explain可以查看內部執行計劃,他可以解釋的有SELECTDELETEINSERTREPLACE, 和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_typeValue 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)



















發佈了31 篇原創文章 · 獲贊 6 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章