【发布时间】:2014-07-13 02:37:31
【问题描述】:
我一直在尝试收集有关重建和重组索引的信息。从 stackoverflow 页面 (How Often should the indexes be re-build in sql-server DB?) 我得到了这个查询:
SELECT
t.NAME 'Table name',
i.NAME 'Index name',
ips.index_type_desc,
ips.alloc_unit_type_desc,
ips.index_depth,
ips.index_level,
ips.avg_fragmentation_in_percent,
ips.fragment_count,
ips.avg_fragment_size_in_pages,
ips.page_count,
ips.avg_page_space_used_in_percent,
ips.record_count,
ips.ghost_record_count,
ips.Version_ghost_record_count,
ips.min_record_size_in_bytes,
ips.max_record_size_in_bytes,
ips.avg_record_size_in_bytes,
ips.forwarded_record_count
FROM
sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'DETAILED') ips
INNER JOIN
sys.tables t ON ips.OBJECT_ID = t.Object_ID
INNER JOIN
sys.indexes i ON ips.index_id = i.index_id AND ips.OBJECT_ID = i.object_id
WHERE
AVG_FRAGMENTATION_IN_PERCENT > 0.0
ORDER BY
AVG_FRAGMENTATION_IN_PERCENT, fragment_count
问题是当我重建索引时,avg_fragmentation_in_percent 增加而不是减少。任何指针?如果这是正常行为,那么我在这里缺少什么?
以前 avg_fragmentation_in_percent 为 30,重建后增加到 66。
【问题讨论】:
-
尝试发布表格的填充因子以及表格布局。听起来您需要根据重建结果调整填充因子。
-
@JStead : 我已经上传了屏幕截图.. 填充因子是 0
-
这是一个非常小的索引,基于您拥有的统计数据,此外该表非常瘦。在每一步重建索引时,将填充因子从 95 降低到 70 左右,每块 5 个。如果根据这张表有多小,你得到 10-20% 的碎片范围,我会说它完成了任务。
标签: sql-server sql-server-2008 sql-server-2005 sql-server-2012