MySQL based index (2)


Preface

We call to find the primary key index by the index K, and then look for the primary key index corresponding to the tree-line process is back to the table , this process will consume additional resources, this article describes how to avoid back to the table


Tip: The following is the content of this article, the following cases are for reference

One, covering index

select * from T where k between 3 and 5
select id from T where k between 3 and 5

The SQL that searches all data in the previous line will cause the return to the table, and the next line directly retrieves the primary key field id to avoid the process of returning to the table.

Covering index can significantly reduce the number of tree searches , avoiding the process of returning to the table, and also significantly improving performance

Regarding the joint index: If for a hot table, the user needs to find the content of another primary key based on the content of another primary key, then it is necessary to avoid returning to the table through the joint primary key

Second, the principle of the leftmost prefix

The leftmost prefix principle involves the problem of index items : index items are sorted according to the fields appearing in the index definition

The joint index mentioned above can form an index item, such as (id, address)

Therefore, when searching for all people living in a certain place , locate the first record whose residence is xxx through the primary key id , and then continue to search backwards until all users whose residence is xxx are found.

So how do you sort the fields in the index when creating a joint index? That is, (A,B) OR (B,A)
If there is already an (A,B) index, we don't need to create a new one on the A field Indexed

What if we have to create a new index for each of A and B? At this time, we need to choose the shorter field length as the index , that is, there is no need to create a new index for A and B, but choose the smaller field to build the index (spatial principle)

3. Index condition pushdown

The purpose of index push down is to reduce the number of back to the table. The fields contained in the index can be first judged during the index traversal process, and the records that do not meet the conditions are filtered
and the judgment process is done inside the index by innoDB.

Guess you like

Origin blog.csdn.net/qq_45596525/article/details/114684626