Skip to interview prep
Apexed

24. How do database indexes work and what do they cost?

MediumDatabases

Technical
Show model answer

An index (usually a B-tree) keeps a sorted structure of column values pointing to rows, turning full table scans into O(log n) lookups and speeding up range queries and sorts.

Costs: extra storage and slower writes, because every insert or update must maintain each index. Index columns used in frequent filters and joins, check query plans with EXPLAIN, and consider column order in composite indexes.

How do database indexes work and what do they cost — Software engineering interview question — Apexed