0 day streak
8. DatabasesIndexes

Indexes

A database index is a separate, sorted structure that lets the database jump straight to the rows you want instead of reading the whole table, much like the index at the back of a book. Most are B+ trees: wide, shallow trees of sorted keys, so finding one value among millions takes only a handful of steps, and range queries just walk along the sorted leaves. The catch is that every insert, update or delete must also update each index, so indexes speed up reads at the cost of slower writes and extra storage. An index on several columns is sorted by the first, then the second, so it only helps queries that filter on the leading columns.

In this lesson: The B+ tree from section 1 running real queries. A composite-index column-order sim and a write-cost counter.