The index (5)

T in the following list, execute select * from T where k betwee 3 and 5;, need to perform a search operation several times tree?

mysql> create table T (
ID int primary key,
k int NOT NULL DEFAULT 0, 
s varchar(16) NOT NULL DEFAULT '',
index k(k))
engine=InnoDB;

insert into T values(100,1, 'aa'),(200,2,'bb'),(300,3,'cc'),(500,5,'ee'),(600,6,'ff'),(700,7,'gg');

image

SQLStatement execution process:

  1. k 3 is recorded in the index tree to find k acquires ID 300
  2. Then the index tree ID 300 corresponding to the ID is found recorded R3
  3. 5 k value recorded in the index tree to find k acquires ID 500
  4. Found back on the index tree ID 500 corresponding to the ID recording R4
  5. Record 6 k value of k in the index to find the tree, do not qualify, ending cycle

In this process, the key index back to the main course of the search tree, become back to the table.

In this case, since the data needed for the query results only have a primary key index, so had to return to the table. If the statement is executing select ID from T where k between 3 and 5;, only need to query the value of the ID, and the index k tree with this value does not need back to the table, the index k has been covering the value of the query need, to be covered by the index .

Covering indexes can reduce the number of searches of the tree, significantly improve query performance, so use a covering index is a common performance optimization tools.

Joint index: multiple field to the index, B + tree in line with the principle of the most left-prefix.

Guess you like

Origin www.cnblogs.com/jackw1/p/12597148.html