š Why Indexes Are Not Free
The Silent Cost Behind Fast Reads
Indexes donāt make systems faster ā
they shift cost from reads to writes, memory, and latency tails.
š§ The Illusion
CREATE INDEX idx_user_email ON users(email);
Looks harmless.
But this single line changes your entire system behavior.
š§© Cost #1 ā Write Amplification
ā What Actually Happens on INSERT
INSERT INTO users (id, email, name) VALUES (...);
This causes:
Write to base table
Write to index B-Tree
Possible page split
WAL / redo log update
š§ Key Point
1 logical write ā multiple physical writes
š§© Cost #2 ā Slower Writes (Lock Contention)
Indexes increase lock scope.
UPDATE users SET email = 'x' WHERE id = 42;
Locks:
Row lock (table)
Index node lock
Possibly parent nodes
Effect
Higher contention
Worse under high concurrency
š§© Cost #3 ā Memory Pressure (Cache Pollution)
Indexes consume RAM aggressively.
What lives in memory
Hot index pages
Root & intermediate B-tree nodes
š§ Result
Indexes can evict actual data, hurting cache hit rate.
š§© Cost #4 ā Read Amplification Still Exists
Indexes donāt always mean 1 read.
Example:
SELECT * FROM orders WHERE user_id = 42;
Execution:
Read index page
Read table page(s)
Index scan + table lookup = 2 I/O paths
š§© Cost #5 ā Index Maintenance (Deletes & Updates)
Deletes donāt free space immediately.
Problems:
Fragmentation
Page splits
Rebalancing
Vacuum / compaction overhead
Result
Background CPU
Unpredictable latency spikes
š§© Cost #6 ā Indexes Hurt Write-Heavy Systems
Example: Like Counter
UPDATE posts SET likes = likes + 1 WHERE id = 7;
With index on likes:
Every increment updates index order
Constant tree rebalancing ā
Better
No index
Or async aggregation
š§ When Indexes Make Things Worse
| Scenario | Index Impact |
|---|---|
| Write-heavy | ā Bad |
| High churn fields | ā Bad |
| Low-selectivity columns | ā Bad |
| Hot rows | ā Very bad |
| Cold analytical reads | ā Wasted |
ā Example of a Bad Index
CREATE INDEX idx_gender ON users(gender);
Why bad?
Low cardinality
- What is cardinality ? will be explained in upcoming blog.
Poor selectivity
Index scan almost as big as table scan
ā When Indexes Are Worth It
| Scenario | Index |
|---|---|
| High selectivity | ā |
| Read-heavy | ā |
| Stable data | ā |
| Covering index | āāā |
| OLAP workloads | ā |
ā Covering Index (The Only āFree-ishā One)
CREATE INDEX idx_user_email_name
ON users(email, name);
Query:
SELECT name FROM users WHERE email = ?;
ā No table lookup
ā Reduced read amplification
š„ How This Connects to Previous Blogs
Read Amplification ā indexes donāt eliminate it
Write Amplification ā indexes multiply it
Hot Keys ā hot index pages become bottlenecks
P99 latency ā index rebalancing spikes
