1. IntroductionICP (Index Condition Pushdown) is a query optimization strategy introduced in MySQL 5.6. It pushes the index condition check originally done by the server layer down to the storage engine layer to reduce the number of table returns and storage engine accesses, thereby improving query efficiency. 2. PrincipleTo understand how ICP works, let's first understand how MySQL queries without ICP:
When using ICP, the query process is as follows:
III. PracticeFirst create a table and insert records CREATE TABLE user ( id int(11) NOT NULL AUTO_INCREMENT COMMENT "Primary key", name varchar(32) COMMENT "Name", city varchar(32) COMMENT "city", age int(11) COMMENT "age", primary key(id), key idx_name_city(name, city) )engine=InnoDB default charset=utf8; insert into user(name, city, age) values("ZhaoDa", "BeiJing", 20),("QianEr", "ShangHai", 21),("SunSan", "GuanZhou", 22), ("LiSi", "ShenZhen", 24), ("ZhouWu", "NingBo", 25), ("WuLiu", "HangZhou", 26), ("ZhengQi", "NanNing", 27), ("WangBa", "YinChuan", 28), ("LiSi", "TianJin", 29), ("ZhangSan", "NanJing", 30), ("CuiShi", "ZhengZhou", 65), ("LiSi", "KunMing", 29), ("LiSi", "ZhengZhou", 30); Check the table records mysql> select * from user; +----+----------+-----------+------+ | id | name | city | age | +----+----------+-----------+------+ | 1 | ZhaoDa | Beijing | 20 | | 2 | QianEr | ShangHai | 21 | | 3 | SunSan | GuanZhou | 22 | | 4 | LiSi | ShenZhen | 24 | | 5 | ZhouWu | NingBo | 25 | | 6 | WuLiu | HangZhou | 26 | | 7 | ZhengQi | NanNing | 27 | | 8 | WangBa | YinChuan | 28 | | 9 | LiSi | TianJin | 29 | | 10 | ZhangSan | NanJing | 30 | | 11 | CuiShi | ZhengZhou | 65 | | 12 | LiSi | KunMing | 29 | | 13 | LiSi | ZhengZhou | 30 | +----+----------+-----------+------+ 13 rows in set (0.00 sec) Note that a joint index (name, city) is created in this table. Suppose we want to query the following statement: select * from user where name="LiSi" and city like "%Z%" and age > 25; 3.1 Not using index pushdownWithout using index pushdown, according to the "leftmost match" principle of the joint index, only the name column can use the index. The city column cannot use the index because it is a fuzzy match. The execution process at this time is as follows:
Let’s draw a picture: Index condition pushdown is not used 3.2 Using Index PushdownWhen using index pushdown, the execution process is as follows:
Let’s draw a picture:
In addition, you can also see from the execution plan that index pushdown is used (Using index condition is displayed in Extra) mysql> explain select * from user where name="LiSi" and city like "%Z%" and age > 25; +----+-------------+-------+------------+------+---------------+---------------+---------+-------+------+----------+------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+---------------+---------+-------+------+----------+------------------------------------+ | 1 | SIMPLE | user | NULL | ref | idx_name_city | idx_name_city | 99 | const | 4 | 7.69 | Using index condition; Using where | +----+-------------+-------+------------+------+---------------+---------------+---------+-------+------+----------+------------------------------------+ 1 row in set, 1 warning (0.00 sec) IV. Conditions of Use
5. Related system parametersIndex condition pushdown is enabled by default, and you can use the system parameter optimizer_switch to control whether it is enabled. View the default status: mysql> select @@optimizer_switch\G; *************************** 1. row *************************** @@optimizer_switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,duplicateweedout=on,subquery_materialization_cost_based=on,use_index_extensions=on,condition_fanout_filter=on,derived_merge=on 1 row in set (0.00 sec) Toggle state: set optimizer_switch="index_condition_pushdown=off"; set optimizer_switch="index_condition_pushdown=on"; SummarizeThis is the end of this article about what is MySQL Index Pushdown (ICP). For more information about MySQL Index Pushdown (ICP), please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the solution to image deformation under flex layout
>>: Use of docker system command set
This article shares the specific code of JavaScri...
Install pymysql pip install pymysql 2|0Using pymy...
1. Create a MySQL database 1. Create database syn...
Generally speaking, we can have the following two...
Table of contents 1. What is an Operating System ...
I followed the tutorial on W3school. I think the t...
In the front-end layout of the form, we often nee...
1. What is CSS Animations is a proposed module fo...
I believe everyone is familiar with the trashcan,...
Docker is becoming more and more popular. It can ...
This article describes the Linux user and group c...
Table of contents What is insert buffer? What are...
In the horizontal direction, you can set the cell...
Open the cpanel management backend, under the &qu...
In combination with the scenario in this article,...