mysql index

1. What is an index?

Index Index is a data structure that helps MySQL obtain data efficiently. It can be simply understood as "sorted fast lookup data structure"

The essence of indexes: indexes are data structures

The purpose of index: to improve query efficiency

Generally speaking, the index itself is also very large, and it is impossible to store all of it in memory, so the index is often stored on disk in the form of an index file

 

2. What situations need to be indexed

1. The primary key automatically creates a unique index

2. Fields that are frequently used as query conditions

3. Fields associated with the gas table in the query, foreign key relationships

4. The sorting field in the query, if the sorting field is accessed through the index, the sorting speed will be greatly improved

5. The choice of single key / composite index (high concurrency tends to create composite index)

6. Statistics or grouping fields in the query

 

3. What situations are not suitable for creating indexes

1. Frequently updated fields. Because the update not only updates the record, but also updates the index

2. Fields that are not used in the where condition

3. Too few table records

4. Tables that are frequently added, deleted and modified (for example, when updating a table, not only the data but also the index file must be saved)

5. Table fields with repeated and evenly distributed data (building an index for him does not have much practical effect)

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326326973&siteId=291194637
Recommended