MySQL optimized btree index usage rules

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.