Algorithm Search⌘K

Theoremcore

Serializability theorem

Also called precedence graph test for conflict serializability.

A schedule is conflict serializable exactly when its conflict graph is acyclic, and a topological order gives an equivalent serial order.

The serializability theorem says that the committed work of a schedule can be reordered into a serial schedule, by moves that keep every conflict, exactly when its serialization graph has no cycle. The serial orders that work are then exactly the topological orders of the graph. Eswaran, Gray, Lorie and Traiger stated it in 1976; Bernstein, Hadzilacos and Goodman gave it its name in their 1987 book, in the form with commits and aborts that is used here. It turns conflict serializability into a graph question that takes polynomial time, while the more permissive view serializability is NP-complete to test.

Statement

Let SS be a schedule over T1,…,TnT_1, \ldots, T_n with read, write, commit and abort actions, and let C(S)C(S) be its committed projection: the actions of the transactions that have committed in SS. Two actions conflict if they belong to different transactions, touch the same item, and at least one is a write.

The serialization graph SG(S)SG(S) has one node for each committed transaction, and an arc Ti→TjT_i \to T_j (i≠ji \ne j) if some action of TiT_i in C(S)C(S) conflicts with a later action of TjT_j in C(S)C(S). (This is the conflict graph of C(S)C(S).)

Theorem (serializability theorem). For every schedule SS:

  1. C(S)C(S) is conflict equivalent to a serial schedule if and only if SG(S)SG(S) is acyclic.
  2. A serial schedule Tk1⋯TkmT_{k_1} \cdots T_{k_m} of the committed transactions is conflict equivalent to C(S)C(S) if and only if Tk1,…,TkmT_{k_1}, \ldots, T_{k_m} is a topological order of SG(S)SG(S).
  3. SG(S)SG(S) can be built, and tested for a cycle, in time O(N2)O(N^2) for a schedule of NN actions.

In plain words

Draw an arrow from one transaction to another whenever the first touched an item before the second, and one of the two touches was a write. Such a pair can never be swapped without changing what some transaction reads or what the database holds at the end, so any serial order that works has to follow every arrow. If the arrows go round in a circle, no order can follow them all. If they do not, sort the transactions so that every arrow points forward, and that order works.

Proof

Write G=SG(S)G = SG(S) and H=C(S)H = C(S). Part 2 implies part 1, because a directed graph has a topological order if and only if it is acyclic (the topological ordering theorem). The conflict serializability page proves part 2 by comparing conflicting pairs directly. Here is a second proof that builds the serial schedule by swaps, in the same way as Kahn's algorithm builds a topological order. It uses the swap lemma from that page: two schedules are conflict equivalent if and only if one can be turned into the other by swapping adjacent actions of different transactions that do not conflict.

Every equivalent serial order is a topological order. Let H′H' be serial in the order π\pi and conflict equivalent to HH. For an arc Ti→TjT_i \to T_j of GG there are conflicting p∈Tip \in T_i and q∈Tjq \in T_j with p<Hqp <_H q, so p<H′qp <_{H'} q, so TiT_i comes before TjT_j in π\pi.

Every topological order gives an equivalent serial schedule. We show by induction on the number mm of committed transactions: if π=Tk1,…,Tkm\pi = T_{k_1}, \ldots, T_{k_m} is a topological order of GG, then HH can be turned into the serial schedule in the order π\pi by allowed swaps. For m≤1m \le 1, HH is already serial.

Let m≥2m \ge 2 and T=Tk1T = T_{k_1}. Since π\pi is a topological order, TT has no incoming arc. Take the actions of TT from first to last, and move each one to the left by adjacent swaps until it stands right after the actions of TT that are already at the front. An action bb that the action aa of TT passes in this way comes before aa in HH and is not an action of TT. If bb conflicted with aa, GG would have the arc from the transaction of bb to TT, which does not exist. So each swap is allowed. The result is H1=T⋅H−H_1 = T \cdot H^-, where H−H^- is HH without the actions of TT, in their old order.

The conflict graph of H−H^- is GG without the node TT, because removing actions does not change the order of the others. So Tk2,…,TkmT_{k_2}, \ldots, T_{k_m} is a topological order of it, and by induction H−H^- can be turned into the serial schedule Tk2⋯TkmT_{k_2} \cdots T_{k_m} by allowed swaps. The same swaps work in H1H_1 behind the block of TT. By the swap lemma the final serial schedule is conflict equivalent to HH.

Part 3. HH has at most NN actions. Compare every pair of positions, which takes O(N2)O(N^2) time and gives at most n2n^2 arcs; then a depth-first search finds a cycle or a topological order in time linear in the size of the graph. □\square

Worked example. S=r1(x) r2(y) w3(x) w1(y) c1 c2 c3S = r_1(x)\ r_2(y)\ w_3(x)\ w_1(y)\ c_1\ c_2\ c_3. The conflicts are r1(x)<Sw3(x)r_1(x) <_S w_3(x), which gives T1→T3T_1 \to T_3, and r2(y)<Sw1(y)r_2(y) <_S w_1(y), which gives T2→T1T_2 \to T_1. The graph is the path T2→T1→T3T_2 \to T_1 \to T_3, with the single topological order T2,T1,T3T_2, T_1, T_3. The proof first moves r2(y)r_2(y) to the front, past r1(x)r_1(x), and then c2c_2 right behind it, past r1(x)r_1(x), w3(x)w_3(x), w1(y)w_1(y) and c1c_1; a commit conflicts with nothing. Then T1T_1 comes next: r1(x)r_1(x) is already in place, and w1(y)w_1(y) and c1c_1 move past w3(x)w_3(x), which touches another item. The result is r2(y) c2 r1(x) w1(y) c1 w3(x) c3r_2(y)\ c_2\ r_1(x)\ w_1(y)\ c_1\ w_3(x)\ c_3, and no other serial order is conflict equivalent to SS.

Consequences

  • Testing is easy. Conflict serializability can be decided in polynomial time. Practical schedulers do not build the graph for every schedule; they use protocols whose output is acyclic by design.
  • The protocol theorems. The two-phase locking theorem is proved by showing that every arc of SG(S)SG(S) points from the earlier to the later lock point. Timestamp ordering makes every arc point from the smaller to the larger timestamp, and commitment ordering from the earlier to the later commit. Each then gets acyclicity for free.
  • Prefix closure. If S′S' is a prefix of SS, then every transaction committed in S′S' is committed in SS, and every conflict of C(S′)C(S') is a conflict of C(S)C(S). So SG(S′)SG(S') is a subgraph of SG(S)SG(S), and conflict serializability of the committed projection is prefix closed.
  • A scheduler must also watch active transactions. In S=r1(x) w2(x) c2 w1(x)S = r_1(x)\ w_2(x)\ c_2\ w_1(x), the graph SG(S)SG(S) has the single node T2T_2. But if T1T_1 commits, the arcs T1→T2T_1 \to T_2 and T2→T1T_2 \to T_1 appear. A serialization graph testing scheduler therefore keeps the graph over all transactions that have not aborted, and refuses or aborts an action that would close a cycle.
  • Aborts remove arcs. r1(x) w2(x) w1(x) c1 a2r_1(x)\ w_2(x)\ w_1(x)\ c_1\ a_2 has a cycle between T1T_1 and T2T_2 among all actions, but T2T_2 aborted, and SG(S)SG(S) is the single node T1T_1. The theorem says nothing about whether that abort was safe; that is the job of the recovery classes.

Tightness

  • Only conflict equivalence. Acyclicity is necessary for conflict serializability, not for serializability in general. r1(x) w2(x) w1(x) w3(x) c1 c2 c3r_1(x)\ w_2(x)\ w_1(x)\ w_3(x)\ c_1\ c_2\ c_3 has the cycle T1→T2→T1T_1 \to T_2 \to T_1, but it is view equivalent to T1T2T3T_1 T_2 T_3: the blind write w3(x)w_3(x) hides the order of the other two writes. For view serializability the graph is replaced by a polygraph with choice arcs, and the test becomes NP-complete.
  • Only the read-write model. The theorem treats every pair of accesses with a write as a conflict. With operations that commute, such as increments, a cycle in the read-write graph can still allow a serial order. Semantic concurrency control uses a smaller conflict relation, and the theorem holds for that relation with the same proof.
  • The bound in part 3 is for the plain method. The number of conflicting pairs can be quadratic in NN, but it is enough to keep, for each item, the last writer and the readers since that write; this gives O(N)O(N) arcs and a test in time linear in NN up to hashing.

History

Eswaran, Gray, Lorie and Traiger (1976) modeled a schedule as a sequence of actions, defined its dependency graph, and proved that a schedule is consistent (equivalent to a serial one) when the graph has no cycle; their paper used this to prove that two-phase transactions are safe. Papadimitriou (1979) compared this notion with broader ones and showed that they are harder to test. Bernstein, Hadzilacos and Goodman (1987) put the theorem in its present form over committed projections and called it the Serializability Theorem.

References

  1. Philip A. Bernstein, Vassos Hadzilacos and Nathan Goodman, Concurrency Control and Recovery in Database Systems, Addison-Wesley, 1987, Chapter 2 (the serialization graph of a history over its committed transactions, and the Serializability Theorem)
  2. K. P. Eswaran, J. N. Gray, R. A. Lorie and I. L. Traiger, The notions of consistency and predicate locks in a database system, Communications of the ACM 19(11), 1976, pages 624 to 633, the dependency graph of a schedule and the theorem that a schedule is equivalent to a serial one when the graph has no cycle
  3. Christos H. Papadimitriou, The serializability of concurrent database updates, Journal of the ACM 26(4), 1979, pages 631 to 653, the comparison of the conflict based test with other notions of serializability
  4. Gerhard Weikum and Gottfried Vossen, Transactional Information Systems, Morgan Kaufmann, 2001, Chapter 3 (conflict serializability and the conflict graph test)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/YM4CC5/text.yaml