码迷,mamicode.com
首页 > 其他好文 > 详细

查找索引碎片Find Index Fragmentation Details – Slow Index Performance

时间:2014-09-09 15:42:48      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   ar   strong   for   

SQL SERVER – 2005 – Find Index Fragmentation Details – Slow Index Performance

Just a day ago, while using one index I was not able to get the desired performance from the table where it was applied. I just looked for its fragmentation and found it was heavily fragmented. After I reorganized index it worked perfectly fine. Here is the quick script I wrote to find fragmentation of the database for all the indexes.

SELECT ps.database_id, ps.OBJECT_ID,
ps.index_id, b.name,
ps.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS ps
INNER JOIN sys.indexes AS b ON ps.OBJECT_ID = b.OBJECT_ID
AND ps.index_id = b.index_id
WHERE ps.database_id = DB_ID()
ORDER BY ps.OBJECT_ID
GO

 

You can REBUILD or REORGANIZE Index and improve performance. Here is article SQL SERVER – Difference Between Index Rebuild and Index Reorganize Explained with T-SQL Script for how to do it.

查找索引碎片Find Index Fragmentation Details – Slow Index Performance

标签:des   style   blog   http   color   io   ar   strong   for   

原文地址:http://www.cnblogs.com/mywiki/p/3962542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!