Preface: Index Pushdown (ICP) is an optimization for situations where MySQL uses indexes to retrieve rows from a table.
Index pushdown can reduce the number of times the storage engine accesses the data table and the number of times the MySQL server accesses the storage engine. Are you still a little confused? That's right. There is no doubt that the above paragraph is quite difficult to understand, but please don't be discouraged. I will use the most easy-to-understand language to show you how to understand index pushdown. To summarize:
1. Leftmost prefix principle The index can be used in the following situations: SELECT * FROM USER WHERE id = 1 SELECT * FROM USER WHERE id = 1 and name = 'zhangsan' SELECT * FROM USER WHERE id = 1 and name = 'zhangsan' and age = 18 The index cannot be used in the following situations: SELECT * FROM USER WHERE name = 'zhangsan' SELECT * FROM USER WHERE age = 18 SELECT * FROM USER WHERE name = 'zhangsan' and age = 18 For a joint index, 2. Return to table
Here we focus on clustered indexes. The official documentation has the following description
When 3. Index pushdownFirst create a user table CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `age` int DEFAULT 0, `class` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `index_two` (`name`,`age`) )ENGINE=InnoDB; //Add a composite index (`name`,`age`) to this table Insert data into the table INSERT INTO `student` (`name`, `age`, `class`) VALUES ('pengpeng', 21, '1'); INSERT INTO `student` (`name`, `age`, `class`) VALUES ('pengpeng', 22, '2'); INSERT INTO `student` (`name`, `age`, `class`) VALUES ('pengpeng', 23, '3'); INSERT INTO `student` (`name`, `age`, `class`) VALUES ('pengpeng', 24, '4'); INSERT INTO `student` (`name`, `age`, `class`) VALUES ('pengpeng', 25, '5'); The query inserted data is as follows Next explain the following SQL explain select * from student where name like 'peng%' and age = 23; You can see that the Extra field is displayed as USING INDEX CONDITION, which indicates that this SQL uses index pushdown. Let's analyze the above SQL statement:
Question and Answer Area Question 1: When the composite index column is (name, age, address), can the following SQL use the index? select * from student where name like 'peng%' and age = 23; Yes, encountering like will interrupt the matching of subsequent elements, but only the name field can be used. MySQL will keep matching to the right until it encounters a range query (>, <, between, like) and stops matching. The range column can use the index, but the columns following the range column cannot use the index. That is, the index is used for at most one range column, so if there are two range columns in the query condition, the index cannot be fully used. Question 2: Can index pushdown only exist in joint indexes? Yes, index pushdown is not possible with non-joined indexes. Question 3: In what situations can index pushdown not be used?
Question 4 : How to turn on and off index pushdown? // Index pushdown is enabled by default set optimizer_switch='index_condition_pushdown=off'; // Disable set optimizer_switch='index_condition_pushdown=on'; // Enable Summarize The optimization of index pushdown on non-primary key indexes can effectively reduce the number of table returns and greatly improve the efficiency of queries. In daily work, you can use index pushdown to improve business throughput by optimizing indexes according to business conditions. This is the end of this detailed article about MySQL index pushdown. For more relevant MySQL index pushdown content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: CSS uses BEM naming convention practice
>>: Linux installation apache server configuration process
Table of contents redo log Why do we need to upda...
Regarding some MySQL specifications, some compani...
In MySQL operation and maintenance, a R&D col...
The before/after pseudo-class is equivalent to in...
Table of contents 1. v-text (v-instruction name =...
Table of contents Preface Why do we need to encap...
The project was tested these days, and the tester...
1. Enter the container docker run [option] image ...
Problem description (what is keep-alive) keep-ali...
Table of contents Short Introduction 1. Check the...
1. Prepare in Advance For your convenience, I cre...
Permissions and database design User Management U...
Download MySQL for Mac: https://downloads.mysql.c...
This article shares the specific code of JavaScri...
Table of contents 1. Basic SELECT statement 1. Qu...