CS PAPERS DEEP-READ · PAPER 62

A Critique of ANSI SQL Isolation Levels

Berenson, Bernstein, Gray, Melton, O'Neil, O'Neil · SIGMOD 1995

中文 →

What did this paper do?

Every database has a dial called the isolation level. It decides how much several simultaneous pieces of work are allowed to disturb each other. Turn it tight and you are safe but slow; turn it loose and you are fast but your books may come out wrong. The 1992 international SQL standard put four notches on that dial and described, in a few sentences of plain English, what each notch protects you from. In 1995 six heavyweights of the database world — including the editor of the SQL standard himself, and Jim Gray, one of the founders of transaction processing — wrote this paper and took those sentences apart. Their finding: the plain English can be read two different ways, and the list of hazards it names leaves out several accidents that happen every day.

Start with something odd

The standard's description of a "dirty read" runs roughly like this: A changes a row but has not finalized it, B reads that row anyway, and then A changes its mind and cancels — so B has read a number that never really existed. Sounds reasonable.

But the paper points out: taken literally, it is only an accident if A cancels at the end. What if A never changes its mind and finishes normally? B can still read a half-finished ledger — money has left one account and not yet arrived in the other, and B, looking at that moment, sees the total mysteriously short. By the literal reading, that does not count as a violation. One sentence, two readings: the strict one forbids all of these situations, the loose one forbids only a corner of them. This is not hair-splitting — what sits between the two readings is whether your money gets counted wrong.

What else the manual left out

The paper then lists hazards the standard never mentions but that are common in practice. First: two people change the same spot at once, and the later write quietly erases the earlier one. Even the loosest notch has to prevent that one, or else "cancel" itself stops working — you no longer know which old value to restore. Second: two people each read a balance, each add money, each write it back, and one of the two updates simply evaporates.

The nastiest is the third: two people each look at the same books, each make a decision that is perfectly legal on its own, and together they break the rule. A couple holds two cards on two accounts, and the bank's rule is that the two accounts together must not go into the red. Both check at the same time, both see "a hundred left between us", so one takes eighty from this account and the other takes eighty from that one. Neither withdrawal crosses the line by itself; together they are sixty in the red. Nobody read dirty data, and the books are still wrong.

Snapshot isolation: everyone reads their own photograph

The paper also tidied up and formally named a technique that databases were already using: snapshot isolation. The intuition: the moment you walk in, someone photographs the entire library for you; from then on, no matter how other people shuffle the books, you only ever look at your own photograph. So reading never has to queue behind anyone, and you never catch anyone mid-shuffle. Your own changes are kept under your name where nobody else can see them, and only come out when you go to the counter to check out. There the clerk runs one test: if someone touched the same book after you walked in and checked out before you did, they win and your whole basket is voided — go do it again.

It is fast and clean, and it blocks nearly every accident above — except the couple at the cash machine: those two touched different books, so the clerk's test finds no collision and waves both through, even though the photographs they each acted on had gone stale.

What it led to

This paper turned "isolation level" from a paragraph that is easy to misread into a checklist you can go through line by line: for each notch, exactly which accidents are prevented and which are let through. The industry got a shared vocabulary out of it — dirty read, non-repeatable read, phantom, lost update, write skew, snapshot isolation all trace back here.

Remember one thing

The standard defined isolation levels in a few sentences of plain English that were both ambiguous (one sentence, two readings, with real money between them) and incomplete (real accidents missing). This paper wrote out, hazard by hazard, what each notch actually prevents, filled in the gaps, and named the "read your own snapshot, first committer wins" technique snapshot isolation — while noting that useful as it is, it cannot stop the case where two decisions are each legal and jointly wrong.

Want the precise notation, the four missing anomalies, and why isolation levels do not line up in a single row? → Switch to the deep read