mysql執行計劃

EXPLAINOutput Columns

 id (JSON name: select_id)

 

The SELECT identifier.This is the sequential number of the SELECT withinthe query. The value can be NULL if the row refers to the unionresult of other rows. In this case, the table column shows a valuelike <unionM,N> toindicate that the row refers to the union of the rows with id valuesof M and N.

包含一組數字,表示查詢中執行select子句或操作表的順序。id相同,執行順序由上至下,如果是子查詢,id的序號會遞增,id值越大優先級越高,越先被執行,id如果相同,可以以認爲是一組,從上往下順序執行;在所有組中,id值越大,優先級越高,越先執行

id如果相同,可以認爲是一組,從上往下順序執行;在所有組中,id值越大,優先級越高,越先執行

 

 

select_type (JSONname: none)

 

 select_type (JSON name: none)

Thetype of SELECT, which can be any of those shownin the following table. A JSON-formatted EXPLAIN exposes the SELECT type as a property ofa query_block, unless it is SIMPLE or PRIMARY. The JSON names (whereapplicable) are also shown in the table.

table (JSON name: table_name

type

 

possible_keys 

 

The possible_keys columnindicates the indexes from which MySQL can choose to find the rows in thistable. 

key

 

 

 

The key column indicatesthe key (index) that MySQL actually decided to use.

要想強制MySQL使⽤用或忽視possible_keys列中

的索引,在查詢中使⽤用FORCEINDEXUSEINDEX或者IGNORE

INDEX

key_len

 

 

 

The key_len columnindicates the length of the key that MySQL decided to use.

一般越短越好

ref

 

The ref column showswhich columns or constants are compared to the index named inthe key column to select rows from the table.

rows

 

 

 

The rows column indicatesthe number of rows MySQL believes it must examine to execute the query.

這只是一個預估值

filtered

 

 

 

The filtered columnindicates an estimated percentage of table rows that will be filtered by thetable condition. That is, rows shows

 the estimated number of rows examinedand rows × filtered / 100 shows the number ofrows that will be joined with previous tables.

extra

 

 

 

Distinct:一旦mysql找到了與行相聯合匹配的行,就不再搜索了。

Notexists mysql優化了LEFTJOIN,一旦它找到了匹配LEFTJOIN標準的行,就不再搜索了。

Usingindex:說明查詢是覆蓋了索引的,這是好事情。MySQL直接從索引中過濾不需要的記錄並返回命中的結果。這是

MySQL服務層完成的,無需再回表查詢記錄。

Usingwhere

使用了WHERE從句來限制哪些行將與下一張表匹配或者是返回給用戶。

注意:Extra列出現Using where表⽰示MySQL服務器將存儲引擎返回服務層以後再應用WHERE條件過濾。

Rangechecked for each Recordindexmap:#) :沒有找到理想的索引,因此對從前面表中來的每一個行組合,

mysql檢查使用哪個索引,並用它來從表中返回行。這是使用索引的最慢的連接之一。

UsingfilesortMySQL中無法利用索引完成的排序操作稱爲“文件排序”

看到這個的時候,查詢就需要優化了。mysql需要進行額外的步驟來發現如何對返回的行排序。它根

據連接類型以及存儲排序鍵值和匹配條件的全部行的行指針來排序全部行。

 

Usingtemporary :表示MySQL需要使用臨時表來存儲結果集,常見於排序和分組查詢

Usingindex condition

這是MySQL 5.6出來的新特性,叫做“索引條件推送”。簡單說⼀一點就是MySQL原來在索引上是不能執⾏行

like這樣的操作的,但是現在可以了,這樣減少了不必要的IO操作,但是隻能⽤用在⼆二級索引上。

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章