Serializability in DBMS
Press Next → or use ← → arrow keys
The Story — Two Chefs, One Kitchen
"Can this interleaved schedule produce the same result as some serial one?" If yes, it's safe — concurrency and correctness. That property is serializability.
Serial · Non-Serial · Serializable
Serial ⊂ Conflict Serializable ⊂ View Serializable ⊂ All Schedules. Every conflict-serializable schedule is serializable — but not every serializable one is conflict-serializable (that wider class is view serializability, which is NP-hard to test).
When Do Two Operations Conflict?
Two operations conflict if — and only if — all three hold at once:
| Pair (same item X, different txns) | Conflict? | Name | Reason |
|---|---|---|---|
| Read(X) … Read(X) | NO | — | Two reads never change a result |
| Read(X) … Write(X) | YES | RW | Swap and the read sees a different value |
| Write(X) … Read(X) | YES | WR | Read depends on whether the write came first |
| Write(X) … Write(X) | YES | WW | Final value depends on which write is last |
Different items → never conflict. Same transaction → never conflict. Read–Read is the only same-item, different-transaction pair that is safe.
Conflict Equivalence by Swapping
Two schedules are conflict equivalent if one becomes the other by swapping only adjacent, non-conflicting operations. A schedule is conflict serializable if it's conflict-equivalent to some serial schedule.
For anything bigger than a toy schedule, we need a faster, mechanical test — the precedence graph.
The Precedence Graph Test
Hunt conflicts item by item, not line by line: list each item's operations in time order and draw edges only between pairs where at least one is a Write.
A Serializable Schedule
| Time | T1 | T2 |
|---|---|---|
| t1 | R1(A) | |
| t2 | W1(A) | |
| t3 | R2(A) | |
| t4 | W2(A) | |
| t5 | R1(B) | |
| t6 | W1(B) |
Item B: only T1 touches it → no conflict.
All three conflicts on A (WR, RW, WW) collapse into the single edge T1 → T2. One arrow can't form a cycle → acyclic → serializable. The interleaving behaves like running T1 fully, then T2 fully.
A Non-Serializable Schedule — The Cycle
| Time | T1 | T2 |
|---|---|---|
| t1 | R1(X) | |
| t2 | R2(X) | |
| t3 | W2(X) | |
| t4 | W1(X) |
R1(X) before W2(X) gives T1 → T2; R2(X) before W1(X) gives T2 → T1. Two opposing arrows = a cycle. T1 must come both before and after T2 — impossible. A real DBMS would abort one transaction (deadlock victim / serialization failure).
Three Transactions — Exam Level
| Time | T1 | T2 | T3 |
|---|---|---|---|
| t1 | R1(X) | ||
| t2 | R3(X) | ||
| t3 | R2(Y) | ||
| t4 | W1(Y) | ||
| t5 | W2(X) | ||
| t6 | W3(Y) |
Edges: T1→T2, T3→T2, T2→T1, T2→T3, T1→T3. The two-node cycle T1 → T2 → T1 settles it (T2 ⇄ T3 exists too). One cycle is enough to reject.
Reading Off the Serial Order
S: R1(x) R3(y) R3(x) R2(y) R2(z) W3(y) W2(z) R1(z) W1(x) W1(z)
x: R3(x) before W1(x) → T3→T1
y: R2(y) before W3(y) → T2→T3
z: W2(z)/R1(z), R2(z)/W1(z), W2(z)/W1(z) → T2→T1
Edges T2→T1, T2→T3, T3→T1 all flow one way. T2 has no incoming edge, then T3, then T1. Equivalent serial schedule: T2 → T3 → T1.
Three Shapes, Three Verdicts
A node with no incoming edges goes first in the serial order. If two such nodes exist, either can lead — that's why some schedules have more than one correct answer.
Counting Schedules
Transactions T1 and T2 have m = 3 and n = 2 operations. How many schedules exist?
Eight non-serial schedules — and only some of those are conflict serializable. Each must be tested with its own precedence graph.
Conflict vs View · Theory vs Practice
Stricter isolation → fewer anomalies but more blocking/aborts. Weaker → faster, but the app must reason about anomalies. Serializable is the only level where you never reason about interleavings at all.
Rapid-Fire Concept Check
| Question | Answer |
|---|---|
| Two reads on same item, different txns — conflict? | No (the only Write-free pair) |
| Test for conflict serializability | Precedence (serialization) graph |
| Graph has a cycle → verdict? | Not conflict serializable |
| Acyclic → how to get serial order? | Topological sort |
| Edge Ti → Tj means | Ti must precede Tj |
| Serial schedules for k transactions | k! |
| Broader class, NP-hard to test | View serializability |
| Protocol guaranteeing conflict-serializable schedules | Two-Phase Locking (2PL) |
Golden Rules of Serializability
Draw the Graph, Find the Cycle
A schedule is safe if it behaves like some serial order. To check: draw one node per transaction, add an edge for every conflict (same item, at least one write, earlier→later), and look for a cycle. No cycle → conflict serializable, and any topological order is your equivalent serial schedule. A cycle → reject.
Conflicts become arrows; arrows that loop mean "impossible order." No loop = safe — next stop: recoverability and the locking protocols (2PL) that enforce all this live.
🔀 End of tutorial · Press ← to review, or click Restart