High-performance MySQL (5) Indexing strategy

Source: Internet
Author: User

The advantages of the index

1, the index can greatly reduce the amount of data the server needs to scan

2, the index can help the server avoid sorting and temporary tables.

3, the index can turn I/O into sequential I/O

Second, indexing strategy

1, Independent column

A separate column means that an indexed column cannot be part of an expression, nor can it be a function argument. For example:

A table with a record of 500W, ID is the primary key.

So always place the index column on one side of the comparison symbol.

2, prefix index and index selectivity

For larger columns, you can usually index the starting part of the character, which saves the index space and increases the index rate. But it also lowers the selectivity of the index.

The selectivity of an index is the ratio of a distinct index value (cardinality) to the total number of records in a table, and the higher the selectivity of the index, the higher the query efficiency, since it is possible to filter out more rows in the lookup, the selectivity of the unique index is 1, and the performance is best.

How to choose a suitable length, so that the cardinality of the prefix is close to the cardinality of the complete column, generally we have 2 methods:

A, to determine the appropriate length of the prefix, you need to find a list of the most common values, and then compare them with the most common list of prefixes.

For example: A table with a 100W record to add a prefix index to name

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.