For Day 27 of this series, we start out with Query #61<\/strong>, which is Volatile Indexes. This query retrieves information from the sys.objects<\/a> object catalog view, the sys.stats<\/a> object catalog view, and the sys.dm_db_stats_properties<\/a> dynamic management function about the most volatile indexes and statistics in the current database. Query #61 is shown in Figure 1.<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/div>\n<\/div>\n Figure 1: Query #61 Volatile Indexes<\/strong><\/p>\n This query shows you which indexes and statistics have had the most updates, which helps you understand your workload in more detail. Understanding which tables, indexes and statistics are most volatile is useful when you are thinking about how to layout your database files, how to design and configure your storage subsystem, and how to handle your index tuning and maintenance.<\/p>\n <\/p>\n Query #62<\/strong> is Index Fragmentation. This query retrieves information from the sys.dm_db_index_physical_stats<\/a> dynamic management function and the sys.indexes<\/a> object catalog view about the fragmentation status for all of the indexes larger than 2500 pages in the current database. Query #62 is shown in Figure 2.<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/div>\n<\/div>\n Figure 2: Query #62 Index Fragmentation<\/strong><\/p>\n This query shows you the current fragmentation status for your heap tables and all indexes above 2500 pages in the current database. This helps you evaluate your index maintenance effectiveness. It is also useful when you are thinking about how you do your index maintenance and whether you might want to consider changing the fill factor on some indexes to reduce how often you need to rebuild or reorganize them.<\/p>\n I would say that most of the customers that I see fall into one of three categories regarding their index maintenance practices: <\/p>\n For Day 27 of this series, we start out with Query #61, which is Volatile Indexes. This query retrieves information from the sys.objects object catalog view, the sys.stats object catalog view, and the sys.dm_db_stats_properties dynamic management function about the most volatile indexes and statistics in the current database. Query #61 is shown in Figure 1. […]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[272],"class_list":["post-1055","post","type-post","status-publish","format-standard","hentry","category-dmv-diagnostic-queries-detailed","tag-dmv-diagnostic-queries-detailed"],"yoast_head":"\n 1:<\/span> -- Look at most frequently modified indexes and statistics (Query 61) (Volatile Indexes)<\/span><\/pre>\n 2:<\/span> SELECT<\/span> o.name AS<\/span> [Object<\/span> Name], o.[object_id], o.type_desc, s.name AS<\/span> [Statistics<\/span> Name], <\/pre>\n 3:<\/span> s.stats_id, s.no_recompute, s.auto_created, <\/pre>\n 4:<\/span> sp.modification_counter, sp.rows<\/span>, sp.rows_sampled, sp.last_updated<\/pre>\n 5:<\/span> FROM<\/span> sys.objects AS<\/span> o WITH<\/span> (NOLOCK)<\/pre>\n 6:<\/span> INNER<\/span> JOIN<\/span> sys.stats AS<\/span> s WITH<\/span> (NOLOCK)<\/pre>\n 7:<\/span> ON<\/span> s.object_id = o.object_id<\/pre>\n 8:<\/span> CROSS<\/span> APPLY sys.dm_db_stats_properties(s.object_id, s.stats_id) AS<\/span> sp<\/pre>\n 9:<\/span> WHERE<\/span> o.type_desc NOT<\/span> IN<\/span> (N'SYSTEM_TABLE'<\/span>, N'INTERNAL_TABLE'<\/span>)<\/pre>\n 10:<\/span> AND<\/span> sp.modification_counter > 0<\/pre>\n 11:<\/span> ORDER<\/span> BY<\/span> sp.modification_counter DESC<\/span>, o.name OPTION<\/span> (RECOMPILE);<\/pre>\n 1:<\/span> -- Get fragmentation info for all indexes above a certain size in the current database (Query 62) (Index Fragmentation)<\/span><\/pre>\n 2:<\/span> -- Note: This query could take some time on a very large database<\/span><\/pre>\n 3:<\/span> SELECT<\/span> DB_NAME(ps.database_id) AS<\/span> [Database<\/span> Name], OBJECT_NAME(ps.OBJECT_ID) AS<\/span> [Object<\/span> Name], <\/pre>\n 4:<\/span> i.name AS<\/span> [Index<\/span> Name], ps.index_id, ps.index_type_desc, ps.avg_fragmentation_in_percent, <\/pre>\n 5:<\/span> ps.fragment_count, ps.page_count, i.fill_factor, i.has_filter, i.filter_definition<\/pre>\n 6:<\/span> FROM<\/span> sys.dm_db_index_physical_stats(DB_ID(),NULL<\/span>, NULL<\/span>, NULL<\/span> , N'LIMITED'<\/span>) AS<\/span> ps<\/pre>\n 7:<\/span> INNER<\/span> JOIN<\/span> sys.indexes AS<\/span> i WITH<\/span> (NOLOCK)<\/pre>\n 8:<\/span> ON<\/span> ps.[object_id] = i.[object_id] <\/pre>\n 9:<\/span> AND<\/span> ps.index_id = i.index_id<\/pre>\n 10:<\/span> WHERE<\/span> ps.database_id = DB_ID()<\/pre>\n 11:<\/span> AND<\/span> ps.page_count > 2500<\/pre>\n 12:<\/span> ORDER<\/span> BY<\/span> ps.avg_fragmentation_in_percent DESC<\/span> OPTION<\/span> (RECOMPILE);<\/pre>\n 13:<\/span> <\/pre>\n 14:<\/span> -- Helps determine whether you have framentation in your relational indexes<\/span><\/pre>\n 15:<\/span> -- and<\/span> how effective your index<\/span> maintenance strategy is<\/pre>\n\n
\n
\n
\n