检查SQL Server 2005的索引密度和碎片信息(转)
时间:2021-07-01 10:21:17
帮助过:2人阅读
i.name
AS indexname,
o.name
AS tablename,
s.name
AS schemaname,
f.index_type_desc
AS indextype,
f.avg_page_space_used_in_percent
AS indexdensity,
f.avg_fragmentation_in_percent
AS indexfragmentation,
f.page_count
AS pages
FROM sys.dm_db_index_physical_stats(DB_ID(),
NULL,
NULL,
NULL, ‘
SAMPLED‘) f
INNER JOIN sys.objects o
ON o.object_id = f.object_id
INNER JOIN sys.schemas s
ON o.schema_id = s.schema_id
INNER JOIN sys.indexes i
ON f.object_id = i.object_id AND f.index_id = i.index_id
WHERE page_count > 50
AND f.index_id > 0
ORDER BY o.name, i.index_id
LIMITED | SAMPLED | DETAILED | NULL | DEFAULT
这些模式影响了如何收集碎片数据。LIMITED模式扫描堆所有的页,但对于索引,则只扫描叶级上面的父级别页。SAMPLED收集在堆或索引中1%采样
率的数据。DETAILED模式扫描所有页(堆或索引)。DETAILED是执行最慢的,但也是最精确的选项。指定NULL或DEFAULT的效果与
LIMITED模式的相同。
检查SQL Server 2005的索引密度和碎片信息(转)
标签: