Core Concept

Indexing and Query Optimization

Most database outages are slow-query problems, not CPU failures. Indexing is the frontline of database access optimization.


What:

An index is a secondary database access path built on top of primary tables.

Primary purpose:

Accelerating read query speeds by replacing slow full table disk scans with binary tree traversals.

Usually used for:

Filtering rows (WHERE), sorting datasets (ORDER BY), joining tables, and resolving point lookups.

How should I think about this inside system architectures?

🔍 Secondary Access Path

Instead of reading millions of database rows sequentially from disk, follow a tree branch directly to the row pointer in O(log N) steps.

⚖️ Write & Memory Tax

Indexes are not free. Every added index slows database mutations because the engine must update both the raw table and the index tree.

⛓️ Left-to-Right Sort Order

Composite (multi-column) indexes are sorted hierarchically. They only support queries matching from left to right (leftmost prefix rule).