MySQL Composite Index

Source: Internet
Author: User

One

1. The fewer indexes, the better, when the data is modified, the first index is updated to reduce the write speed.
2. The narrowest field is placed on the left side of the key
3. Avoid file sort sorting, temporary tables, and table scans.

Second, the establishment of composite Index principles:

If you are likely to perform a search more than once on only one column, the column should be the first column in the composite Index. If you are likely to perform a separate search for two columns in a two-column index, you should create another index that contains only the second column.
As shown, if you need to query for age and gender in your query, you should create a new composite index that contains age and gender.
A primary key that contains multiple columns is always automatically created as a composite index, in the order in which they appear in the table definition, rather than in the order specified in the primary key definition. Determine which column should be at the top, considering the search that will be performed by the primary key in the future.
Note that creating a composite index should contain a few columns, and these columns are often used in select queries. Including too many columns in a composite index does not give you too much benefit. And because of the amount of memory used to store the values of the columns of the composite index, the consequence is memory overflow and performance degradation.


If the query condition of a like statement does not start with a wildcard character, the index is used.
such as:% Car or% car% do not use index.
Vehicle% use index.

MySQL Composite Index

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.