CodeOath
← All posts
SQL65 min total · 16 parts

Understanding SQL Indexes and Query Performance

Contents — Part 13 of 16: The Write-Performance Cost of Indexes
Part 13 of 16 · ~1 min

The Write-Performance Cost of Indexes

Every index speeds up reads that use it, but slows down writes — every INSERT, UPDATE (of an indexed column), and DELETE has to update every index touching the affected columns, not just the underlying table. Each additional index is one more B-tree that has to be kept balanced and sorted on every write.

OperationCost with no indexesCost with N indexes on the affected columns
INSERTWrite one rowWrite the row, plus insert into each of the N index structures
UPDATE (indexed column)Update one rowUpdate the row, plus remove/re-insert in each affected index
DELETERemove one rowRemove the row, plus remove the entry from each index

Indexing every column "just in case" is a common anti-pattern that quietly degrades write throughput without a corresponding read benefit, since most of those indexes never actually get used by any real query — every table's indexes should be a deliberate, reviewed set, not a reflexive default.