• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    MySQL優化之ICP(indexconditionpushdown:索引條件下推)_MySQL

    來源:懂視網 責編:小采 時間:2020-11-09 20:13:43
    文檔

    MySQL優化之ICP(indexconditionpushdown:索引條件下推)_MySQL

    MySQL優化之ICP(indexconditionpushdown:索引條件下推)_MySQL:ICP技術是在MySQL5.6中引入的一種索引優化技術。它能減少在使用 二級索引 過濾where條件時的回表次數 和 減少MySQL server層和引擎層的交互次數。在索引組織表中,使用二級索引進行回表的代價相比堆表中是要高一些的。Index Condition Push
    推薦度:
    導讀MySQL優化之ICP(indexconditionpushdown:索引條件下推)_MySQL:ICP技術是在MySQL5.6中引入的一種索引優化技術。它能減少在使用 二級索引 過濾where條件時的回表次數 和 減少MySQL server層和引擎層的交互次數。在索引組織表中,使用二級索引進行回表的代價相比堆表中是要高一些的。Index Condition Push

    ICP技術是在MySQL5.6中引入的一種索引優化技術。它能減少在使用 二級索引 過濾where條件時的回表次數 和 減少MySQL server層和引擎層的交互次數。在索引組織表中,使用二級索引進行回表的代價相比堆表中是要高一些的。

    Index Condition Pushdown optimization is used for the range, ref, eq_ref, and ref_or_null access methods when there is a need to access full table rows. This strategy can be used for InnoDB and MyISAM tables. (Note that index condition pushdown is not supported with partitioned tables in MySQL 5.6; this issue is resolved in MySQL 5.7.) For InnoDB tables, however, ICP is used only for secondary indexes. The goal of ICP is to reduce the number of full-record reads and thereby reduce IO operations. For InnoDB clustered indexes(值主鍵索引), the complete record is already read into the InnoDB buffer. Using ICP in this case does not reduce IO.

    要想深入理解 ICP 技術,必須先理解數據庫是如何處理 where 中的條件的。

    對 where 中過濾條件的處理,根據索引使用情況分成了三種:index key, index filter, table filter

    1. index key

    用于確定SQL查詢在索引中的連續范圍(起始范圍+結束范圍)的查詢條件,被稱之為Index Key。由于一個范圍,至少包含一個起始與一個終止,因此Index Key也被拆分為Index First Key和Index Last Key,分別用于定位索引查找的起始,以及索引查詢的終止條件。

    2. index filter

    在使用 index key 確定了起始范圍和介紹范圍之后,在此范圍之內,還有一些記錄不符合where 條件,如果這些條件可以使用索引進行過濾,那么就是 index filter。

    3. table filter

    where 中的條件不能使用索引進行處理的,只能訪問table,進行條件過濾了。

    如何確定 index key, index filter, table filter,可以參考何博士的文章。

    在 MySQL5.6 之前,并不區分Index Filter與Table Filter,統統將Index First Key與Index Last Key范圍內的索引記錄,回表讀取完整記錄,然后返回給MySQL Server層進行過濾。而在MySQL 5.6之后,Index Filter與Table Filter分離,Index Filter下降到InnoDB的索引層面進行過濾,減少了回表與返回MySQL Server層的記錄交互開銷,提高了SQL的執行效率。

    所以所謂的 ICP 技術,其實就是 index filter 技術而已。只不過因為MySQL的架構原因,分成了server層和引擎層,才有所謂的“下推”的說法。所以ICP其實就是實現了index filter技術,將原來的在server層進行的table filter中可以進行index filter的部分,在引擎層面使用index filter進行處理,不再需要回表進行table filter。

    4. ICP 技術啟用前后比較

    To see how this optimization works, consider first how an index scan proceeds when Index Condition Pushdown is not used:

    Get the next row, first by reading the index tuple, and then by using the index tuple to locate and read the full table row.

    Test the part of the WHERE condition that applies to this table. Accept or reject the row based on the test result.

    When Index Condition Pushdown is used, the scan proceeds like this instead:

    Get the next row's index tuple (but not the full table row).

    Test the part of the WHERE condition that applies to this table and can be checked using only index columns. If the condition is not satisfied, proceed to the index tuple for the next row.

    If the condition is satisfied, use the index tuple to locate and read the full table row.

    Test the remaining part of the WHERE condition that applies to this table. Accept or reject the row based on the test result.

    When Index Condition Pushdown is used, the Extra column in EXPLAIN output shows Using index condition. It will not show Index only because that does not apply when full table rows must be read.

    5. ICP 例子

    官方文檔給出了一個例子:

    Suppose that we have a table containing information about people and their addresses and that the table has an index defined as INDEX (zipcode, lastname, firstname). If we know a person's zipcode value but are not sure about the last name, we can search like this:

    SELECT * FROM people WHERE zipcode='95054' AND lastname LIKE '%etrunia%' AND address LIKE '%Main Street%';

    MySQL can use the index to scan through people with zipcode='95054'. The second part (lastname LIKE '%etrunia%') cannot be used to limit the number of rows that must be scanned, so without Index Condition Pushdown, this query must retrieve full table rows for all the people who have zipcode='95054'.

    With Index Condition Pushdown, MySQL will check the lastname LIKE '%etrunia%' part before reading the full table row. This avoids reading full rows corresponding to all index tuples that do not match the lastname condition.

    Index Condition Pushdown is enabled by default; it can be controlled with the optimizer_switch system variable by setting the index_condition_pushdown flag. See Section 8.9.2, “Controlling Switchable Optimizations”.

    上面例子中的 lastername like '%etrunia%' 和 address like '%Main Street%' 本來是無法使用復合索引 index(zipcode, lastername, firstname) 進行過濾的,但是因為有了ICP技術,所以他們可以在 index filter 階段使用索引進行過濾,而不需要回表進行 table filter.

    例子2:

    role_goods 表上有組合索引 index(roleId,status,number),下面的select語句,因為 “索引最左前綴原則”,只能使用到 組合索引的 roleId 部分,但是因為 ICP 技術的存在,現在 number 條件過濾也可以在 index filter 階段完成了,無需像以前一樣需要進行 table filer 了:

    mysql> explain select * from role_goods where roleId=100000001 and number=1;

    +----+-------------+------------+------+---------------+----------+---------+-------+------+-----------------------+

    | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

    +----+-------------+------------+------+---------------+----------+---------+-------+------+-----------------------+

    | 1 | SIMPLE | role_goods | ref | roleId_2 | roleId_2 | 9 | const | 14 | Using index condition |

    +----+-------------+------------+------+---------------+----------+---------+-------+------+-----------------------+

    1 row in set (0.01 sec)

    可以看到 key_len = 9, 因為 roleId 是big int 類型,所以 key_len = 8 + 1 = 9; 所以在 index key 階段中,并沒有使用到 組合索引 index(roleId,status,number) 中的 number 字段(因為中間有一個status字段沒有出現在where 條件中),但是 “Using index condition” 卻說明使用到了ICP技術,顯然是 number =1 條件過濾使用到了ICP技術。

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    MySQL優化之ICP(indexconditionpushdown:索引條件下推)_MySQL

    MySQL優化之ICP(indexconditionpushdown:索引條件下推)_MySQL:ICP技術是在MySQL5.6中引入的一種索引優化技術。它能減少在使用 二級索引 過濾where條件時的回表次數 和 減少MySQL server層和引擎層的交互次數。在索引組織表中,使用二級索引進行回表的代價相比堆表中是要高一些的。Index Condition Push
    推薦度:
    標簽: 條件 mysql 優化
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 亚洲国产精品国产自在在线| 久久久久九国产精品| 国产精品美女免费视频观看| 久久精品这里热有精品| 久久精品国产只有精品2020| 亚洲第一永久AV网站久久精品男人的天堂AV | 人人妻人人澡人人爽人人精品97 | 精品久久久久久亚洲精品| 2022国产精品福利在线观看| 久久国产亚洲精品麻豆| 国产精品网址在线观看你懂的| 国产一区二区三区欧美精品| 人妻少妇精品系列| 日韩精品极品视频在线观看免费| 精品国产一区二区三区在线观看| 欧美精品免费观看二区| 青草国产精品久久久久久| 欧美日韩精品在线观看| 国产亚洲精品国看不卡| 国产精品爱搞视频网站 | 91久久精品国产91性色也| 久久久久久久亚洲精品| 亚洲国产精品自在线一区二区| 久热这里只有精品99国产6| 91亚洲国产成人久久精品| 国产在线精品网址你懂的| 国产精品99久久99久久久| 国产精品伦理久久久久久| 麻豆精品成人免费国产片| 97精品国产福利一区二区三区| 国产精品一区二区av不卡| 亚洲欧美日韩精品永久在线| 国产精品国产三级国产专播| 精品a在线观看| 国产精品 码ls字幕影视| 亚洲精品性视频| 四虎国产精品免费入口| 88国产精品无码一区二区三区| 亚洲精品国产成人99久久| 91国内揄拍国内精品对白不卡| 亚洲国产精品自在线一区二区|