Advantages and disadvantages of database creation indexes

Source: Internet
Author: User

Why do you create an index? This is because creating an index can greatly improve the performance and benefits of the system:
first, by creating a unique index, you can guarantee the uniqueness of each row of data in a database table.
second, it can greatly speed up the retrieval of data, which is the main reason for creating indexes.
Thirdly, the connection between tables and tables can be accelerated, particularly in terms of achieving referential integrity of the data.
Finally , when using grouping and sorting clauses for data retrieval, you can also significantly reduce the time to group and sort in queries.
by using the index, we can improve the performance of the system by using the optimized hidden device in the process of querying.

Perhaps someone will ask: there are so many advantages to adding indexes, why not create an index for each column in the table?
Although this kind of thought has its rationality, but also has its one-sidedness. Although indexes have many advantages, it is very unwise to add indexes to each column in a table.
This is because increasing the index also has many disadvantages in one aspect, the disadvantage :
first, it takes time to create indexes and maintain indexes, and this time increases as the amount of data increases.
second, the index needs to occupy the physical space, in addition to the data table to occupy the data space, each index also occupies a certain amount of physical space, if you want to establish a clustered index, then the space will be larger.
Thirdly, when the data in the table is added, deleted and modified, the index should be maintained dynamically, thus reducing the maintenance speed of the data.

indexes are built on top of some columns in a database table. Therefore, when you create an index, you should carefully consider which columns you can create an index on, and on which columns you cannot create an index. In general, you should create indexes on these columns,
For example, you can speed up your search on columns that you often need to search for;
(1) on the column that is the primary key, enforce the uniqueness of the column and the arrangement of the data in the organization table;
(2) often used in connected columns, these columns are mainly foreign keys, you can speed up the connection;
(3) Create an index on a column that is often required to search by scope, because the index is sorted and its specified range is continuous;
(4) Create indexes on columns that often need to be sorted, because the index is sorted so that the query can use the sorting of the index to speed up the sorting query time;
(5) speed up the judgment of the condition by creating an index on the column that is often used in the WHERE clause.

Similarly, indexes should not be created for some columns. In general, these columns that should not be indexed have the following characteristics:
(1) For those columns that are seldom used or referenced in the query, the index should not be created. This is because, since these columns are seldom used, they are indexed or non-indexed and do not improve query speed. Conversely, by increasing the index, it reduces the system maintenance speed and increases the space requirement.
(2) You should not increase the index for columns that have only a few data values. This is because, because these columns have very few values, such as the gender column of the personnel table, in the results of the query, the data rows of the result set occupy a large proportion of the data rows in the table, that is, the data rows that need to be searched in the table are large. Increase the index,
Does not significantly speed up the retrieval.
(3) For those columns that are defined as text, the image and bit data types should not increase the index. This is because the amount of data in these columns is either quite large or has very little value.
(4) You should not create an index when the performance of the modification is far greater than the retrieval performance. This is because modifying performance and retrieving performance are conflicting.
When you increase the index, the retrieval performance is improved, but the performance of the modification is reduced. When you reduce the index, you increase the performance of the modification and reduce the retrieval performance. Therefore, you should not create an index when the performance of the modification is far greater than the retrieval performance.

Advantages and disadvantages of database creation indexes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.