Table index (index design principle) detailed explanation

Table of contents

foreword

1. Choose a unique index

2. Suggest indexes for fields that often require sorting, grouping, and union operations

3. Create indexes for fields that are often used as query conditions

Fourth, limit the number of indexes

5. Try to use indexes with less data

6. Try to use prefixes to index

7. Delete indexes that are no longer used or rarely used


foreword

        In order to make the index more efficient, when creating an index, you must consider which fields to create the index on and what type of index to create. This section describes some design principles for indexes.


1. Choose a unique index

        The value of the unique index is unique, and a record can be determined more quickly through the index. For example, the student number in the student table is a unique field. Building a unique index for this field can quickly determine the information of a certain student. If the name is used, the same name may exist, thereby reducing the query speed.

2. Suggest indexes for fields that often require sorting, grouping, and union operations

        Fields that often require operations such as ORDER BY, GROUP BY, DISTINCT, and UNION will waste a lot of time in sorting operations. If they are indexed, sorting operations can be effectively avoided.

3. Create indexes for fields that are often used as query conditions

        If a field is often used as a query condition, the query speed of this field will affect the query speed of the entire table, and indexing such a field can improve the query speed of the entire table.

Fourth, limit the number of indexes

        The number of indexes is not as many as possible. Each index needs to occupy disk space. The more indexes, the more disk space is required. When modifying the table, it is very troublesome to reconstruct and update the index.

5. Try to use indexes with less data

        If the indexed value is very long, then the speed of the query will be affected. For example, a full-text search of a field of type CHAR(100) will definitely take more time than a field of type CHAR(10).

6. Try to use prefixes to index

        If the indexed value is long, it is better to use a prefix of the value to index. For example, for fields of type TEXT and BLOG, it would be a waste of time to perform a full-text search. If only a few characters in front of the field are searched, the search speed can be improved.

7. Delete indexes that are no longer used or rarely used

        After a large amount of data in the table is updated, or the way the data is used is changed, some original indexes may no longer be needed. DBAs should regularly identify these indexes and delete them to reduce the impact of indexes on update operations.

Guess you like

Origin blog.csdn.net/m0_65635427/article/details/130383608