SQL Server中Reorganize和Rebuild索引的区别(链接)

下面这篇微软的官方文档,详细阐述了在SQL Server中ReorganizeRebuild索引的区别:

Reorganize and rebuild indexes

 

其中微软给出了一个建议的阈值,如果索引的avg_fragmentation_in_percent值小于等于30%时,建议使用Reorganize,大于30%时,建议使用Rebuild,当然微软也说了这只是一个建议值,具体要根据实际情况对阈值进行调整。

其中索引的avg_fragmentation_in_percent值,可以根据sys.dm_db_index_physical_stats这个系统方法来得到。下面的语句演示了,如何查询数据库AdventureWorks2016中的HumanResources.Employee表下所有索引的avg_fragmentation_in_percent值:

USE AdventureWorks2016

SELECT a.object_id, object_name(a.object_id) AS TableName,
    a.index_id, name AS IndedxName, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats
    (DB_ID (N'AdventureWorks2016')
        , OBJECT_ID(N'HumanResources.Employee')
        , NULL
        , NULL
        , NULL) AS a
INNER JOIN sys.indexes AS b
    ON a.object_id = b.object_id
    AND a.index_id = b.index_id;

关于ReorganizeRebuild索引的区别,还可以参考下面这篇文章:

sql server中index的REBUILD和REORGANIZE

 

你可能感兴趣的:(SQL Server中Reorganize和Rebuild索引的区别(链接))