Covers the per-index write, log, memory and blocking cost, building an index set from real query patterns, finding unused indexes with sys.dm_db_index_usage_stats and missing indexes with the missing-index DMVs and Query Store, their caveats (resets, no column-order or write-cost awareness), safe removal by disabling first, and Azure SQL automatic tuning.
Every non-clustered index is another B-tree that each insert and delete (and updates to its columns) must modify, log and keep in memory, so a dozen indexes can multiply write cost several times. I design the set from the top queries by total cost in Query Store, then prune.
sys.dm_db_index_usage_stats, comparing seeks/scans/lookups with user_updates. Caveat: counters reset on restart or failover, so collect over a full business cycle.Trade-off: every index is a read optimisation paid for by every write.
"I start from the fact that every non-clustered index is a separate B-tree that has to be maintained on the write path. An insert into a table with twelve indexes is thirteen B-tree inserts, each logged, each needing pages in the buffer pool, and each a place for latch contention and deadlocks. On a write-heavy table that shows up as insert latency, log throughput limits in Azure SQL, longer backups and slower availability group redo. So the question is never 'would this index help a query?' It's 'is the read benefit worth the cost on every write?'
My process: pull the top queries for the table from Query Store by total CPU and duration, write down each query's equality, range and sort columns, and design the smallest set of composite indexes whose prefixes cover them, with INCLUDE only for the hot ones. Then prune with sys.dm_db_index_usage_stats: indexes with zero seeks, scans and lookups but millions of updates are candidates. The caveat is that those counters reset when the instance restarts, when the database goes offline or an Azure SQL failover happens, so I collect snapshots over a full business cycle including month-end, otherwise the month-end report's index looks unused. I never drop unique indexes, because they enforce rules, or indexes on foreign key columns, because deletes on the parent rely on them.
The missing-index DMVs are useful as hints, not as instructions: they suggest an index per query, ignore what already exists, ignore write cost, list key columns as equality then inequality without thinking about order, and never suggest filtered or columnstore indexes. The mistake I see is scripting every suggestion. For example, at [company] we [consolidated fourteen indexes on an events table into six; insert p95 dropped from [12] to [4] ms and log generation by [45]% with no read regressions in Query Store]. And I remove indexes by disabling them first, so rolling back is a rebuild rather than a guess at the old definition."
| Cost | Where you see it |
|---|---|
| Extra B-tree modification per insert/delete (and per update of its columns) | Insert/update duration, sys.dm_db_index_operational_stats |
| Log records | Log throughput, Azure SQL log rate cap, AG redo and backup size |
| Buffer pool pages | Page life expectancy, memory pressure |
| Locks and latches on more structures | Blocking, deadlocks between index access orders |
| Maintenance and storage | Rebuild/statistics time, backup size |
| Optimiser choice | More plans to consider; plan changes after adding or dropping |
| DMV | Tells you | Caveat |
|---|---|---|
sys.dm_db_index_usage_stats |
Seeks, scans, lookups, updates since last reset | Reset on restart, failover, offline/detach; a scan counts once regardless of size |
sys.dm_db_index_operational_stats |
Leaf inserts, splits, lock and latch waits | Resets when metadata leaves the cache |
sys.dm_db_missing_index_* |
Suggested columns and estimated impact | Per query, overlapping, no write cost, no filtered/columnstore, max 600 groups, reset on restart |
sys.dm_db_missing_index_group_stats_query (2019+) |
Which query produced a suggestion | Same reset caveat |
| Query Store | Persistent query cost history | Must be enabled (on by default in Azure SQL and SQL Server 2022 new databases) |
A telemetry table took 4,000 inserts a second with 14 non-clustered indexes. Four had no reads over 35 days of snapshots, three were left-prefix duplicates of others, and one was a missing-index suggestion covering a report that ran once a week. Dropping eight (after a two-week disable period) cut insert p95 from 12 ms to 4 ms, log generation by 45% and the table's size by 38%.
Checks whether the candidate manages indexes as a cost-benefit portfolio with evidence, and knows the traps in the DMVs everyone quotes.
Green flags
Red flags
INSERT INTO dbo.Events (...)
-> clustered index insert (log record)
-> IX_Events_DeviceId insert (log record)
-> IX_Events_Type_CreatedAt insert (log record)
-> ... x N non-clustered indexes
-> commit: flush log to disk (write-ahead logging)
Updates touch only indexes containing a modified column (key or INCLUDE), unless the update changes the clustered key, which updates every index. Deletes touch every index. Each modification needs the page in memory, a latch, possibly a page split, and a lock on the key, so more indexes also means more ways for two transactions to take locks in different orders and deadlock.
user_seeks, user_scans, user_lookups count operations, not rows. user_updates counts write operations. Because the DMV resets, persist snapshots (e.g. daily into a table) and sum across them. Historically, some SQL Server 2012-2016 builds also reset an index's row on rebuild; current versions do not, but treat old numbers with care. On availability groups, readable secondaries have their own counters: an index used only by reports on the secondary looks unused on the primary.
The optimiser records a suggestion when it thinks an index would have helped a plan. Equality columns, inequality columns and included columns are listed by column id, not by best order. Two similar queries produce two overlapping suggestions. avg_user_impact is the optimiser's own estimated cost reduction, not measured time. Use them to find candidate patterns, then design one consolidated index.
ALTER INDEX ... DISABLE (keeps metadata, frees the data; for non-clustered indexes only, because disabling a clustered index makes the table unreadable).WITH (INDEX(name)) fails with error 308 when the index does not exist and error 315 when it is disabled, so a hinted query breaks outright instead of just slowing down.ALTER INDEX ... REBUILD.Azure SQL Database can recommend CREATE INDEX and DROP INDEX and, if you enable those options, apply them automatically, validate the effect and roll back regressions. They are off by default for new databases, while FORCE_LAST_GOOD_PLAN is on. Teams that manage indexes through EF Core migrations usually keep automatic index changes off to avoid drift between the model and the database, and review the recommendations instead.
sys.dm_db_log_stats before and after in a test database).sys.dm_db_index_usage_stats hourly into a table for a week on a test workload.WITH (INDEX( and FORCESEEK before removing any index.Measure read value against write cost per index, and persist usage across restarts.
-- Reads vs writes per index (since the last reset: check sqlserver_start_time first)
SELECT sqlserver_start_time FROM sys.dm_os_sys_info;
SELECT i.name AS index_name, i.is_unique, i.is_primary_key,
ISNULL(us.user_seeks, 0) + ISNULL(us.user_scans, 0) + ISNULL(us.user_lookups, 0) AS reads,
ISNULL(us.user_updates, 0) AS writes,
ps.used_page_count * 8 / 1024 AS size_mb
FROM sys.indexes AS i
LEFT JOIN sys.dm_db_index_usage_stats AS us
ON us.database_id = DB_ID() AND us.object_id = i.object_id AND us.index_id = i.index_id
JOIN sys.dm_db_partition_stats AS ps ON ps.object_id = i.object_id AND ps.index_id = i.index_id
WHERE i.object_id = OBJECT_ID(N'dbo.Events') AND i.index_id > 1
ORDER BY reads, writes DESC;
-- Persist daily so a restart or failover does not erase the evidence
INSERT INTO dba.IndexUsageSnapshot (captured_at, object_id, index_id, user_seeks, user_scans, user_lookups, user_updates)
SELECT SYSUTCDATETIME(), object_id, index_id, user_seeks, user_scans, user_lookups, user_updates
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID();
-- Missing index suggestions with the query that produced them (SQL Server 2019+ / Azure SQL)
SELECT TOP (20) d.statement AS table_name, d.equality_columns, d.inequality_columns, d.included_columns,
gs.user_seeks, gs.avg_user_impact, SUBSTRING(st.text, 1, 200) AS query_start
FROM sys.dm_db_missing_index_details AS d
JOIN sys.dm_db_missing_index_groups AS g ON g.index_handle = d.index_handle
JOIN sys.dm_db_missing_index_group_stats AS gs ON gs.group_handle = g.index_group_handle
JOIN sys.dm_db_missing_index_group_stats_query AS q ON q.group_handle = g.index_group_handle
CROSS APPLY sys.dm_exec_sql_text(q.last_sql_handle) AS st
WHERE d.database_id = DB_ID()
ORDER BY gs.user_seeks * gs.avg_user_impact DESC;
-- Remove safely: disable first (definition kept), drop after a business cycle
ALTER INDEX IX_Events_Type ON dbo.Events DISABLE;
-- Roll back if needed:
-- ALTER INDEX IX_Events_Type ON dbo.Events REBUILD WITH (ONLINE = ON);
If indexes are owned by EF Core migrations, the model must change too, or the next migration will recreate the dropped index.
namespace Telemetry.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
public sealed class DeviceEvent
{
public long EventId { get; set; }
public int DeviceId { get; set; }
public short EventType { get; set; }
public DateTime CreatedAt { get; set; }
}
public sealed class DeviceEventConfiguration : IEntityTypeConfiguration<DeviceEvent>
{
public void Configure(EntityTypeBuilder<DeviceEvent> b)
{
b.HasKey(e => e.EventId);
// One consolidated index serves: by device, by device + time range, latest per device.
b.HasIndex(e => new { e.DeviceId, e.CreatedAt })
.HasDatabaseName("IX_Events_Device_CreatedAt");
// Removed after 35 days with zero reads: (DeviceId), (EventType), (CreatedAt, DeviceId).
// Keep this list in the configuration so nobody re-adds them from a missing-index hint.
}
}
WITH (INDEX( before disabling.On write-heavy tables I aim for the fewest indexes that keep the top queries' plans healthy, and I make that a documented, reviewed decision, because indexes accumulate one well-meant hotfix at a time and nobody ever removes them. Ownership matters: if migrations own the schema, index changes go through the model and code review like any other change, and Azure SQL's automatic index creation stays off to avoid drift.
Concurrency is where index sprawl hurts most. Under many parallel writers, each extra index is another structure whose pages need latches and whose keys need locks; two transactions that touch the same rows through different indexes can take those locks in different orders and deadlock, and hot pages at the end of ever-increasing index keys create PAGELATCH_EX contention. When I see deadlock graphs on a write-heavy table, the number and shape of its indexes is one of the first things I check.
To keep the decision visible I record it: a short ADR or a table-level note listing each index, the queries it serves (Query Store query ids), and the indexes deliberately removed and why. New index requests go through a pull request with Query Store evidence and an estimate of the write impact, reviewed by whoever owns the table.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Consolidated composite indexes from Query Store | Ongoing tuning of a busy table | Analysis time | Workload unknown or too new |
| Missing-index DMV suggestions | Finding candidate patterns | Overlap, write cost ignored | Applied blindly |
| Azure SQL automatic index tuning | Small teams without DBA time, no migration ownership | Drift from the model, less control | Schema owned by EF Core migrations |
| Separate reporting copy or columnstore | Heavy reports on a write-heavy table | Another structure or pipeline | A couple of point queries |
Note that availability group secondaries have the same indexes as the primary, so moving reports to a readable secondary does not remove their write cost; a separate reporting copy (or a columnstore) does.
A composite index is a B+ tree sorted by the first column, then by the second within each first value, like a phone book sorted by surname then first name.
(CustomerId, OrderDate, Status) supports CustomerId = @c, CustomerId = @c AND OrderDate >= @d, but not OrderDate >= @d alone (that scans; SQL Server has no skip-scan).Trade-off: one well-ordered index can serve several queries; the wrong order serves none.
When you delete a parent row, SQL Server must check every child table that references it. If the child's foreign key column has no index, each check is a table scan, and the delete's locks are held for the whole long statement. A large delete also escalates to a table lock after about 5,000 locks, blocking everyone.
I'd confirm it from the actual plan (a scan of the child under the FK check, huge logical reads) and the blocking chain (sys.dm_exec_requests, sp_WhoIsActive). The fix: index the FK columns, delete in small batches with short transactions, and avoid wide cascades. Separately, constraints created WITH NOCHECK are untrusted, so the optimiser cannot use them; re-validate with WITH CHECK CHECK CONSTRAINT once the data is clean.
A key lookup happens when a non-clustered index finds the rows but lacks some columns the query needs, so SQL Server goes back to the clustered index for each row (a RID lookup on a heap). Each one is 3–4 random logical reads.
A covering index holds every column the query references, so no lookup is needed.
WHERE, JOIN and ORDER BY.Lookups hurt when they run for thousands of rows; past the tipping point the optimiser scans instead. Trade-off: covering speeds a query but widens the index and every write.
How to tell it (STAR)
**S:** At [company] our telemetry ingestion was slowing every evening and Azure SQL was throttling log writes. **T:** I had to cut write cost without breaking any reads. **A:** Wait stats pointed at the log rate cap, so I looked at the [14] indexes on the events table, persisted usage stats across a full month, found eight that were unused, duplicated or served one weekly report, disabled them in two waves while watching Query Store, then dropped them through a migration and moved the report to a columnstore copy. **R:** Insert p95 went from [12] ms to [4] ms, log generation dropped about [45]%, and we scaled back down to the original tier.
Last updated 23 Nov 2026.