[MySQL] Precautions for creating and using B+ tree index

Indexes can be used to reduce the number of records that need to be scanned, as well as for sorting and grouping.

When using an index to reduce the number of records that need to be scanned, you should first find the corresponding scan interval when using the index to execute the query and the boundary conditions that form the scan interval, and then you can scan the records in each scan interval. If you are scanning secondary index records, and if you need complete user records, you need to perform a table return operation based on the obtained primary key value of each secondary index record.

Keep the following in mind when creating and using indexes

  • Only create indexes for columns used for searching, sorting or grouping;
  • When the number of unique values ​​in the column accounts for a large proportion of the total number of records, the column is indexed and the type of the index column is as small as possible;
  • You can create an index only for the prefix of the index column to reduce the storage space occupied by the index. Try to use the covering index for query to avoid the performance loss caused by the table operation;
  • Let the index column appear in the search condition alone in the form of the column name. In order to minimize the page split of the clustered index, it is recommended to let the primary key have the AUTO_INCREMENT attribute;
  • Locate and drop redundant and duplicate indexes on the table.

——"How does MySQL work" reading notes

Guess you like

Origin blog.csdn.net/xiaoyue_/article/details/130335974