Which Queries Use This Index? Check Before You Drop

Which Queries Use This Index? Check Before You Drop

You have an index that looks dead. It is large, every insert pays for it, and you want it gone. Then somebody asks what will run slower afterward, and the room goes quiet. A read counter cannot tell you which queries use this index. It only tells you how many times something did.

How do I find which queries use this index in SQL Server? To find which queries use this index, search execution plans rather than usage counters. Look through the plan cache, and Query Store if it is on, for the schema, table and index name together. Then note whether each matching statement seeks, scans, looks up or writes, how often it runs, and what CPU it costs.

The Index Usage by Query report in Database Health Monitor answers with statements instead of totals. Pick an index, and it searches execution plans for every statement that touches it.

Why usage counters mislead you

Most people open sys.dm_db_index_usage_stats first. Zero seeks, zero scans, thousands of updates: drop it. The trouble is what that zero means. The counters start empty after a restart, and an index rebuild can reset them too. A quiet number may only describe a short window.

A busy number is no better. It does not say whether the reads came from a checkout procedure that runs all day or from one curious person in a query window last Tuesday. Same counter. Very different risk.

Plans are the better witness, because each one records the indexes it touches. That gives you a statement, the procedure it lives in, and a cost you can argue about.

Index Usage by Query is one of the reports in Database Health Monitor. It runs against your own servers, and it takes about a minute to have this same screen open on one of them.

Which queries use this index, and how

You will find the report under a database at Real Time, Indexing, Index Usage by Query. Type part of an index name, then choose Plan cache, Query Store or Both. The grid lists the top 50, 100 or 300 statements by CPU per day.

The How used column is where the decision gets made:

  • Seek or Scan: the statement reads the index directly.
  • Lookup from: this index led to a key lookup. Lookup into: your clustered index was the target of one.
  • Update, Insert or Delete: the statement only has to maintain it. Drop the index and that write cost goes away.

Next to that sit Lives in, Operator cost, Runs per day and CPU seconds per day. A scan buried in a reporting procedure that barely runs is a conversation. A seek with heavy daily CPU behind it is a stop sign. And if a scan surprises you, Non Sargable Predicate: Why the Plan Never Warns You is worth a read.

What to do before you drop or create

Check the footer, which says how many plans were searched out of how many. The cache search reads the busiest 20,000 statements first, and plans over 4 MB are skipped and counted. Matching uses schema, table and index together, so a namesake on another table will not fool you.

Sometimes the counters show reads but no plan mentions the index. Those plans may have been evicted, or the readers were ad hoc, so switch to Query Store. It covers the last 24 hours, including plans that have left the cache. A month-end job can still hide from both, so know your calendar.

When you are ready, Copy DROP INDEX gives you a script that notes how many statements read the index in the plans searched. Nothing is run for you.

The search also works in reverse. Switch to Missing index request and you get the statements that asked for that index, something the missing index DMVs never tell you. Match shows Exact or Subset, Plan impact shows the optimizer's estimate, and CPU saved per day multiplies daily CPU by that impact. Now you know who benefits before you build it.

You need SQL Server 2008 or newer and VIEW SERVER STATE. The Query Store source needs 2016 or newer with Query Store turned on. The full column reference is on the Index Usage by Query help page.

What to check on your own server

  • Note when the instance last restarted and the index was last rebuilt, since either can leave usage counters misleadingly low
  • Search the plan cache and Query Store for the index, matching on schema, table and index name together
  • Sort what you find into reads and writes, then weigh each reading statement by runs and CPU seconds per day
  • Script the CREATE INDEX statement and keep it somewhere safe before you drop anything

Try Database Health Monitor Today

Stop guessing who will run slower after an index drop, and read the actual statements that seek, scan, look up or update it. Database Health Monitor shows it on every instance you connect, in the time it takes to open the report.

Download Database Health Monitor and run the Index Usage by Query report against your own server. There is nothing to configure first, and you will know inside a few minutes whether it tells you something you did not already know.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

To prove you are not a robot: *