Mysql index selection

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff. 1. Try to index the data columns used for search, classification, or grouping. Do not index the data columns displayed as output. The most suitable data columns with indexes are the data columns in the where clause, the data columns that appear in the join clause, or in the Groupby, Orderby

Welcome to the Linux community forum and interact with 2 million technical staff> 1. Try to index the data columns used for search, classification, or grouping, do not index the data columns displayed as output. The most suitable data columns with indexes are the data columns in the where clause, the data columns that appear in the join clause, or in Group by, Order

Welcome to the Linux community forum and interact with 2 million technicians>

1. Try to index the data columns used for search, classification, or grouping. Do not index the data columns displayed as output.

The data columns with indexes are the data columns in the where clause, the data columns in the join clause, or the data columns in the Group by and Order by clauses. It is best not to use indexes for data columns after select.

2. comprehensively consider the dimensions of each data column.

The dimension of a data column is equal to the number of non-repeated values it contains. For example, if the value of a data column is 1, 2, 3, 3, and 4, the dimension is 3. The higher the dimension, the more suitable it is for indexing. The reason is self-evident.

3. Index short values.

4. Create an index for the prefix of a string.

5. Make full use of the leftmost prefix.

When you create an index that matches n data columns, because the leftmost data column set in the index can use n indexes. A composite index is equivalent to n indexes at work, because the leftmost data column set of the index can be used to match data rows. Such a set is equivalent to the "leftmost prefix". MYSQL cannot use an index without the leftmost prefix.

6. Do not create too many indexes.

Indexes occupy additional disk space and affect write performance. When you have too many indexes, mysql cannot even choose the best index to use.

7. Make the index type match the type of the comparison operation you intend to perform. (Use the keyword using btree for B-tree Indexing ).

8. Use the slow query log to find the query with poor performance. (The Slow query log file is a text file .)

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.