July, the 31 Days of SQL Server DMO’s – Day 28 (sys.dm_db_stats_properties)
Posted
by Tamarick Hill
on SQL Blog
See other posts from SQL Blog
or by Tamarick Hill
Published on Sun, 28 Jul 2013 15:06:28 GMT
Indexed on
2013/08/02
15:53 UTC
Read the original article
Hit count: 448
The sys.dm_db_stats_properties Dynamic Management Function returns information about the statistics that are currently on your database objects. This function takes two parameters, an object_id and a stats_id. Let’s have a look at the result set from this function against the AdventureWorks2012.Sales.SalesOrderHeader table. To obtain the object_id and stats_id I will use a CROSS APPLY with the sys.stats system table.
SELECT sp.* FROM sys.stats s
CROSS APPLY sys.dm_db_stats_properties(s.object_id, s.Stats_id) sp
WHERE sp.object_id = object_id('Sales.SalesOrderHeader')
The first two columns returned by this function are the object_id and the stats_id columns. The next column, ‘last_updated’, gives you the date and the time that a particular statistic was last updated. The next column, ‘rows’, gives you the total number of rows in the table as of the last statistic update date. The ‘rows_sampled’ column gives you the number of rows that were sampled to create the statistic. The ‘steps’ column represents the number of specific value ranges from the statistic histogram. The ‘unfiltered_rows’ column represents the number of rows before any filters are applied. If a particular statistic is not filtered, the ‘unfiltered_rows’ column will always equal the ‘rows’ column. Lastly we have the ‘modification_counter’ column which represents the number of modification to the leading column in a given statistic since the last time the statistic was updated.
Probably the most important column from this Dynamic Management Function is the ‘last_updated’ column. You want to always ensure that you have accurate and updated statistics on your database objects. Accurate statistics are vital for the query optimizer to generate efficient and reliable query execution plans. Without accurate and updated statistics, the performance of your SQL Server would likely suffer.
For more information about this Dynamic Management Function, please see the below Books Online link:
http://msdn.microsoft.com/en-us/library/jj553546.aspx
Folllow me on Twitter @PrimeTimeDBA
© SQL Blog or respective owner