r/SQLServer • u/chadbaldwin • Oct 22 '25
Discussion Index usage analysis for large single tenant environments - Are there any good solutions?
I'm doing some research for my company into finding (or building) a tool for helping with index usage and analysis. I've already posted this in the SQL Server community slack and already have a few things on my list from there. I'm asking here as well to do a bit more crowdsourcing.
I'm asking here to see if any of you are aware of any solutions which can cover our needs.
The issue is, we are a large single tenant environment. We have hundreds of customers each with a dedicated database. On top of that, we have a very large (and old) schema...
Just to give you an idea: * 16,000 procs * 4,000 tables * 90% of tables have a clustered index * 4,000 total non-clustered indexes * Many tables having well over 10 indexes
That's PER database...and we have hundreds and hundreds of databases.
Our goal is to find (or build) a system that can track all ~5M indexes and provide the ability to identify indexes that are: * Missing (new index suggestions) * Unused * Underutilized * Duplicate * Overlapping * Mergeable * Bad clustered index * Missing clustered index (heaps) * Index drift (some tenant DBs have the index, others don't, or the index is different)
To be clear, I'm not asking about index maintenance, we already have that covered.
The key thing that makes things difficult is that it needs to be able to aggregate across tenants. Just because an index isn't used by some customers doesn't mean it's unused by all customers. Similar to how you would handle index analysis across availability groups.
We accept there will be some "intentional drift" because the top 10% of our customer databases are going to be special cases due to their workloads, usage patterns and database size. But for the most part, we expect all databases to have the same set of indexes.
At this point, I've been unable to find any off-the-shelf solutions that handle all the things we want to check for. And it seems that we'll need to build something ourselves using one or more of the solutions below.
Just to list what I'm already aware of: * Brent Ozar's First Responder Kit - sp_BlitzIndex * Erik Darling's sp_IndexCleanup * Tiger Toolbox's index scripts * Missing indexes * Overlapping indexes * Glenn Berry's Diagnostic Queries * serenefiresiren's (aka Court) PerformanceLogging solution * Shameless self plug - My scripts / projects: * sys-schema-sync tool for creating a centralized location for common DMVs * Missing indexes * Overlapping indexes * Index stats * SQL Server System DMVs - too many to list
4
u/SQLBek 1 Oct 22 '25
Beyond what you've listed, no such "index specific" system exists that will accomplish everything on your requirement list.
You'll have to utilize a combination of the above and/or roll up your sleeves for some custom analysis.
3
u/InsoleSeller 1 Oct 22 '25
What is the problem you're trying to solve?
You have DMVs to track index usage, you can start from there. But what is your goal? Are you having performance issues?
2
u/mrpink70 Oct 22 '25
I think you could check for index drift across all of your databases using SSDT/sqlpackage. If you have a database that you consider a "gold copy" that would be easy enough to wrap up in a PowerShell script.
I think that's where I'd probably start but the rest of your requirements will more challenging. I'm not aware of anything that already exists for all of those other bullet points.
1
u/VladDBA βͺ βͺMicrosoft MVP βͺ βͺ Oct 22 '25
sp_BlitzIndex modes 2 and 0 (or 4 if you want the additional checks that come with it) should give you most of what you need.
Mode 2 gives you lots of information for existing indexes (usage, writes vs reads, seeks or scans, lock wait times) and heaps. You can also use this for index drift if you log the output to a table and compare between databases/environments - but you'll have to write your own queries to do the comparison.
Mode 0 or 4 will give you diagnostics and recommendations for missing indexes, unused (indexes with more writes than reads or with 0 reads), duplicates and overlapping, as well as missing clustered indexes (the "should this table be a heap?" finding).
Bad clustered indexes you'll most likely have to get by combining information from mode 2 with your query patterns.
One example that comes to mind here is where I ended up adjusting a clustered index (which was already composite based on two INT columns) by adding a third INT column to the clustering key because our application always filtering for those 3 specific columns and returned pretty much all of the columns.
The original version of the index caused a residual predicate for that third column which in turn increased the lock waits on the clustered index, adding the third column to the clustering key sorted that out.
1
u/xerxes716 Oct 22 '25
I just created a script that runs every night that captures index usage, appends to data that has already been collected, and only creates new data for an index when the server restarts. Then I have a view to aggregate it all together so I can evaluate data across restarts. We patch monthly so the stuff in memory goes away once per month. Keeping the info across multiple months is good for valuating processes that only happen monthly or quarterly. An index looks to be unused but then you remove it and that quarterly process goes from 30 minutes to 30 hours.
1
u/Black_Magic100 Oct 22 '25
I'm just focusing on Index drift between customers. Index drift is extremely easy to alert on if you have some form of standard nomenclature that can be used to automate the checks; otherwise you will have to manually map entities to each other and that's a pain to manage.
1
u/jshine13371 6 Oct 22 '25
Not sure why
sp_BlitzIndexdoesn't get you what you need? It's the gold standard here.If you have multiple databases you need to analyze then 10 lines of dynamic SQL will generate you the script to run it for all databases and put the results into the same temp table so it can be aggregated.
IMO, you'd probably be better served though by storing the results of each database individually within the respective database, and then creating a report (e.g. SSRS or PowerBI - whatever floats your boat) that aggregates all the databases data together for you. Can even easily build out drilldowns from the aggregate so you can look at it per tenant or by smart metrics like "top 10..." etc.
1
u/Menthalion Oct 22 '25 edited Oct 22 '25
We're practically in the same boat, and I'm currently working on a system that gathers the basic index info that's the basis of sp_indexinfo over all our 10000-ish acc and prod databases and stores them in parquet files.
I can then load these into Jupyter notebooks for offline analysis, like detecting duplicate/subindexes, poison indexes, etc. similar to sp_indexinfo. Except this way I can also take into account usage or suggestion info in percentiles over customers, and find out the commonalities between the outliers.
We're also thinking being able to track customer specific index changes, and how much and which we rolled out of these over which customers would be really useful. We decided a specific naming scheme combined with regular exports mentioned before could do the trick of maintaining a library of customisations.
1
u/Important_Cable_2101 Oct 23 '25
I would save some time and install some monitoring tool like Redgate monitor. If tool comes in short for analysis then just query the collected data yourself.
1
u/asdfse Oct 23 '25
A lot of recommendations are ps scripts or sql based solutions. with this amount of data i would try to avoid both. consider writing a application in a moderately performant language and use it to collect the raw data you need from each db. based on the amoumt of data you can do some in memory aggregate and transforming before storing it in a storage optimized for time based data like influxdb. From there you can further aggregate, do some calculations etc. based on the complexity you can do this on demand or pre calculate it and store the results for reporting etc. If you want charts consider using grafana (which plays nicely with influx).