Fix database index problems: delete indexes to improve performance

Source: Internet
Author: User
Creating an index on a database will negatively affect the database. When you insert, update, and delete a table, you will see a negative impact on this performance. Each time you make a modification to the table, the indexes that contain the modification records must be updated to comply with the latest modification.

After filtering indexes, the number of indexes to be updated is reduced. However, indexes containing these records still need to be updated when the record is modified.

Because these operations must be performed at each data modification, you should delete the indexes not used for data query in the database. This reduces the I/O requirements and size of the database.

To search for unused indexes, you can use the following query statement to query the SYS. dm_db_index_usage_stats dynamic management view.

selectobject_name (sys. indexes. object_id) tablename,
sys. indexes. name,
sys. dm_db_index_usage_stats.user_seeks,
sys. dm_db_index_usage_stats.user_scans,
sys. dm_db_index_usage_stats.user_lookups,
sys. dm_db_index_usage_stats.user_updates
fromsys. dm_db_index_usage_stats
joinsys. indexesonsys. dm_db_index_usage_stats.object_id = sys. indexes. object_id
andsys. dm_db_index_usage_stats.index_id = sys. indexes. index_id
andsys. indexes. name notlike 'pk % '
andobject_name (sys. indexes. object_id) <> 'sysdiagrams '
wheresys. dm_db_index_usage_stats.database_id = db_id ()
and user_scans = 0
and user_scans = 0
and user_lookups = 0
and user_seeks = 0
andsys. dm_db_index_usage_stats.index_id notin (0, 1)
orderbyobject_name (sys. indexes. object_id),
sys. indexes. name

Create a file group

An important way to improve index performance is to create one or more file groups to store non-clustered indexes. Only the tables corresponding to the non-clustered index and the index can be stored in different file groups. If you want to create a clustered index in a different file group from the table, SQL Server will move the table to the new file group regardless of whether it is based on the primary key or not.

Separating a non-clustered index from a basic table transfers the storage and I/O requirements of indexes from the table corresponding to the index to other file groups, reducing the time required to modify the index. Although using multiple file groups in your database increases the database management load, this improvement is worthwhile.

When creating a physical file for the second file group, you must save the file to another group of physical disks so that the workload can actually be transferred to different regions. If both physical files are stored in the same physical area, this improvement will not be significant even if you can get some performance improvements.

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.