MSSQL: Index Heatmaps in TreeView Format

Would you like to know which indexes are used frequently or rarely? Which ones aren't used at all? Which tables and indexes are the largest? It's very easy to create visualizations for this. They're both visually appealing and practically useful.

Environment Setup

As always, we'll extract data from production where you likely can't install anything. Therefore, we'll do all the work on our local machine while transferring data from the server.

You'll need:

The stored procedure from heatmap.sql needs to be installed on your target server in a "technical" database (the kind that exists everywhere under various names). Everything else is done on your personal computer.

Creating the Diagram

Execute the procedure on your target server. Save the results as CSV and transfer to your local machine. The Python program interface works as follows:

For example, if you have size.csv, run

You'll get in your browser a familiar TreeView visualization with a thermal color palette, where colors represent "temperature" based on the logarithm of one of the metrics (seeks, scans, updates). All values are displayed in tooltips.

The diagram is "live" and clickable. It retains these properties if you save the entire page from your browser as HTML file(s).

What Can You Discover with This Diagram?

Remember that data in sys.dm_db_index_usage_stats accumulates since server startup. After a restart, allow sufficient time to collect relevant statistics.

If you have AlwaysOn with secondary nodes that allow reads, you might find indexes that are useless on the primary node but valuable on secondaries (this can happen when, for example, the primary handles OLTP while secondaries handle OLAP/Reporting).

Key metrics interpretation:

@Tzimie
20.05.2025 13:33 UTC
Первоисточник