MSSQL Rebuild Index (on-line rebuild, control Max processor count, MAXDOP)

Source: Internet
Author: User
Tags mssql

First, under what circumstances need to rebuild index 1, too many fragments (reference value: >20%)

How index fragmentation occurs, move to the fragmentation and fill factor in the T-SQL query Advanced-sql Server index

2, fill through the Low (reference value: <75%)

Possible causes for the population to pass Low: ①. There is a partition table ③. The clustered index is not a digital ④. Less than the number of millions of data

Ii. reconstruction of the index
ALTER INDEX <  of Index >  on < Table or View name>with=on=4)

Online : on-line execution reduces locks during rebuild (extended execution time)

MAXDOP: Manually configure the maximum number of processors used to run index statements

value Description
0

Specifies that the server determines the number of CPUs used based on the current system workload. This is the default value, or the recommended setting.

1

Cancel the generation of the parallel plan. The operation will be executed serially.

2-64

Limit the number of processors to the specified value. depending on the current workload, fewer processors may be used. if the specified value is greater than the number of available CPUs, the actual number of available CPUs will be used.


third, extended notes:

Workaround for fragmentation (referenced from: Song and fill factor in SQL Server index)

Basically all of the solutions are based on the reconstruction and collation of the index, but in a different way

1. Delete the index and rebuild

This is not a good way. The index is not available during the drop index. Causes blocking to occur. In the case of dropping a clustered index, it causes the corresponding nonclustered index to be rebuilt two times (when the deletion is rebuilt, and then rebuilt at build time). Although this method is not good, it is most effective for index collation.

2. rebuilding an index using the DROP_EXISTING statement

To avoid rebuilding two indexes, use the DROP_EXISTING statement to rebuild the index, because the statement is atomic and does not cause nonclustered indexes to be rebuilt two times, but the same way it can cause blocking

3. use the ALTER INDEX rebuild statement to rebuild the index as shown in the previous article

Using this statement also rebuilds the index, but it does not need to unload and rebuild the index by dynamically rebuilding the index. is superior to the first two methods, but will still cause blocking. You can reduce the lock by using the online keyword, but it will cause the rebuild time to be extended.

4. using the Alter INDEX REORGANIZE

This method does not rebuild the index, nor does it generate a new page, it simply organizes and skips when a locked page is encountered, so it does not cause blocking. But at the same time, the finishing effect will be worse than the first three kinds.

MSSQL Rebuild Index (on-line rebuild, control Max processor count, MAXDOP)

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.