Mysql-optimized BTree index and mysqlbtree Index

Source: Internet
Author: User

Mysql-optimized BTree index and mysqlbtree Index

Start with a question:

Suppose a table has a joint index (c1, c2, c3, c4). Only c1, c2, and c3 parts of the joint 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 the following A-E can use the index !! Why?

OK; Start

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 ');

Add an index:

Alter table t add index c1234 (c1, c2, c3, c4 );

The first case indicates that c1, c2, c3, and c4 are used.


Slightly changed:



Use group by to generate temporary files and sort them.


Order? Similar to above


A little change, analysis: It's easy to know how it works!


What is the answer to the above question? I don't know!

Summary Rules are available:



Related Article

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.