From the beginning of a problem analysis:
Suppose a table has a federated index (C1,C2,C3,C4)--only the C1,C2,C3 portion of the federated Index can be used
A where c1=x and C2=x and C4>x and C3=x
B where c1=x and C2=x and c4=x order by C3
C where c1=x and c4= x GROUP by C3,C2
D where c1=? and c5=? ORDER by C2,C3
E where c1=? and c2=? and c5=? ORDER by C2,C3
who knows whether the following a-e can use the index!! Why?
OK, start
To create a table:
INSERT into T values (' A1 ', ' A2 ', ' A3 ', ' A4 ', ' A5 '), (' B1 ', ' B2 ', ' B3 ', ' B4 ', ' B5 ');
Insert data:
INSERT into T values (' A1 ', ' A2 ', ' A3 ', ' A4 ', ' A5 '), (' B1 ', ' B2 ', ' B3 ', ' B4 ', ' B5 ');
To add an index:
ALTER TABLE T add index c1234 (C1,C2,C3,C4);
For the first case: Description c1,c2,c3,c4 is used
Make a slight change:
Use GROUP by General as a temporary file, in order to
Where is Order by? Similar to the above.
A little change, analysis: Know the principle is very easy!
What's the answer to the question above? Anyway, I don't know!
The rules can be summarized as follows:
MySQL optimized btree index usage rules