Try
↑ ↓ move↵ openesc close

Interview prep / Indexes and filters

Junior · Indexes and filters · System design interview question

What does adding an index cost, and what does it buy?

Sketch your own answer first, then compare it with the one below.

A strong answer

An index lets a query find rows by a column without scanning the table. A lookup reads a few pages instead of all of them.

The cost lands on writes. Each insert, delete or update of an indexed column must also change the index, which is another tree with its own page writes and its own log records. The index also takes disk space and memory in the cache.

So each index is a bet that the reads it speeds up are worth the writes it slows. A good answer says to index for the queries you actually run and to drop indexes that nothing uses.

Sources

Learn it by running it

The indexes and bloom filters lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms