Tinker Databases & indexes

by Kondasamy Jayaraman · drawn with Colorfigures by April Zhu

No index yet.0 pages read · 0 rows read

Chapter 2 of 7

The index

A full scan opened every drawer for one order. The team builds a card index on order number, sorted like a phone book.

This chapter: How does an index find one order in a few page reads?

About this chapter

You will learn

  • An index is a sorted copy of a column
  • A B-tree lookup reads one page per level
  • Why the tree stays shallow

Words you’ll meet

Index
A sorted copy of one or more columns, each entry pointing at its row.
B-tree
The tree most databases use for indexes: a root page, levels of pages under it, sorted leaves.
Leaf
A page at the bottom of a B-tree, holding sorted keys and where each row lives.

Step 1 of 5

An is a sorted copy of one column, each entry pointing at its row. Larkspur’s is a .

Build the order-number index.

The SQL
CREATE INDEX ON orders (id);