System design paper · 1995
ANSI SQL isolation levels
Why the SQL standard’s safety levels for overlapping database transactions let bugs through, and what Repeatable Read and Serializable mean in real databases today.
You’ll learn to
- Explain why the three rules in the SQL standard do not make overlapping transactions safe.
- Trace a dirty write, a lost update, read skew and write skew through two-transaction histories with real numbers.
- Explain what Snapshot Isolation prevents and the one bug it still allows.
- Check what Repeatable Read and Serializable mean in Postgres, MySQL and other databases today.
The idea in short
A database runs many transactions at once. A transaction is a group of reads and writes that succeed or fail together, such as taking £40 out of one account and putting it into another. The SQL standard offers four safety levels and defines each one by three bad things it must not allow.
This paper showed that those definitions are vague and incomplete. A database can pass all three tests and still return wrong answers. Bugs the standard never named, such as two transactions overwriting each other’s unfinished work, can get through. And a popular design called Snapshot Isolation, where each transaction works on its own frozen copy of the data, passes all three tests yet is still not safe.
The problem
A database serves many people at once. Each piece of work is a : a group of reads and writes that succeed or fail together, such as taking £40 out of one account and putting it into another. Running transactions strictly one after another would be safe and far too slow. So databases run them at the same time, and the risk is that their steps interleave in a way no one-at-a-time order could produce.
The safe outcome has a name. A set of transactions is if the result is the same as if they had run one after another, in some order. That is the gold standard, but it costs speed, because the database must make transactions wait or cancel them. So SQL lets you pick a weaker setting, an , and trade some safety for speed.
The SQL standard of 1992 defined four levels. It did not describe how they work. It described them by three bad things each level must not allow, which it called phenomena:
- A is reading a value that another transaction has written but not yet finished. If that transaction then cancels its work, you have read something that never existed.
- A (the paper says “fuzzy read”) is reading a row twice and getting two values, because another transaction changed the row in between and finished.
- A is running the same search twice, such as “all active employees”, and getting different rows, because another transaction added or removed a matching row.
Each level was then defined by which of the three it allows. This is the standard’s table, as the paper reproduces it:
| Level | Dirty read | Non-repeatable read | Phantom |
|---|---|---|---|
| Read Uncommitted | Possible | Possible | Possible |
| Read Committed | Not possible | Possible | Possible |
| Repeatable Read | Not possible | Not possible | Possible |
| “Anomaly Serializable” | Not possible | Not possible | Not possible |
“Anomaly Serializable” is the paper’s label for a history that avoids all three. The standard also says, in a separate clause, that its top level must give fully serializable execution: the safe outcome described above. The two are not the same, and the table covers only the first. Because the table is the part people remember, the authors say, it leads to a common misconception: that ruling out these three things is enough to make a database safe.
So the question the paper answers is: do these three rules really define the levels that databases need, and if not, what is missing?