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
This article uses examples to illustrate the usag...
Google's goal with Flutter has always been to...
Summarize 1. Similarities Both can change the int...
1: If you use the tag <a> to link to a page,...
I saw in the LOFTER competition that it was mentio...
This article mainly introduces the example analys...
Preface This article introduces how to use the ne...
Because frameset and body are on the same level, y...
<br />I have summarized the annotation writi...
Preface This article mainly introduces the releva...
Table of contents 1. Introduction 2. Main text 2....
Table of contents 1. Environmental Preparation 2....
This article mainly introduces the effect of div ...
How to make a simple web calculator using HTML, C...
Table of contents 1. Basics 1.ref 2. toRef 3. toR...