ContentsThe library

What a Transaction Promises

Keep the Old Row and Nobody Has to Wait

Last timeDoing It With Locks

Writers make a new version rather than overwriting, so every reader sees the database as it was when it started and never waits for anybody. One gap survives.

The mechanism in the previous lesson makes transactions wait, and the waiting

is where both the latency and the deadlocks come from. This lesson is the other

mechanism, which asks a different question: what if a reader never needed a

lock at all?

Several versions of one row

The idea is one change to what a write does. Instead of overwriting the row, it

writes a new copy of it and leaves the old one where it is, stamped with which

transaction made it and when.

FIG 1One row, four versions, and who reads which
stepversionbalancewritten bycommitted atwho can see itwhat happened
11500transaction 40100anybody who started after 100The original value, and still the right answer for any transaction that began before the next commit landed.
22460transaction 51140anybody who started after 140A withdrawal. Version 1 is not deleted, only marked as ending at 140, because somebody may still be reading it.
33760transaction 55180anybody who started after 180A deposit. Three versions of one row now exist on disk and all three are correct answers to somebody.
44700transaction 610nobody yetUncommitted. Visible only to transaction 61 itself, and if 61 aborts this version is simply never shown to anybody and is removed later.
4 steps
The row is a short history rather than a value, and the question what is the balance has no answer without saying who is asking. A transaction that started at time 160 reads version 2 and gets 460, while a transaction that started at 190 reads version 3 and gets 760, and both are reading the committed truth as of the moment they began. Note the fourth row: an uncommitted version costs nothing to discard, which is why rollback under this scheme is cheap.

What a snapshot is

The reader's rule is one sentence: read the newest version of this row that was

committed before I started, and pretend nothing newer exists.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Power Can Fail Between Your Two Statements
  2. 02Both of Them Read 10 and Both of Them Wrote 11opening only
  3. 03Reading Something That Was Never True, and Three Relativesopening only
  4. 04Your Database Is Not Using the Level You Think It Isopening only
  5. 05Take Them All Before You Give Any Backopening only
  6. 06Keep the Old Row and Nobody Has to Waityou are here
  7. 07Both Doctors Checked That Someone Else Was on Callopening only
  8. 08Name the Rule First, Then Pick the Weakest Level That Holds Itopening only

Read alongside