Column Sequence Determination of composite indexes

Source: Internet
Author: User

The most confusing order of composite indexes is the order of index columns, which depends not only on queries using this index, but also on sorting and grouping. Some time ago I posted a post: where condition order and compound index field order. Interested friends may wish to participate in the discussion. Today, I want to share my opinion. In the application development stage, [selectivity] is our primary consideration. Please refer to the figure below:
When SQL Performance problems occur, you may need to pay attention to the following: 1. random IO2. sorting (order by) 3. group by or distinct. In this case, you don't have to worry about [selectivity]. My experience is that when you already have Top n SQL statements, we should give priority to [value distribution] rather than selectivity.
How to determine the value distribution is as follows:

Select * from userresult_f where askid = 800808 and uid = 110996854;

There are two indexes available: 1. idx_1 (askid, uid) 2. Is idx_2 (uid, askid) 1 or 2? Use the [sarg] method:
Mysql> select sum (askid = 800808), sum (uid = 110996854) from userresult_f \ G; * *************************** 1. row ************************** sum (askid = 800808 ): 6sum (uid = 110996854): 21 row in set (0.00 sec)

Based on the query output, we should select idx_2
By data Shepherd Good Luck! Fuzhou


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.