Sequential test scheme for federated indexes under MySQL b-tree index

Source: Internet
Author: User
Tags mysql query

Column order to be aware of using federated indexes
For example, when using
SELECT * from user where x=1 and y=2;
The index that should be created may be the add key (x, y)
How to determine the order of indexes
General Experience
can use
Select COUNT (Distinct x)/count (x) as X_selectivity,
COUNT (distinct y)/count (y) as x_selectivity,
Count (*),
from user;
row1***************************
x_selectivity:0.0001
y_selectivity:0.0312
COUNT (*): 16022

The higher the selectivity in X, the more you can put in the first column
Alert table User add key (x, y);

In addition, similar optimizations can be found in historical slow queries.

Like what
SELECT * from user where x=1 and y=2;

Select SUM (x=1), sum (y=2) from User\g;
row1**********************************
SUM (x=1): 7992
SUM (y=2): 30

The selectivity of Y is higher and can be placed in the first column

And look at the selectivity of the X column for y=2.
Select SUM (x=1) from user where y=2
row1**********************************
SUM (x=1): 17

However, there is a possibility that MySQL query is unfair, the overall performance of the server may be worse, so we need to extract the worst query to do this query work

This kind of work is called Sarg by some optimization geek geek. This is the abbreviation for "searchable parameters (searchable argument)".

Sequential test scheme for federated indexes under MySQL b-tree index

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.