Codele / System design
Database indexes
A big book has an index at the back so you never read every page to find a word. A database can have one too. Pick a name and watch both ways of finding it.
- Without an index the database does a full scan: it reads every row to be sure it found every match.
- An index is a small sorted list of one column, with a pointer to each row. The database jumps straight to the match.
- Looking in a sorted list is quick: each peek throws away half of what is left.
- The cost is on writes: every new or changed row must also update the index, and the index takes space.
- Index the columns you search or join by often. Do not index everything.
Loading the playable lesson…