Mysql Performance Optimization: What is an index pushdown?

Original: Mysql Performance Optimization: What is an index pushdown?

REVIEW

  • This article originated in my public number: yard ape technology column, the original is not easy, Thank recommendation.
  • Pushdown index (index condition pushdown) referred to as the ICP, in Mysql5.6 launch on versions for optimizing queries.

  • Without the use of ICP, the use of non-primary key index (also called ordinary index or two indexes) when queried, retrieved by the storage engine to the indexed data, then returns to the MySQL server, the server then determines whether the data matches.

  • In the case of the ICP, if certain conditions are judged to be indexed column is present, this part is determined MySQL server to a stored engine conditions, then the storage engine conditions by determining whether the index passed MySQL server, only when the index eligible retrieved data will only be returned to the MySQL server.

  • Index condition pushdown optimization can reduce the number of storage engine query the underlying table, you can reduce the number of servers from MySQL storage engine receives data .

 

Open line and

  • Before you start to prepare a user table (user), there are several fields mainly: id, name, age, address . Establish joint index (name, Age) .

  • Suppose there is a demand, a requirement to match the first name for all users Chen, sql statement is as follows:

  SELECT * from user where  name like '陈%'
  • According to the principle of "the best left-prefix", where the use of the joint index (name, age) were queries, the performance will certainly be higher than the full table scan.

  • The question is, if there are other conditions? Assuming that there is a demand, requires matching the first word of the name is Chen, aged 20 users , this time sql statement is as follows:

  SELECT * from user where  name like '陈%' and age=20
  • How this sql statement should enforce it? The following prior to Mysql5.6 version and the version after the analysis.

 

Mysql5.6 previous version

  • Before version 5.6 this is no index pushdown optimization, so the process is performed in the following figure:

 

  • This field is ignored age, direct inquiries by name, find the two results in (name, age) this lesson trees, respectively 2,1 id, then holding to take the id value again and again back to the table query, Therefore, this process takes back to the table twice .

 

Mysql5.6 and later versions

  • Version 5.6 adds the index pushdown optimization, the process of implementation in the following figure:

  • InnoDB age did not ignore this field, but in the internal index determines whether the age is equal to 20, the recording is not equal to the skip 20, thus (name, age) the index tree to tree matching only a record, this Take this time to go to the primary key index id tree query all the data back to the table, this process takes only back to the table again .

 

practice

  • Of course, the above analysis only on principle, we can analyze the real, so Chen Mysql5.6 installed version of Mysql, resolve the above statement, as follows:

  • It can be seen Extra explain the analysis result is based on the Using index for condition Condition , showing pushdown index has been used.

 

to sum up

  • Push down the index in the non-primary key index optimization, can effectively reduce the number back to the table, greatly improves the efficiency of queries.

  • Close index pushdown can use the following command to modify the configuration file is no longer tells the story, after all, so why close it excellent features:

  set optimizer_switch='index_condition_pushdown=off';

 

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12630085.html