当前位置:网站首页>Understand what MySQL index push down (ICP) is in one article
Understand what MySQL index push down (ICP) is in one article
2022-06-30 21:20:00 【Aiky WOW】
One 、 brief introduction
ICP(Index Condition Pushdown) Is in MySQL 5.6 Query optimization strategy launched on version , Put the original Server The index condition check performed by the storage engine layer is pushed down to the storage engine layer , To reduce the number of times to return to the table and access the storage engine , Improve query efficiency .
Two 、 principle
In order to understand ICP How it works , Let's first understand that it is not used ICP Under the circumstances ,MySQL How to query :
- The storage engine reads index records ;
- According to the primary key value in the index , Locate and read the complete row record ;
- The storage engine gives the records to
ServerLayer to detect whether the record meetsWHEREConditions .
Use ICP Under the circumstances , The query process is as follows :
- Read index records ( Not a complete line record );
- Judge
WHEREWhether the condition part can be checked with the columns in the index , Condition not satisfied , Then process the next row of index records ; - Conditions met , Use the primary key in the index to locate and read the complete row record ( It's the so-called back table );
- The storage engine gives the records to
Serverlayer ,ServerThe layer detects whether the record meetsWHEREThe rest of the condition .
3、 ... and 、 practice
First create a table , And insert the record
CREATE TABLE user (
id int(11) NOT NULL AUTO_INCREMENT COMMENT " Primary key ",
name varchar(32) COMMENT " full 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) Be careful , A union index is created in this table (name, city), Suppose we want to query the following statement :
select * from user where name="LiSi" and city like "%Z%" and age > 25;3.1 Push down without index
Without index push down , According to the joint index “ The leftmost match ” principle , Only name Columns can use indexes ,city Columns are then fuzzy matched , You can't use indexes , The execution process is as follows :
- The storage engine is based on
(name, city)Joint index , findnameThe value isLiSiThe record of , common 4 Bar record ; - Then according to this 4 Of records id value , Scan the table one by one , Remove the complete row record from the clustered index , And return these records to
Serverlayer ; ServerThe layer receives these records , And according to the conditionsname="LiSi" and city like "%Z%" and age > 25To filter , Finally stay("LiSi", "ZhengZhou", 30)This record .
Draw a picture to see :
3.2 Use index to push down
When using index push down , The execution process is like this :
- The storage engine is based on
(name, city)Joint index , findname='LiSi'The record of , common 4 strip ; - Because the union index contains
cityColumn , The storage engine presses... Directly in the federated indexcity like "%Z%"To filter , After filtering, there is 2 Bar record ; - According to the filtered records id value , Scan the table one by one , Remove the complete row record from the clustered index , And return these records to
Serverlayer ; ServerAccording to WHERE Other conditions of the statementage > 25, Filter the row records again , In the end, only("LiSi", "ZhengZhou", 30)This record .
Draw a picture to see :
in addition , You can also see from the execution plan that index push down is used (Extra Inside display Using index condition)
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)
Four 、 Conditions of use
- It can only be used for
range、ref、eq_ref、ref_or_nullAccess method ; - It can only be used for
InnoDBandMyISAMStorage engine and its partition table ; - Yes
InnoDBFor storage engines , Index push down is only applicable to secondary indexes ( Also called secondary index );
The purpose of index push down is to reduce the number of table returns , That is to reduce IO operation . about
InnoDBOf Cluster index Come on , The complete row record has been loaded into the cache , There is no point in pushing down the index .
- Conditions that reference subqueries cannot be pushed down ;
- A condition that references a storage function cannot be pushed down , Because the storage engine cannot call the storage function .
5、 ... and 、 Related system parameters
Push is enabled by default under index conditions , You can use system parameters optimizer_switch To check whether the controller is on .
View 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)Switch state :
set optimizer_switch="index_condition_pushdown=off";
set optimizer_switch="index_condition_pushdown=on";边栏推荐
- sdfsdf
- A group of K inverted linked lists
- Spatiotemporal data mining: an overview
- 银行集体下架的智能投顾产品,为何成了“鸡肋”?
- FreeRTOS记录(九、一个裸机工程转FreeRTOS的实例)
- How to move forward when facing confusion in scientific research? How to give full play to women's advantages in scientific research?
- 防范未授权访问攻击的十项安全措施
- ceshi deces
- 《ClickHouse原理解析与应用实践》读书笔记(3)
- uniapp怎么上传二进制图片
猜你喜欢

stacking集成模型预测回归问题

个人开发的渗透测试工具Satania

片荒吗?不用下载直接在线免费看的资源来了!2022年收藏夹必须有它!

MySQL高级篇3

毕业五年,想当初若没有入行测试,我是否还会如这般焦虑

关于,奇安信检测代码漏洞,XSS系列解决

Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement

修改已经上线的小程序名称

MySQL introduction, detailed installation steps and usage | dark horse programmer
测试媒资缓存问题
随机推荐
Iclr'22 spotlight | how to measure the amount of information in neural network weights?
Icml2022 | utility theory of sequential decision making
凤凰架构——架构师的视角
ArcGIS construction and release of simple road network data service and rest call test
ncat详细介绍(转载)
物联网僵尸网络Gafgyt家族与物联网设备后门漏洞利用
[untitled]
的撒啊苏丹看老司机
clickhouse原生监控项,系统表描述
Use the log server to output the topn of various Apache logs
DM8:生成DM AWR报告
Dm8: generate DM AWR Report
元宇宙可能成为互联网发展的新方向
Fletter nested hell? No, constraintlayout to save!
代码改变一小步,思维跨越一大步
[grade evaluator] how to register a grade evaluator? How many passes?
sdfsdf
将博客搬至CSDN
twelve thousand three hundred and forty-five
FreeRTOS记录(九、一个裸机工程转FreeRTOS的实例)