Algorithm Search⌘K

Theoremadvanced

NP-completeness of view serializability

Also called Papadimitriou view serializability theorem.

Testing whether a schedule is view serializable is NP-complete, unlike conflict serializability, which a cycle test decides.

Deciding whether a schedule is view serializable is NP-complete. Papadimitriou proved this in 1979, by showing that view serializability is the same as the acyclicity of a polygraph, a graph with some arcs fixed and some arcs given as choices, and that polygraph acyclicity is NP-complete. The contrast with the serializability theorem is the reason why real schedulers aim at conflict serializability: one cycle test decides it, while for view serializability no polynomial test is known, and none exists unless P = NP.

Statement

A schedule SS in which all transactions commit is view serializable if some serial schedule of the same transactions is view equivalent to it: every read reads from the same write (or from the initial state in both), and every item has the same final write.

Theorem (Papadimitriou 1979). The problem VSR, which asks for a schedule SS whether it is view serializable, is NP-complete. It stays NP-complete for schedules without aborts in which every item is accessed at most four times.

Papadimitriou worked in his own model of transactions and proved the hardness through polygraphs and satisfiability. The proof below follows the same plan, polygraph acyclicity in the middle, but it is a self-contained version in the read-write action model of the schedule page, with its own gadgets.

In plain words

When a write is blind, that is, when the writing transaction never read the item, the order of that write against other writes can be hidden by a later write. A serial order must still put each writer either before or after each reader that reads from someone else, but which side is free. With many such free choices, a schedule can encode a puzzle in which each choice is a bit, and the puzzle is satisfiable exactly when some serial order exists. The proof builds such a puzzle from a 3-SAT formula.

Proof

Membership in NP. A certificate is a serial order of the mm transactions. For the serial schedule σ\sigma, compute for each read the last earlier write of the same item, and for each item its last write. Do the same for SS, with occurrences of actions as identifiers. This takes time polynomial in the length of SS, and σ\sigma is view equivalent to SS exactly when the two results agree.

The ordering problem. An instance of ORD is a finite set NN of nodes and a set of triples (k;j,i)(k; j, i) of distinct nodes. A solution is a linear order << of NN such that for every triple

j<iand(k<j or i<k),j < i \quad\text{and}\quad (k < j \ \text{or}\ i < k),

that is, jj comes before ii and kk is not between them. An arc j→ij \to i is a constraint j<ij < i alone. This is the polygraph acyclicity problem in the form of linear orders: each triple is a fixed arc j→ij \to i and a choice between the arcs k→jk \to j and i→ki \to k.

Step 1: from ORD to VSR. Given an instance with nodes 1,…,n1, \ldots, n, take transactions T1,…,TnT_1, \ldots, T_n and one more transaction TFT_F. For each triple (k;j,i)(k; j, i) use a fresh item gg and append the actions

wk(g) wj(g) ri(g) wF(g),w_k(g)\ w_j(g)\ r_i(g)\ w_F(g),

for each arc j→ij \to i use a fresh item hh and append wj(h) ri(h) wF(h)w_j(h)\ r_i(h)\ w_F(h), and end with the commits c1⋯cn cFc_1 \cdots c_n\, c_F. Each transaction consists of its actions in the order of the schedule SS.

Claim. SS is view serializable if and only if the instance has a solution.

Proof. Look at the item gg of a triple. In SS, the read ri(g)r_i(g) reads from wj(g)w_j(g), and the final write of gg is wF(g)w_F(g). In a serial schedule σ\sigma, the writers of gg are TkT_k, TjT_j and TFT_F, and the read of TiT_i sees the last of them that comes before TiT_i. So σ\sigma agrees with SS on gg exactly when TFT_F is the last of the three writers, and TjT_j is the last writer before TiT_i. The second condition means Tj<σTi<σTFT_j <_\sigma T_i <_\sigma T_F, because TFT_F comes after TjT_j, and that TkT_k is not between TjT_j and TiT_i. The first condition then only adds Tk<σTFT_k <_\sigma T_F. For the item hh of an arc, the same argument gives Tj<σTi<σTFT_j <_\sigma T_i <_\sigma T_F. If σ\sigma is view equivalent to SS, its order on T1,…,TnT_1, \ldots, T_n is therefore a solution. If << is a solution, the serial schedule in the order << followed by TFT_F meets all these conditions, item by item. □\square

Step 2: from 3-SAT to ORD. Let φ\varphi be a 3-SAT formula with variables v1,…,vnv_1, \ldots, v_n and clauses C1,…,CmC_1, \ldots, C_m, each with three literals. Say that a node yy has range (a,b)(a, b) if the instance holds the arcs a→ya \to y and y→by \to b.

The spine. A chain of arcs fixes the order of these nodes:

BEGIN, O1,L1,…,On,Ln, the clause cells, R1,O1′,…,Rn,On′, END.\mathrm{BEGIN},\ O_1, L_1, \ldots, O_n, L_n,\ \text{the clause cells},\ R_1, O'_1, \ldots, R_n, O'_n,\ \mathrm{END}.

The clause cells are, for c=1,…,mc = 1, \ldots, m in turn, the nodes Wc,1W_{c,1} and then Sc,t,Kc,t,Ec,t,Wc,t+1S_{c,t}, K_{c,t}, E_{c,t}, W_{c,t+1} for t=1,2,3t = 1, 2, 3. Call everything before the first cell the left zone and everything after the last cell the right zone. In what follows, cc is fixed and we drop it from the names.

Variable gadget. For each variable vv, a node xvx_v with range (Ov,Ov′)(O_v, O'_v) and the triple (xv;Lv,Rv)(x_v; L_v, R_v). In a solution, xvx_v lies between OvO_v and LvL_v or between RvR_v and Ov′O'_v. Read the first case as vv false and the second as vv true.

Clause gadget. For each clause, a node zz with range (S1,E3)(S_1, E_3) and the triples (z;E1,S2)(z; E_1, S_2) and (z;E2,S3)(z; E_2, S_3). In a solution, zz lies in one of the three gaps (St,Et)(S_t, E_t): it is after S1S_1 and before E3E_3, and it can be neither between E1E_1 and S2S_2 nor between E2E_2 and S3S_3.

Literal gadget. For the literal ℓ\ell of cell tt, on the variable uu, four nodes:

  • pp with range (BEGIN,Et)(\mathrm{BEGIN}, E_t) and p′p' with range (St,END)(S_t, \mathrm{END});
  • q′q' with range (Wt,Kt)(W_t, K_t), qq with range (Kt,Wt+1)(K_t, W_{t+1}), and the arc q′→qq' \to q;
  • the triples (q;p,Et)(q; p, E_t), (q′;St,p′)(q'; S_t, p') and (z;q′,q)(z; q', q);
  • if ℓ=u\ell = u, the triples (p;xu,Ou′)(p; x_u, O'_u) and (p′;xu,Ou′)(p'; x_u, O'_u); if ℓ=¬u\ell = \neg u, the triples (p;Ou,xu)(p; O_u, x_u) and (p′;Ou,xu)(p'; O_u, x_u).

The instance has O(n+m)O(n + m) nodes and constraints, and it is built in polynomial time.

Lemma (a false literal closes its gap). In a solution, if the literal of cell tt is false under the assignment read from the variable gadgets, then zz is not in the gap (St,Et)(S_t, E_t).

Proof. Take ℓ=u\ell = u with uu false, so xu<Lux_u < L_u. The node pp is before EtE_t, so it is not after Ou′O'_u, and the triple (p;xu,Ou′)(p; x_u, O'_u) forces p<xup < x_u: pp is in the left zone. Then p<Kt<qp < K_t < q, so the triple (q;p,Et)(q; p, E_t) forces q>Etq > E_t. The node p′p' is after StS_t, so it is not before xux_u, and its triple forces p′>Ou′p' > O'_u: p′p' is in the right zone. Then q′<Kt<p′q' < K_t < p', so the triple (q′;St,p′)(q'; S_t, p') forces q′<Stq' < S_t. Now q′<Stq' < S_t and q>Etq > E_t, and the triple (z;q′,q)(z; q', q) says that zz is not between q′q' and qq, so zz is not in (St,Et)(S_t, E_t). For ℓ=¬u\ell = \neg u with uu true, xu>Rux_u > R_u, and the triples (p;Ou,xu)(p; O_u, x_u) and (p′;Ou,xu)(p'; O_u, x_u) again push pp before OuO_u into the left zone and p′p' after xux_u into the right zone. The rest is the same. □\square

Soundness. Let the instance have a solution. Read the assignment from the variable gadgets. For each clause, zz lies in some gap (St,Et)(S_t, E_t), so by the lemma the literal of cell tt is true. So φ\varphi is satisfied.

Completeness. Let an assignment satisfy φ\varphi. Keep the spine order and place the other nodes as follows.

  • Put xvx_v right after OvO_v if vv is false, and right after RvR_v if vv is true.
  • In a cell whose literal is false, put pp right after BEGIN, p′p' right before END, q′q' right after WtW_t and qq right after EtE_t.
  • In a cell whose literal is true, use the order St, p′, q′, Kt, q, p, EtS_t,\ p',\ q',\ K_t,\ q,\ p,\ E_t.
  • For each clause, choose a cell t∗t^* with a true literal and put zz right after St∗S_{t^*}, before p′p'.

All arcs hold. The variable triples hold by the placement of xvx_v. The clause triples hold because zz is in a gap. The triple (q;p,Et)(q; p, E_t) holds with q<pq < p in a true cell and with q>Etq > E_t in a false cell; the triple (q′;St,p′)(q'; S_t, p') holds with q′>p′q' > p' in a true cell and with q′<Stq' < S_t in a false cell. The triple (z;q′,q)(z; q', q) holds in the cell t∗t^* because z<q′z < q', and in every other cell of the clause because there q′q' and qq lie between WtW_t and Wt+1W_{t+1}, while zz lies outside that interval. For the literal triples: in a false cell, pp is before all of OuO_u, xux_u and Ou′O'_u, and p′p' is after all of them. In a true cell with ℓ=u\ell = u, xux_u is in the right zone, so p<xup < x_u and p′<xup' < x_u. In a true cell with ℓ=¬u\ell = \neg u, xux_u is in the left zone, so p>xup > x_u and p′>xup' > x_u. So every constraint holds. □\square

Conclusion. Steps 1 and 2 give a polynomial-time reduction from 3-SAT to VSR. In the schedule of Step 1, every item has at most four actions and no transaction aborts. With membership in NP, VSR is NP-complete. ■\blacksquare

Consequences

  • Schedulers use conflict serializability. It is a subclass of VSR that the serializability theorem decides with one cycle test, and that is closed under prefixes. View serializability is neither easy to test nor closed under prefixes, so an online scheduler could not use it even with unlimited time per step.
  • Exact view tests are exponential in the worst case. A test can try all m!m! serial orders, or search over the choices of the polygraph. Both are fine for a handful of transactions and hopeless in general.
  • Rules that exploit blind writes are local. The Thomas write rule accepts some schedules that are view serializable but not conflict serializable. It does so by a fixed rule on timestamps, not by solving the hard problem.
  • The same method gives other hardness results. Polygraph acyclicity is the core of several later proofs, for example for multiversion serializability, where the version function adds more freedom of the same kind.

Tightness

  • Blind writes are needed. If every transaction reads each item before it writes it, view serializability coincides with conflict serializability, and the test is polynomial. The hard instances above rely on writes such as wk(g)w_k(g) that no read precedes.
  • A fixed number of transactions is easy. For mm transactions the brute force test takes O(m!⋅N)O(m! \cdot N) time on a schedule of NN actions, which is polynomial for each fixed mm. The hardness needs a growing number of transactions.
  • NP-hardness, not more. The problem is in NP, so it is not PSPACE-hard unless NP = PSPACE.
  • The model matters. The statement is about the read-write action model with view equivalence. Papadimitriou proved his result in a model of his own, and a change of model, for example a different notion of equivalence, needs its own proof.

History

Papadimitriou (1979) studied the serializability of schedules of read and write steps, introduced the polygraph of a schedule, and proved that testing serializability is NP-complete, by a reduction from satisfiability through polygraph acyclicity. The same paper compared this class with the class that the precedence graph decides, which is a polynomial subclass. Garey and Johnson (1979) included serializability of database histories in their list of NP-complete problems. Later textbooks, such as Weikum and Vossen (2001), separate final-state, view and conflict serializability and present the hardness of the view test as the reason for the practical focus on conflict serializability.

References

  1. Christos H. Papadimitriou, The serializability of concurrent database updates, Journal of the ACM 26(4), 1979, pages 631 to 653, the polygraph of a schedule, the NP-completeness of polygraph acyclicity, and the NP-completeness of testing serializability
  2. Gerhard Weikum and Gottfried Vossen, Transactional Information Systems, Morgan Kaufmann, 2001, Chapter 3 (view serializability, the polygraph characterization and the complexity of the test)
  3. Michael R. Garey and David S. Johnson, Computers and Intractability, W. H. Freeman, 1979, the appendix list of NP-complete problems, the entry on serializability of database histories

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/RBVB1W/text.yaml