New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sp_BlitzIndex: add statistics histograms for table-level detail #1900

BrentOzar opened this Issue Jan 2, 2019 · 1 comment


None yet
1 participant
Copy link

BrentOzar commented Jan 2, 2019

Is your feature request related to a problem? Please describe.
When I'm explaining index designs, I like showing the selectivity of different indexes. It's a little painful to run DBCC SHOW_STATISTICS for each stat, or bust out DMV queries.

Describe the solution you'd like
When I run:

sp_BlitzIndex @TableName = 'Users'

When sys.dm_db_stats_histogram is available (2016+), I'd like to add a new result set at the end (after the foreign keys) showing:

screen shot 2019-01-02 at 5 18 53 am

Proof of concept query:

SELECT s.auto_created, s.user_created,, AS column_name, hist.step_number, hist.range_high_key, hist.range_rows, 
    hist.equal_rows, hist.distinct_range_rows, hist.average_range_rows
FROM sys.stats AS s
INNER JOIN sys.stats_columns sc ON s.object_id = sc.object_id AND s.stats_id = sc.stats_id AND sc.stats_column_id = 1
INNER JOIN sys.columns c ON sc.object_id = c.object_id AND sc.column_id = c.column_id
CROSS APPLY sys.dm_db_stats_histogram(s.[object_id], s.stats_id) AS hist
WHERE s.object_id = OBJECT_ID('dbo.Users')
ORDER BY s.auto_created, s.user_created,, hist.step_number;

Describe alternatives you've considered
Adding a column for each index definition in the first result set, giving them DBCC SHOW_STATISTICS or a SELECT from the histogram DMV (depending on their version) that they could run themselves to see the stats on that index.

Are you ready to build the code for the feature?

@BrentOzar BrentOzar self-assigned this Jan 2, 2019

BrentOzar added a commit that referenced this issue Jan 2, 2019

1900 sp_BlitzIndex add histograms
When @TableName is specified and sys.dm_db_stats_histogram is available. Closes #1900.

This comment has been minimized.

Copy link
Member Author

BrentOzar commented Jan 2, 2019

Done! Here's what it looks like:

screen shot 2019-01-02 at 5 54 26 am

Not totally proud of the non-normalized format for last update date on stats, but I know that's the first thing people are gonna ask for.

BrentOzar added a commit that referenced this issue Jan 28, 2019

2019-01 Release (#1932)
* Updating for sp_DatabaseRestore

Documenting @ExistingDBAction for

* 1900 sp_BlitzIndex add histograms

When @TableName is specified and sys.dm_db_stats_histogram is available. Closes #1900.

* #1903 sp_Blitz SQLServerCheckup

Adding filter for that app name. Closes #1903.

* #1905 sp_BlitzIndex remove BOU link

Nothing against BOU, just don't need it in that particular place. Closes #1905.

* #1908 Update copyright dates

Ah, the glamour. Closes #1908.

* Issue #1904 Change RAISERROR 'severity' for that should trigger throw and error.

* Issue #1910 Add SQL Server version check before choosing 'memory grant' as the @BlitzCacheSortOrder.

* Issue #1910 Add temp table creation.

* #1914 sp_BlitzIndex partition error severity

Dropping severity level from 16 to 0 since we're logging it in the result set anyway. Closes #1914.

* Issue 1894 Moved RESTORE HEADERONLY up

* LF line endings

* added some extra checks + corrected some nesting

* rebase and line endings

* Web site commit

Does this fix line endings?

* #1916 sp_Blitz ignore backup on TempDB drive

Closes #1916.

* Auto line endings

Dealing with sp_DatabaseRestore's line endings.

* 1919 sp_Blitz ignoring a few checks for Managed Instances (#1920)

* 1919 sp_Blitz ignoring a few checks for Managed Instances

Working on #1919.

* #1919 sp_Blitz excluding restored databases

When checking backup history. Working on #1919.

* #1919 sp_Blitz ignore some checks on Mgd Instances

Changing RCSI wording on Azure SQL DB. Working on #1919.

* #1921 Sp_BlitzIndex Add Drop and Create Columns to Output (#1923)

Joined output query to #IndexCreateTsql to retrieve the CreateTsql already generated earlier in the script.  Created Drop TSQL based off evaluating what type of index was present.

* #1921 sp_BlitzIndex adding drops (#1924)

Moving drop and create TSQL to the end of mode 2's results. Closes #1921.

* #1925 sp_Blitz AWS RDS detection (#1926)

Don't just rely on EC2 VM name to detect RDS. Also adds a new result noting that checks were skipped. Closes #1925.

* #1927 sp_BlitzIndex skip rdsadmin db (#1928)

GetAllDatabases = 1 fails when it hits rdsadmin because they're referring to the resource db. Closes #1927.

* 2019_01 Release (#1931)

Prep work for the release - changing version numbers, building build scripts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment