The Art of Database Indexing

H
Henrik Larsson
· 1 min read

Indexes are the single most impactful performance optimization in most applications. A missing index can make a query 1000x slower. An unnecessary index wastes disk space and slows writes. Getting indexing right is both art and science.

The science: B-tree indexes work like a phone book. They let the database jump directly to matching rows instead of scanning the entire table. Composite indexes work left-to-right, so the column order matters. A partial index only indexes rows matching a condition, keeping the index small and fast.

The art: knowing which queries need indexes and which do not. Queries that run once a day on a small table do not need optimization. Queries that run thousands of times per second on a large table need careful attention. Monitor your slow query log, not your intuition.

Marginalia

Select text to add a note.