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
1. Command method Run the nginx service in the cr...
This article uses an example to describe the simp...
Table of contents 1. Implementation of counter 2....
Today, after the game was restarted, I found that...
Table of contents What is Vuex? Vuex usage cycle ...
Table of contents 1 Create mount directories and ...
Table of contents Overview CommonJS Specification...
Table of contents principle Network environment p...
Table of contents Preface Laying the foundation p...
HTML is a hybrid language used for publishing on ...
This article shares the installation tutorial of ...
1. How to create a user and password 1. Enter the...
Table of contents 1. Install the proxy module 2. ...
Experimental environment: Physical machine Window...
Non-orthogonal margins When margin is used, it wi...