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 07 · From Scratch · Database · with code: Go · about 24 min to read

Play it as a journeyTutor comes with a plan

Database 02: The Index

The Index
The Index · Open board

The address book sitting over last lesson’s file. Follows Database 01: The Append-Only File, which left every read scanning the whole file, and hands off to Pages.

Before you start. This series builds a small database of our own: a program that saves pairs of a key (a name you look something up by) and a value (what’s stored under that name). Ours already saves every change safely, by adding a new line to the end of a file on disk (the disk being the part of the computer that keeps data after the program stops running), so a crash mid-write loses nothing already saved. And it deletes a key by writing a marker over it rather than erasing anything. But asking it “what is the value for this key” has no shortcut yet: it reads the file one byte (one unit of stored data) at a time from the start, checking every line until it finds the answer or runs out of file.

Lesson 47 of 117 in From Scratch

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

  • 1876: a library too big to search
  • Dewey’s card: an address, not a book
  • The index: a map from key to address
  • The hash map: one step to the right slot
  • The index nobody writes down
  • What Dewey’s numbers do that ours can’t
  • What is in one entry
  • The read
  • The write
  • Wall 1, in numbers: rebuild and the memory ceiling
  • Wall 2, in numbers: no order
  • Demonstrating that the scan is gone
  • Crash recovery of the index itself
  • The one thing

Terms it explains: hint file, address, key, start-up, Keys, values, key count, sorted, derived, first.

Review From Scratch