MySQL EXPLAIN Extra列的信息
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
MySQL EXPLAIN Extra列的信息
這一列包含的是不適合在其他列顯示的額外信息。
Using where
這意味著mysql服務(wù)器將在存儲(chǔ)引擎檢索行后再進(jìn)行過(guò)濾。許多where條件里涉及索引中的列,當(dāng)它如果并且讀取索引時(shí),就能背存儲(chǔ)引擎檢驗(yàn),因此不是所有帶有where子句的查詢都會(huì)顯示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
這個(gè)值表示mysql將使用覆蓋索引,以避免訪問(wèn)表。不要把覆蓋索引和type:index訪問(wèn)類型混淆了。
>?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會(huì)對(duì)結(jié)果使用一個(gè)外部索引排序,而不是按照索引次序從表里讀取行。mysql有兩種文件排序算法,兩種方式都可以在內(nèi)存或磁盤文件上完成。EXPLAIN不會(huì)告訴你mysql將使用哪一種文件排序,也不會(huì)告訴你排序會(huì)在內(nèi)存里還是磁盤上完成。
下面的查詢和排序都使用了覆蓋索引,所以不會(huì)出現(xiàn)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版本中的新特性,是一種在存儲(chǔ)引擎層使用索引過(guò)濾數(shù)據(jù)的一種優(yōu)化方式。
a 當(dāng)關(guān)閉ICP時(shí),index 僅僅是data access 的一種訪問(wèn)方式,存儲(chǔ)引擎通過(guò)索引回表獲取的數(shù)據(jù)會(huì)傳遞到MySQL Server層進(jìn)行where條件過(guò)濾。
b 當(dāng)打開(kāi)ICP時(shí),如果部分where條件能使用索引中的字段,MySQL Server會(huì)把這部分下推到引擎層,可以利用index過(guò)濾的where條件在存儲(chǔ)引擎層進(jìn)行數(shù)據(jù)過(guò)濾,而非將所有通過(guò)index access的結(jié)果傳遞到MySQL server層進(jìn)行where過(guò)濾。
優(yōu)化效果:ICP能減少引擎層訪問(wèn)基表的次數(shù)和MySQL Server訪問(wèn)存儲(chǔ)引擎的次數(shù),減少IO次數(shù),提高查詢語(yǔ)句性能。
>?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對(duì)查詢結(jié)果排序時(shí)會(huì)使用一個(gè)臨時(shí)表。
mysql何時(shí)會(huì)使用臨時(shí)表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)
單獨(dú)講
Using join buffer (Batched Key Access)
單獨(dú)講
Using MRR
單獨(dú)講
============END============
轉(zhuǎn)載于:https://my.oschina.net/xinxingegeya/blog/495894
總結(jié)
以上是生活随笔為你收集整理的MySQL EXPLAIN Extra列的信息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java中空值处理的感受
- 下一篇: java向MySQL插入当前时间的四种方