Back to blog
Learning·5 min read

Database indexes, explained with a real example

xcodelab team·

Without an index, a database looks through every row to find matches — fine for a few hundred rows, painfully slow for millions.

An index is a separate, sorted structure that lets the database jump straight to the matching rows, similar to using the index at the back of a book instead of reading every page.

Indexes aren't free: they speed up reads but add overhead to writes, since every insert or update has to keep the index up to date too.

A simple starting rule: add an index on any column you frequently filter or join on, and avoid indexing columns you rarely query — especially on tables with heavy write traffic.

#databases#fundamentals