How Indexes Work, Pros and Cons

What is an index:
It is a collection of one or several column values ​​in a table and a corresponding list of logical pointers to the data pages in the table that physically identify these values. The function of the index is equivalent to the directory of the book.

Working
principle: when there are a large number of records in the table, if you want to query the table, the first way to search for information is to search the entire table, which is to take out all the records one by one, and carry out a search with the query conditions. A comparison, and then return the records that meet the conditions, this will consume a lot of database system time, and cause a lot of disk I/O operations; the second is to create an index in the table, and then find the index value in the index that meets the query conditions, Finally, quickly find the corresponding record in the table through the ROWID (equivalent to the page number) stored in the index.


An index is a decentralized storage structure created to speed up the retrieval of data rows in a table. An index is built on a table and consists of index pages other than data pages. The rows in each index page contain logical pointers to speed up retrieval of physical data.

Advantages
1. Greatly speed up the retrieval of data;
2. Create a unique index to ensure the uniqueness of each row of data in the database table;
3. Speed ​​up the connection between tables;
4. Use grouping and sorting clauses for data When retrieving, the grouping and sorting time in the query can be significantly reduced.


Disadvantages
1. The index needs to occupy physical space.
2. When adding, deleting and modifying the data in the table, the index should also be dynamically maintained, which reduces the data maintenance speed.


Common index, unique index, primary key index and clustered index, bitmap index (oracle), full-text index (mysql)

Guess you like

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