[MySQL] index pushdown (version 5.6 +)

Index pushdown

With the index pushdown optimization, may, with a condition like query case, reduce the number back to the table.

For user_table table, we now have (username, age) joint index
if there is now a need to find out the name of "Zhang" at the beginning of age and less than or equal to 10 user information, the statement is as follows:

select * from user_table where username like '张%' and age > 10

There are two possible execution statement:

  1. According to (username, age) joint index query to meet all names beginning with "sheet" of the index, and then back to the table query the corresponding full-line data, and then screened to meet the age of 10 or less user data.
  2. According to (username, age) joint index all queries meet the name of "Zhang" at the beginning of the index, and then re-screened directly equal to the index younger than 10, then return to full-table query rows of data.

Obviously, the second way is less need to return to a full line of data queries, which is pushed down the index mysql. mysql index pushdown is enabled by default, we can index_condition_pushdown logo by modifying the system also controls the variable optimizer_switch
SET optimizer_switch = 'index_condition_pushdown = off' ;

Suppose there are joint index table t (a, b), the following statement can be used to improve efficiency index pushdown:

select * from t where a > 2 and b > 10;
summary
  1. innodb engine tables, indexes pushdown secondary index can only be used (in addition to the clustering index index index is two (secondary index), each two record index value column addition, further contains primary key value query index by two first primary key is found, then InnoDB corresponding data block to find the primary key / clustered index is found according to the primary key value.). innodb primary key index (clustered index) saved on a leaf child node is a full line of data, so this time pushed down the index does not decrease the risk of the whole bank data query results.
  2. General index pushdown query field can be used to ask (select column) are not all joint index fields, search criteria and query clauses (where / order by) the whole field is a joint index for multiple conditions.
Published 273 original articles · won praise 13 · views 70000 +

Guess you like

Origin blog.csdn.net/LU_ZHAO/article/details/105152039