Talk about MySQL table query and covering index

Analysis & Answer

What is back query?

In layman's terms, if the index column is in the column required by select (because the index in mysql is sorted according to the value of the index column, so there are some values ​​in the column in the index node) or according to an index query The records can be obtained without returning to the table. If there are a large number of non-indexed columns in the columns required by select, the index needs to find the information of the corresponding columns in the table, which is called returning to the table.

A picture to understand:

  1. First locate the primary key value id=5 through the ordinary index;
  2. Locate the row records through the clustered index; this is the so-called return table query, first locate the primary key value, and then locate the row records, its performance is lower than scanning the index tree.

covering index

MySQL official website: All the column data required by SQL can be obtained on only one index tree, without returning to the table, and the speed is faster.

If an index (such as: composite index) contains all the values ​​​​of the fields to be queried, it is called a covering index, such as:

SELECT user_name,city,age FROM user_test WHERE user_name='louxj' AND age>25;
复制代码

Because the fields to be queried (user_name, city, age) are all included in the index columns of the composite index, the covering index query is used to check whether the covering index is used. You can use the value in the Extra in the execution plan to use index. It proves that the covering index is used, and the covering index can greatly improve the access performance.

Meow Interview Assistant: One-stop solution to interview questions, you can search the WeChat applet [Meow Interview Assistant]  or follow [Meow Brush Questions] -> Interview Assistant  free questions. If you have good interview knowledge or skills, look forward to your sharing!

Guess you like

Origin blog.csdn.net/jjclove/article/details/127391482