ContentsThe library

What a Transaction Promises

Reading Something That Was Never True, and Three Relatives

Last timeTwo of Them at Once

There are four named ways concurrent transactions interfere. Each has a schedule you can write in six lines and a precise condition that lets it happen.

The vanishing update from the last lesson is one of several named failures.

This lesson writes out the rest, because the levels in the next lesson are

defined entirely in terms of which of these they forbid.

Reading what was never true

The first is the strangest and, fortunately, the rarest. One transaction

changes a row and has not committed. Another reads it. The first then rolls

back.

FIG 1Acting on a number that no committed state ever held
steptimetransaction Atransaction Bcommitted valuewhat happened
11set the price to 550A has written but not committed. The committed value is still 50; the 5 exists only inside A.
22read the price, gets 550B sees A uncommitted write. This is the step that a level forbidding dirty reads prevents.
33charge the customer 550B has now acted in the outside world on the strength of that number. Refunding a card is not something the database can roll back for you.
44roll back50A abandons its change, perhaps because a validation failed. The price 5 is gone and was never committed by anybody.
55commit50B commits successfully. The customer was charged a price that no committed state of the database ever contained, and no error was raised anywhere.
5 steps
What separates this from the other three is that the value B read was never true. In every other anomaly the values involved were all genuinely committed at some point, and the problem is that they were combined from different moments. Here the number simply never existed outside one transaction private workspace. That is why almost every database forbids this by default and why the level permitting it is a curiosity rather than a choice.

The same row, two answers

The second is milder and far more common. A transaction reads a row, carries on

doing other work, and reads the same row again. Between the two reads, somebody

else committed a change to it.

Both values were real. The first was true when it was read and the second was

true when it was read. The transaction nevertheless now holds two different

answers to the same question, and any arithmetic that used the first is

inconsistent with anything using the second.

This matters most in a report. A statement that reads a balance at the top of

the page and the same balance at the bottom, and prints two different numbers,

is not wrong in any individual step and is useless as a statement.

The lesson stops here

4 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 Relativesyou are here
  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 Waitopening only
  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