對mysql使用索引的誤解 – 小松博客

以前我一直覺得mysql一個查詢中只能使用一個索引,網上的資料有這個說的,並且我也覺得是這樣的,結果今天發現錯了php

主要是在驗證只使用一個索引的時候發現,key中顯示了兩個索引字段,type中顯示index_merge
如圖html

mysql explain

若是按照以前的理解只使用個索引,那就有問題了,那爲何有人會說只使用一個索引mysql

答案在這裏版本問題sql

MySQL5.0以前,一個表一次只能使用一個索引,沒法同時使用多個索引分別進行條件掃描,可是從5.1開始,引入了 index merge 優化技術,對同一個表能夠使用多個索引分別進行條件掃描app

不能在相信百度裏的資料了,查官方文檔
官方文檔:  http://dev.mysql.com/doc/refman/5.7/en/index-merge-optimization.html優化

The Index Merge method is used to retrieve rows with several range scans and to merge their results into one. The merge can produce unions, intersections, or unions-of-intersections of its underlying scans. This access method merges index scans from a single table; it does not merge scans across multiple tables.this

索引合併方法用於與幾個範圍掃描檢索行和他們的結果合併爲一個。合併分爲union, intersection, 以及它們的組合(先內部intersect而後在外面union)。這種訪問方式合併來自單個表索引掃描;它不合並跨多個表掃描。htm

In EXPLAIN output, the Index Merge method appears as index_merge in the type column. In this case, the key column contains a list of indexes used, and key_len contains a list of the longest key parts for those indexes.blog

在EXPLAIN輸出,索引合併方法出如今類型列index_merge。在這種狀況下,鍵列包含用於索引的列表,而且key_len包含這些索引的最長鍵部件的列表索引

說的夠明白了
參考: http://www.cnblogs.com/digdeep/archive/2015/11/18/4975977.html

QQ交流羣:136351212(滿) 455721967

如無特別說明,本站文章皆爲原創,若要轉載,務必請註明如下原文信息:
轉載保留版權:小松博客» 對mysql使用索引的誤解
本文連接地址:https://www.phpsong.com/2753.html

相關文章
相關標籤/搜索