Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 01 · Database Internals · One Database, to the Bolt · about 23 min to read

Play it as a journeyTutor comes with a plan

Which shortcut to build

B-Tree on Disk
B-Tree on Disk · Open board

The shortcut most indexes are: a sorted tree whose leaves point at rows in the table. This lesson is about the other shortcuts Postgres can build, how to pick the right one for a query, and what every one of them costs on the next write.

Before you start. B-Tree on Disk showed what an index is: a second, sorted copy of one column that points back at the table, so a lookup reads a few pages instead of all of them. MVCC & Vacuum showed that an update does not change a row in place. It writes a new version and leaves the old one for vacuum. The sentence that says what set up the bench this lesson runs on, and The Query Planner showed how Postgres chooses between a scan and an index. Here you choose the index.

Lesson 13 of 26 in Database Internals

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 26 July 2016: twelve indexes, one changed field
  • A table, six questions
  • Query 1: a plain B-tree, and what “plain” means
  • Query 2: a partial index, for the slice you actually ask about
  • Query 3: a covering index, so the table is never visited
  • Query 4: an expression index, for a search on a function
  • Query 5: GIN, for finding things inside a value
  • Query 6: BRIN, a few bytes for a table that is already in order
  • The bill: every index is paid for on every write
  • 1. A plain B-tree
  • 2. A partial index
  • 3. A covering index, and the visibility map
  • 4. An expression index
  • 5. GIN
  • 6. BRIN, and the same column as a B-tree
  • The bill, measured
  • Finding indexes that earn nothing

Terms it explains: sequential scan, partial index, covering index, index-only scan, expression index, GIN, BRIN, HOT update, `Heap Fetches: 0`, visibility map.

Related papers

Review Database Internals