首先,我已经用这个脚本确定了碎片:
SELECT
B.name AS TableName
,C.name AS IndexName
,C.fill_factor AS IndexFillFactor
,D.rows AS RowsCount
,A.avg_fragmentation_in_percent
,A.page_count
FROM
sys.dm_db_index_physical_stats(DB_ID(),NULL,NULL,NULL,NULL) A
INNER JOIN
sys.objects B
ON
A.object_id = B.object_id
INNER JOIN
sys.indexes C
ON
B.object_id = C.object_id AND A.index_id = C.index_id
INNER JOIN
sys.partitions D
ON
B.object_id = D.object_id AND A.index_id = D.index_id
WHERE
C.index_id > 0
order by
avg_fragmentation_in_percent desc
然后我执行了重组或重建这样的脚本:
alter index IX_ind1
on TABLE1
reorganize
alter index IX_ind2
on TABLE1
rebuild
我如何知道重建过程是否有效?
我可以查看有关这些索引的查询列表吗?如何在重建之前和重建之后比较查询?
答案 0 :(得分:0)
一个简短而快速的解决方法是创建一个表并将查询中的所有结果存储到其中,以及另一个布尔列IsBeforeRebuildOfIndexes
。
然后,您可以查询并比较之前和之后是否有改进。