查询索引碎片的查询需要很长时间 [英] Query to check index fragmentation is taking very long time
问题描述
亲爱的团队,
我们正在使用以下查询来查找索引碎片,但查询花了将近20分钟来执行并获取所有结果集 我们的生产环境: -
We are using the below query to find index fragmentation but the query is taking almost 20 minutes to execute and fetch the result set in all our production environment :-
SELECT OBJECT_NAME(i.OBJECT_ID)AS [表名称],i.name AS [索引名称],ROUND(indexstats.avg_fragmentation_in_percent,2)as [Fragmentation Percent] FROM sys.dm_db_index_physical_stats( < DB_ID> ,
NULL,NULL,NULL,'DETAILED')indexstats INNER JOIN sys.indexes i ON i.OBJECT_ID = indexstats.OBJECT_ID AND i .index_id = indexstats.index_id WHERE indexstats.avg_fragmentation_in_percent> 30
请确认是否 它&NBSP;是正常还是我需要查看更多内容。
Please confirm whether it is normal or I need to check something more .
感谢您的合作与协助。
最诚挚的问候,
桑迪
Best Regards,
Sandy
推荐答案
你可能有很多桌子 与详细参数一起需要很长时间。尝试在巨大的桌子上运行脚本
You probably have lots of tables along with DETAILED parameter it takes long time. Try running script on huge tables
你也可以 将详细信息更改为有限....
You can also change DETAILED to LIMITED....
SELECT avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats
(
DB_ID( 'testdb'),$
OBJECT_ID('dbo.T1'),
1,
NULL,
NULL
);
SELECT avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats
(
DB_ID('testdb'),
OBJECT_ID('dbo.T1'),
1,
NULL,
NULL
);
这篇关于查询索引碎片的查询需要很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!