Index Type
Index primary key index and a sub-type of non-primary key index. (Be sure to keep in mind is how to store data)
- The leaf nodes of the primary key index is stored entire row of data. In InnoDB, the primary key index is also called clustering index (clustered index).
- Non-primary key index leaf node content is the value of the primary key. In InnoDB, the non-primary key index is also called the secondary index (secondary index).
Clustered index
Clustered default primary key index, if the table does not define the primary key, InnoDB selects a unique index instead of a non-empty. If there is no such index, InnoDB implicitly defined as a primary key clustered index.
B + TREE reasons, it is best to use consecutive integers field, to find a better access range determined
Back to the table
The difference between the query index structure described above, the primary key index and the ordinary index
- If the statement is select * from T where ID = 500, i.e., the primary key query, the tree only needs to search for a B + tree ID;
- If the statement is select * from T where k = 5 , that is, the general index query, you'll need to search the index k tree, get a value of 500 ID, to the ID search index tree once. This process is called back to the table .
Covering index
If the statement is executed select ID from T where k between 3 and 5, then only need to check the ID value, and the value of the ID has the index k in the tree, so you can direct the query results, you do not need back to the table. In other words, this query inside, the index k has been "covered" the needs of our inquiry, we called a covering index.
Index pushdown
Index pushdown is MySQL5.6 version of the launch of the optimization methods
is enabled by default, can be turned off by the following command
SET optimizer_switch = 'index_condition_pushdown=off';
If there about SQL, unreasonable implementation process, the following figure shows
index(name,age)
mysql> select * from tuser where name like '张%' and age=10 and ismale=1;
You can see, no index pushdown is required every time the query back to the table, and push down the previous filter is a good result set back to the table to get the data select *
No index pushed down
the index pushdown