Quantcast
Viewing all articles
Browse latest Browse all 10

Statistics metadata

So, statistics. The information relating to statistics comes from [sys].[stats] and [sys].[stats_columns], so let's get straight in and have a look at those two tables:

object_idThis is the ID of the object on which the statistics were created.
nameThis is the name of the statistics. Like indexes, you cannot have more than one set of stats on an object with the same name, but sets of stats on different objects can share the same name. Auto-generated stats have names starting with '_WA_Sys'.
stats_idThis is the unique ID of the statistics within the entry.
auto_createdThis is 1 if the statistics were auto-created by the query processor. These will only appear if AUTO_CREATE_STATISTICS has been set on for the database using ALTER DATABASE.
user_createdThis is 1 if the statistics were created manually
no_recomputeThis is 1 if the statistics were created with the NORECOMPUTE option, meaning that statistics are not recomputed automatically. This can be a good idea for static data, but seeing as statistics recompution is triggered by 20% of the rows of the underlying object changing, is mostly without merit.
has_filterLike indexes, from SQL Server 2008 onwards, statistics could be filtered using a WHERE clause style filter. Again, like indexes, this column will be 1 if such a filter exists.
filter_definitionThis column will contain the definition of the statistics filter if one is specified, or NULL if not.

So, that's the basics of statistics covered - so what about the involved columns? For that information, we look to [sys].[stats_columns]:

object_idThis is the ID of the object on which the statistics were created.
stats_idThis is the same as the stats_id column from [sys].[stats].
stats_column_idThis is the ID of the column within in the statistics (i.e. giving a sequential number to the columns involved).
column_idThis is the ID of the column covered by the statistics, and can be matched with [sys].[columns] for any given object_id value.

Job done - we now know everything we need to about stats and their metadata. Notice that there are a lot less columns than for indexes, because there isn't any scope for included columns or partitioning, and the order and ascendency of the columns sampled does not matter.

We'll take a break from the metadata series for a while, and posts will be on a variety of topics relating to SQL Server.


Viewing all articles
Browse latest Browse all 10

Trending Articles