Principles of database creation indexing

Source: Internet
Author: User

The principles   Indexes of database creation indexes can increase the speed of data access, but it also increases the processing time for INSERT, update, and delete operations. So whether you want to add indexes to the table, and the indexes on those fields, is an issue that must be considered before you create the index. This problem is solved by analyzing the application's business processes, data usage, and indexing the fields that are often used as query criteria or ordered.   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.   www.2cto.com   Generally choose to create an index on such a column:  1.     Creating an index on a column that often requires search queries can speed up the search;  2.     Creates an index on the column that is the primary key, enforces the uniqueness of the column, and arranges the structure of the data in the organization table;  3.     often creates indexes on connected columns, which are mainly foreign keys that can speed up the connection;  4.     Create an index on a column that often needs to be searched by scope, because the index is sorted and its specified range is continuous;  5.     Create indexes on columns that often need to be sorted, because the indexes are sorted so that the query can take advantage of the sorting of the indexes to speed up the sort query time;  6.     Creates an index on the columns used frequently in the WHERE clause to speed up the judgment of the condition;  7.     Indexes The fields that often appear after the keyword order BY, group by, and distinct.    generally does not choose to create an index on a column that has these characteristics:  1.     You should not create an index for columns that are seldom used or referenced in queries. 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.     Do not create an index on a field that has a large number of identical 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. Increasing the index does not significantly speed up the retrieval;  3.     For those columns that are defined as text, the image and bit data types are notThe index should be increased. This is because the amount of data in these columns is either quite large or has little value;  4.     You should not create indexes when modifying performance is far greater than retrieving 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.   Create an index to be aware of where:  www.2cto.com  1.     Limit the number of indexes on the table. For a table that has a large number of update operations, the number of indexes is typically no more than 3, not more than 5. Although the index improves access speed, too many indexes can affect the update operation of the data.  2.     Avoid indexing fields that are growing in one direction (for example, fields of date types), and compound indexes to avoid placing fields of this type at the front. Since the value of the field always grows in one direction, the new record is always placed in the last leaf page of the index, which constantly causes the access competition of the leaf page, the allocation of the new leaf page, and the split of the intermediate branch page. In addition, if the index is a clustered index, the data in the table is placed in the order of the index, and all inserts are centered on the last data page, causing the "hot spot" to be inserted.  3.     The composite index, indexed by the frequency with which the field appears in the query condition. In a composite index, a record is first sorted by the first field. For records with the same value on the first field, the system is sorted by the value of the second field, and so on. Therefore, only the first field of the composite index appears in the query condition, and the index may be used. Therefore, the application of high frequency fields, placed in front of the composite index, will make the maximum possible use of this index, the role of the index.  4.     Delete indexes that are no longer used, or are rarely used. Some of the existing indexes may no longer be needed after the data in the table has been extensively updated, or if the data has been used in a different way. The database administrator should periodically identify these indexes and remove them, thereby reducing the impact of the index on the update operation.

Principles for creating indexes on databases

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.