B-tree index usage rules optimized by MySQL

Source: Internet
Author: User
B-tree index usage rules for MySQL optimization are analyzed from one question: Assume that a table has a joint index (c1, c2, c3, c4), mdash, and mdash. Only the Union index can be used.

B-tree index usage rules for MySQL optimization are analyzed from one question: Assume that a table has a joint index (c1, c2, c3, c4), mdash, and mdash. Only the Union index can be used.

B-tree index usage rules optimized by MySQL

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:

-------------------------------------- Split line --------------------------------------

Install MySQL in Ubuntu 14.04

MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Build a MySQL Master/Slave server in Ubuntu 14.04

Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS

Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04

MySQL-5.5.38 universal binary Installation

-------------------------------------- Split line --------------------------------------

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.