mysql joint index hit condition

Turn to: https: //blog.csdn.net/claram/article/details/77574600

First clear: Why use joint index?

For the query "SELECT E. * FROM E WHERE E.e1 = 1 AND E.e3 = 2" relate to two, this time we generally use a joint index (e1, e3); instead of two separate index, which because often should a query relational mysql optimizer only one index, even if you have two indexes, he also only one; in only on the basis of a joint index will be faster than a single-column indexes ;

Here to talk about joint index usage rules and what the situation will not hit the joint index


Examples are as follows. First, create the table:
the CREATE TABLE E (E1 INT, VARCHAR e2 (9), e3 INT, PRIMARY KEY (E1, e3));
This establishes a joint index: e1, e3

Test Data

INSERT INTO E
(e1, e2, e3)
VALUES(1, 'aa', 2);


Trigger joint index is conditional:
1, the use of joint index of whole keys can be triggered using the index.
For example: the SELECT * the FROM E. E = the WHERE E.e1 the AND E.e3. 1 2 =

2, the index of the prefix portion used in combination index keys, such as "key_part_1 <op> constant" can be triggered using the index.
For example: the SELECT * the FROM E. E = the WHERE E.e1. 1

. 3, using the index key part, but not part of the index of the combined prefix, such as "key_part_2 <op> constant" can not be triggered using the index.
For example: the SELECT * the FROM E. E = the WHERE E.e3. 1

. 4, all the index keys using the joint index, but the index key is not an AND operation, the trigger can not use the index.
For example: SELECT E. * FROM E WHERE E.e3 = 2 OR E.e1 = 1

 

Can be seen from the above test results explain

Guess you like

Origin www.cnblogs.com/wueryuan/p/12372245.html