database index usage

foreword

    Write a background management system, test the use, and find that loading data is very slow, an average of more than 1 second. After that, I searched for the reason with my colleagues, from the back-end code to the front-end. The final problem was from the database to the design.

What is a database index

    An index is a structure that sorts the values ​​of one or more columns in a database table, and uses an index to quickly access specific information in a database table. The database index is like the table of contents in front of a book, which can speed up the query speed of the database.

    There are two types of indexes: clustered index and non-clustered index . Clustered index is in the order of the physical location of data storage, while non-clustered index is different; clustered index can improve the speed of multi-row retrieval, while Nonclustered indexes are fast for single row retrieval.

What are the pros and cons of indexing?

advantage

First, by creating a unique index, the uniqueness of each row of data in the database table can be guaranteed. 
Second, it can greatly speed up data retrieval, which is the main reason for creating indexes. 
Third, it can speed up table-to-table joins, especially in terms of achieving referential integrity of data. 
Fourth, when using the grouping and sorting clauses for data retrieval, the time for grouping and sorting in the query can also be significantly reduced. 

Fifth, by using the index, the optimization hider can be used in the query process to improve the performance of the system.

shortcoming

First, creating and maintaining indexes takes time, which increases with the amount of data. 
Second, the index needs to occupy physical space. In addition to the data table occupying the data space, each index also occupies a certain amount of physical space. If a clustered index is to be established, the required space will be larger. 

Third, when adding, deleting and modifying the data in the table, the index should also be dynamically maintained, which reduces the speed of data maintenance.

What are the characteristics of the index?

A unique index guarantees that all data in the indexed column is unique and does not contain redundant data.

A compound index is an index created on two or more columns.

In short, the use of indexes is still good.

Guess you like

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