PrefaceIndex Condition Pushdown (ICP) is a new feature of MySQL 5.6. It can reduce the number of table queries and improve retrieval efficiency. MySQL ArchitectureTo understand index pushdown, you must first understand the architecture of MySQL: The above picture is from the official MySQL documentation. MySQL is usually divided into the following layers from top to bottom:
The MySQL service layer is responsible for SQL syntax parsing, triggers, views, built-in functions, binlog, generating execution plans, etc., and calls the storage engine layer to perform data storage and retrieval. The "down" in "index push down" actually means that some of the tasks that are the responsibility of the upper layer (service layer) are handed over to the lower layer (storage engine) for processing. Index pushdown exampleAssume that the user table data and structure are as follows:
Create a joint index (age, birthday) and query users whose age is > 20 and whose birthday is 03-01: select * from user where age>20 and birthday="03-01" Because the age field uses a range query, according to the leftmost prefix principle, in this case only the age field can be used for range query, and the birthday field in the index cannot be used. Use explain to view the execution plan: +------+-------------+-------+-------+---------------+--------------+--------+------+------+------+-----------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------+-------+---------------+--------------+--------+------+------+------+-----------------------+ | 1 | SIMPLE | user | range | age_birthday | age_birthday | 4 | NULL | 3 | Using index condition | +------+-------------+-------+-------+---------------+--------------+--------+------+------+------+-----------------------+ It can be seen that although the age_birthday index is used, the index length key_len is only 4, which means that only the age field of the joint index is effective (because the age field is of int type and occupies 4 bytes). Finally, the Using index condition in the Extra column indicates that this query uses index push-down optimization. To perform the following steps without index pushdown:
If index pushdown optimization is enabled, the execution steps are as follows:
After enabling index pushdown, the where condition is moved from the MySQL service layer to the storage engine layer for execution. The benefit is that the storage engine reads data from the table less often based on the ID. In the above example, when there is no index pushdown, the table needs to be queried twice more. In addition, table query is likely to be discrete IO, which can significantly improve database performance in some cases. SummarizeThis concludes this article on the simple understanding and examples of MySQL Index Pushdown (ICP). For more relevant MySQL Index Pushdown (ICP) content, 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:
|
<<: The implementation code of the CSS3 input box is similar to the animation effect of Google login
>>: The docker prune command can be used to periodically clean up infrequently used data
Table of contents 1. isPrototypeOf() Example 1, O...
In actual Web development, inserting images, incl...
Table of contents Preface 1. Basic knowledge of d...
Currently, most CPUs support floating-point units...
When you get a new Linux server, you generally ha...
This article describes the support and problem so...
1. Horizontal center Public code: html: <div c...
Table of contents 1. Background 2. Verification p...
1. In addition to the default port 8080, we try t...
Building new images from existing images is done ...
Part 3: ❤Three ways to overlook backend data rece...
mysql row to column, column to row The sentence i...
1. Overview Redis Cluster enables high availabili...
Table of contents Preface Introduction to Dockerf...
1. Download MySQL Click on the official website d...