Seven common principles for rational use of index queries

Source: Internet
Author: User

Index query is an important record query method in the database, if you want to enter the index and the index on those fields should be combined with the actual database system query requirements, the following gives some practical general principles:

1. Indexing on fields that are often used as filters;

2. In the SQL statement often in the group by, order by the field to establish the index;

3. There is no need to establish indexes in fields with fewer values, such as gender fields;

4. Avoid indexing of frequently accessed columns;

5. Indexing of columns used for joins (main/external);

6. Establish a composite index on multiple columns that are frequently accessed, but note that the order in which the composite index is established is determined by the frequency of use;

7. A nonclustered index is established by default. However, it is a good idea to consider a clustered index, such as a limited number of (not very few) unique columns, a wide range of queries, and a full use of the index to reduce the number of table scan i/0 and effectively avoid searching the entire table. Of course, a reasonable index should be based on the analysis and prediction of various queries, and also on the database structure designed by the DBA.

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.