我有一个非常简单的标准查询来显示数据库中索引的碎片,如下所示:
SELECT DB_NAME(DB_ID()) AS DatabaseName,
OBJECT_NAME(ddips.[object_id]) AS TableName,
ind.[name] AS IndexName,
ddips.index_type_desc AS IndexType,
ddips.avg_fragmentation_in_percent AS FragmentationPercentage,
ddips.fragment_count AS FragmentCount,
ddips.avg_fragment_size_in_pages AS AvgFragmentSizeInPages,
ddips.page_count AS [PageCount]
FROM sys.dm_db_index_physical_stats (DB_ID(), null, null, null, null) AS ddips
INNER JOIN sys.indexes ind on ind.[object_id] = ddips.[object_id]
ORDER BY ddips.avg_fragmentation_in_percent DESC
然而,当我运行它时,我看到完全相同的数据 - 相同的表名、索引名和索引类型 - 以不同百分比的碎片返回多次。下面是一个例子:
我不明白这些结果。当我在 SSMS 中打开表时,打开索引,然后转到 Fragmentation 页面,它告诉我最低的数字 1.71% 是碎片。所有这些其他碎片数字来自哪里?谁能帮助解释这些结果?非常感谢。