1. The principle of index push-down optimizationLet's first take a brief look at the general architecture of MySQL: The MySQL service layer is responsible for SQL syntax parsing, generating execution plans, etc., and calling the storage engine layer to perform data storage and retrieval. The push-down of Let's take a closer look at the MySQL query without using ICP:
When using ICP, the query process is:
2. Specific Practice of Index PushdownThe theory is rather abstract, so let’s put it into practice. Use a user table If there is a requirement now: retrieve all users in the table whose first name is Zhang and whose age is 10 years old. Then, the SQL statement is written like this: select * from tuser where name like '张%' and age=10; If you understand the leftmost matching principle of the index, then you know that this statement can only be used when searching the index tree, and the id of the first record that meets the conditions is 1. So what are the next steps? 1. Not using ICP Before Let's look at the schematic diagram: It can be seen that the table needs to be returned twice, which wastes the other field 2. Use ICP After Let's look at the schematic diagram: You can see that the table was only returned once. In addition, we can also look at the execution plan and see +----+-------------+-------+------------+-------+---------------+-----------+----------+------+------+------+----------+-----------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+-----------+----------+------+------+------+----------+-----------------------+ | 1 | SIMPLE | tuser | NULL | range | na_index | na_index | 102 | NULL | 2 | 25.00 | Using index condition | +----+-------------+-------+------------+-------+---------------+-----------+----------+------+------+------+----------+-----------------------+ 3. Index pushdown usage conditions
Relevant system parameters: Index condition pushdown is enabled by default, and you can use the system parameter optimizer_switch to control whether it is enabled. View the 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) Toggle state: set optimizer_switch="index_condition_pushdown=off"; set optimizer_switch="index_condition_pushdown=on"; This is the end of this article about understanding MySQL index pushdown in a few minutes. For more relevant MySQL index pushdown content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Responsive Web Design Learning (1) - Determining the screen size and percentage usage
>>: Sample code for programmatically processing CSS styles
<br />Related articles: How to prompt and op...
Downloaded an es image from docker hub, version 6...
Table of contents Where is the source code of the...
I have been in contact with MGR for some time. Wi...
Designers need to understand psychology reading n...
1. Use xshell to connect to the virtual machine, ...
HTML web page list tag learning tutorial. In HTML ...
Recently, I have a project that requires using ifr...
No gaps on both sides, gaps between each column w...
What is a Viewport Mobile browsers place web pages...
Hash Join Hash Join does not require any indexes ...
Problem description: I used a desktop computer an...
This article shares the specific code of jQuery t...
Preface Recently, I was analyzing the startup pro...
1. Add the following code to http{} in nginx.conf...