Quantcast
Channel: SQL Server Blogs, Events, Webcasts, Videos, SQL Server learning & education » statistics
Viewing all articles
Browse latest Browse all 8

Explore statistics histogram using SQL Server 2017

$
0
0

Prior to SQL Server 2016 SP1 CU2, we need to use DBCC SHOW_STATISTICS WITH HISTOGRAM to read Statistics histogram of a specific statistics. Since it is a DBCC command in order to filter any information or if you want to join with another table, we first need to save the out to a table.

Below is the output of DBCC SHOW_STATISTICS when you read the histogram.

Statistics1

Now sys.dm_db_stats_histogram DMF is available in SQL Server 2016 SP1 CU2 and in SQL Server 2017.

Syntax: sys.dm_db_stats_histogram (object_id, stats_id)

The first parameter is the id of the object, for which properties of one of its statistics is requested. Second parameter is the id of the statistics object. You can get the id of ststiatsics using sys.stats DMV.

It returns information similar to DBCC SHOW_STATISTICS WITH HISTOGRAM.

Statistics2

The range_high_key column is of type sql_variant data type so you need to cast or convert if predicate is compared with a non-string constant.

Now you can join the histogram result with other tables and apply filter on it for further analysis.

 

The post Explore statistics histogram using SQL Server 2017 appeared first on SQL Server Blogs, Events, Webcasts, Videos, SQL Server learning & education.


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images