MySQL EXPLAIN Extra列的信息
2019獨角獸企業重金招聘Python工程師標準>>>
MySQL EXPLAIN Extra列的信息
這一列包含的是不適合在其他列顯示的額外信息。
Using where
這意味著mysql服務器將在存儲引擎檢索行后再進行過濾。許多where條件里涉及索引中的列,當它如果并且讀取索引時,就能背存儲引擎檢驗,因此不是所有帶有where子句的查詢都會顯示using where。
>?explain? select?*?from?article?where?createTime?=?'1991-10-10?10:10:10'********************?1.?row?*********************id:?1select_type:?SIMPLEtable:?articletype:?ALL possible_keys:?key:?key_len:?ref:?rows:?5Extra:?Using?where 1?rows?in?setUsing index
這個值表示mysql將使用覆蓋索引,以避免訪問表。不要把覆蓋索引和type:index訪問類型混淆了。
>?explain select?title,shortName?from?article********************?1.?row?*********************id:?1select_type:?SIMPLEtable:?articletype:?index possible_keys:?key:?idx_short_name_titlekey_len:?514ref:?rows:?5Extra:?Using?index 1?rows?in?setUsing filesort
這意味著mysql會對結果使用一個外部索引排序,而不是按照索引次序從表里讀取行。mysql有兩種文件排序算法,兩種方式都可以在內存或磁盤文件上完成。EXPLAIN不會告訴你mysql將使用哪一種文件排序,也不會告訴你排序會在內存里還是磁盤上完成。
下面的查詢和排序都使用了覆蓋索引,所以不會出現using filesort,
>?explain select?title,shortName?from?article?order?by?title,shortName?asc********************?1.?row?*********************id:?1select_type:?SIMPLEtable:?articletype:?index possible_keys:?key:?idx_short_name_titlekey_len:?514ref:?rows:?5Extra:?Using?index 1?rows?in?setUsing index condition
Index Condition Pushdown (ICP)是MySQL 5.6版本中的新特性,是一種在存儲引擎層使用索引過濾數據的一種優化方式。
a 當關閉ICP時,index 僅僅是data access 的一種訪問方式,存儲引擎通過索引回表獲取的數據會傳遞到MySQL Server層進行where條件過濾。
b 當打開ICP時,如果部分where條件能使用索引中的字段,MySQL Server會把這部分下推到引擎層,可以利用index過濾的where條件在存儲引擎層進行數據過濾,而非將所有通過index access的結果傳遞到MySQL server層進行where過濾。
優化效果:ICP能減少引擎層訪問基表的次數和MySQL Server訪問存儲引擎的次數,減少IO次數,提高查詢語句性能。
>?explain? select?*?from?article?where?title?=?'hello'?and?shortName?like?'%hello%'********************?1.?row?*********************id:?1select_type:?SIMPLEtable:?articletype:?ref possible_keys:?idx_short_name_titlekey:?idx_short_name_titlekey_len:?257ref:?constrows:?1Extra:?Using?index?condition 1?rows?in?setUsing temporary
這意味著mysql對查詢結果排序時會使用一個臨時表。
mysql何時會使用臨時表https://dev.mysql.com/doc/refman/5.6/en/internal-temporary-tables.html
>?explain? select?id?,?title?from?article?a?where?a.id?=?1?union?select?id?,title?from?article?b?where?b.id?=?2?order?by?id********************?1.?row?*********************id:?1select_type:?PRIMARYtable:?atype:?const possible_keys:?PRIMARYkey:?PRIMARYkey_len:?4ref:?constrows:?1Extra:? ********************?2.?row?*********************id:?2select_type:?UNIONtable:?btype:?const possible_keys:?PRIMARYkey:?PRIMARYkey_len:?4ref:?constrows:?1Extra:? ********************?3.?row?*********************id:?select_type:?UNION?RESULTtable:?<union1,2>type:?ALL possible_keys:?key:?key_len:?ref:?rows:?Extra:?Using?temporary;?Using?filesort 3?rows?in?setUsing join buffer (Block Nested Loop)
單獨講
Using join buffer (Batched Key Access)
單獨講
Using MRR
單獨講
============END============
轉載于:https://my.oschina.net/xinxingegeya/blog/495894
總結
以上是生活随笔為你收集整理的MySQL EXPLAIN Extra列的信息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java中空值处理的感受
- 下一篇: Objective-C:Objectiv