<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題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關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
        當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

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

        來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-09 20:13:43
        文檔

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

        MySQL優(yōu)化之ICP(indexconditionpushdown:索引條件下推)_MySQL:ICP技術(shù)是在MySQL5.6中引入的一種索引優(yōu)化技術(shù)。它能減少在使用 二級(jí)索引 過(guò)濾where條件時(shí)的回表次數(shù) 和 減少M(fèi)ySQL server層和引擎層的交互次數(shù)。在索引組織表中,使用二級(jí)索引進(jìn)行回表的代價(jià)相比堆表中是要高一些的。Index Condition Push
        推薦度:
        導(dǎo)讀MySQL優(yōu)化之ICP(indexconditionpushdown:索引條件下推)_MySQL:ICP技術(shù)是在MySQL5.6中引入的一種索引優(yōu)化技術(shù)。它能減少在使用 二級(jí)索引 過(guò)濾where條件時(shí)的回表次數(shù) 和 減少M(fèi)ySQL server層和引擎層的交互次數(shù)。在索引組織表中,使用二級(jí)索引進(jìn)行回表的代價(jià)相比堆表中是要高一些的。Index Condition Push

        ICP技術(shù)是在MySQL5.6中引入的一種索引優(yōu)化技術(shù)。它能減少在使用 二級(jí)索引 過(guò)濾where條件時(shí)的回表次數(shù) 和 減少M(fèi)ySQL server層和引擎層的交互次數(shù)。在索引組織表中,使用二級(jí)索引進(jìn)行回表的代價(jià)相比堆表中是要高一些的。

        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 技術(shù),必須先理解數(shù)據(jù)庫(kù)是如何處理 where 中的條件的。

        對(duì) where 中過(guò)濾條件的處理,根據(jù)索引使用情況分成了三種:index key, index filter, table filter

        1. index key

        用于確定SQL查詢?cè)谒饕械倪B續(xù)范圍(起始范圍+結(jié)束范圍)的查詢條件,被稱之為Index Key。由于一個(gè)范圍,至少包含一個(gè)起始與一個(gè)終止,因此Index Key也被拆分為Index First Key和Index Last Key,分別用于定位索引查找的起始,以及索引查詢的終止條件。

        2. index filter

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

        3. table filter

        where 中的條件不能使用索引進(jìn)行處理的,只能訪問(wèn)table,進(jìn)行條件過(guò)濾了。

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

        在 MySQL5.6 之前,并不區(qū)分Index Filter與Table Filter,統(tǒng)統(tǒng)將Index First Key與Index Last Key范圍內(nèi)的索引記錄,回表讀取完整記錄,然后返回給MySQL Server層進(jìn)行過(guò)濾。而在MySQL 5.6之后,Index Filter與Table Filter分離,Index Filter下降到InnoDB的索引層面進(jìn)行過(guò)濾,減少了回表與返回MySQL Server層的記錄交互開(kāi)銷,提高了SQL的執(zhí)行效率。

        所以所謂的 ICP 技術(shù),其實(shí)就是 index filter 技術(shù)而已。只不過(guò)因?yàn)镸ySQL的架構(gòu)原因,分成了server層和引擎層,才有所謂的“下推”的說(shuō)法。所以ICP其實(shí)就是實(shí)現(xiàn)了index filter技術(shù),將原來(lái)的在server層進(jìn)行的table filter中可以進(jìn)行index filter的部分,在引擎層面使用index filter進(jìn)行處理,不再需要回表進(jìn)行table filter。

        4. ICP 技術(shù)啟用前后比較

        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 例子

        官方文檔給出了一個(gè)例子:

        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%' 本來(lái)是無(wú)法使用復(fù)合索引 index(zipcode, lastername, firstname) 進(jìn)行過(guò)濾的,但是因?yàn)橛辛薎CP技術(shù),所以他們可以在 index filter 階段使用索引進(jìn)行過(guò)濾,而不需要回表進(jìn)行 table filter.

        例子2:

        role_goods 表上有組合索引 index(roleId,status,number),下面的select語(yǔ)句,因?yàn)?“索引最左前綴原則”,只能使用到 組合索引的 roleId 部分,但是因?yàn)?ICP 技術(shù)的存在,現(xiàn)在 number 條件過(guò)濾也可以在 index filter 階段完成了,無(wú)需像以前一樣需要進(jìn)行 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, 因?yàn)?roleId 是big int 類型,所以 key_len = 8 + 1 = 9; 所以在 index key 階段中,并沒(méi)有使用到 組合索引 index(roleId,status,number) 中的 number 字段(因?yàn)橹虚g有一個(gè)status字段沒(méi)有出現(xiàn)在where 條件中),但是 “Using index condition” 卻說(shuō)明使用到了ICP技術(shù),顯然是 number =1 條件過(guò)濾使用到了ICP技術(shù)。

        聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

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

        MySQL優(yōu)化之ICP(indexconditionpushdown:索引條件下推)_MySQL:ICP技術(shù)是在MySQL5.6中引入的一種索引優(yōu)化技術(shù)。它能減少在使用 二級(jí)索引 過(guò)濾where條件時(shí)的回表次數(shù) 和 減少M(fèi)ySQL server層和引擎層的交互次數(shù)。在索引組織表中,使用二級(jí)索引進(jìn)行回表的代價(jià)相比堆表中是要高一些的。Index Condition Push
        推薦度:
        標(biāo)簽: 條件 mysql 優(yōu)化
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 啦啦啦在线免费视频| 特黄特色大片免费| 久久久久国产精品免费免费不卡| 国产乱色精品成人免费视频| 亚洲欧美国产国产一区二区三区| 色影音免费色资源| 亚洲AV无码无限在线观看不卡| 99xxoo视频在线永久免费观看| 日产亚洲一区二区三区| 在线观看的免费网站无遮挡| 99久久亚洲精品无码毛片| 国产91色综合久久免费分享| 久久久久se色偷偷亚洲精品av| 成人AV免费网址在线观看| 亚洲另类无码一区二区三区| 国产aa免费视频| 抽搐一进一出gif免费视频| 亚洲精品无码午夜福利中文字幕| a在线视频免费观看| 精品亚洲A∨无码一区二区三区| 精品国产免费人成电影在线观看| 亚洲偷偷自拍高清| 亚洲不卡无码av中文字幕| 国内精品免费久久影院| 亚洲精品人成在线观看| 最新欧洲大片免费在线| 国产精品亚洲二区在线| 国产AV无码专区亚洲AV毛网站 | 在线观看91精品国产不卡免费| 美景之屋4在线未删减免费| 亚洲一区二区三区偷拍女厕| 69影院毛片免费观看视频在线| 色婷五月综激情亚洲综合| 亚洲va中文字幕无码| 中文字幕免费观看| 亚洲av无码专区在线观看亚| 亚洲伊人久久综合中文成人网| 久久免费福利视频| 99亚洲乱人伦aⅴ精品| 亚洲a一级免费视频| 尤物永久免费AV无码网站|