Index in database
Index - a database object created to improve the performance of data retrieval.
Datasets can have a large number of records, which are stored in random order, and it can take a long time to search for them according to a given criterion by sequentially scanning the dataset, record by record. The index is formed from the values of one or several fields and pointers to the corresponding records of the data set, thus, a significant increase in the speed of retrieving from this data is achieved.
Benefits
- acceleration of searching and sorting by a specific field or set of fields
- ensuring the uniqueness of data
Disadvantages
- the requirement for additional space on disk and in RAM, and the larger/longer the key, the larger the index size
- Slower insert, update, and delete operations because the indexes themselves have to be updated.
Indexes are preferred for:
- Counter fields to avoid duplicate values in this field;
- The fields by which the data is sorted;
- Fields that are frequently used to connect datasets. Since in this case the data is arranged in ascending order of the index and the connection is much faster;
- The field that is declared as the primary key;
- Fields in which data is selected from a certain range. In this case, as soon as the first record with the required value is found, all subsequent values will be located side by side.
Using indexes is impractical for:
- Fields that are rarely used in queries;
- Fields that contain only two or three values, for example: male, female, or the values "yes", "no".
Read also:
Comments
Post a Comment