The Serializability of Concurrent Database Updates
description
Transcript of The Serializability of Concurrent Database Updates
1
The Serializability of Concurrent
Database UpdatesCHRISTOS H. PAPADIMITRIOU
(Journal of the ACM, Volume 26, 1979)
Presented by: Yuri Meshman
For any comments or updates contact: [email protected]
2
Transactions History (Preliminary definitions) SR is NPC (stencil of proof)
Polygraph SR Subsets in P
DSR The Class Q Two-Phase locking and P3 Topography of SR, S, Q, SSR, DSR, P3 and 2PL
Restrictions on Read Write Set (when SR is in P) Schedulers of Histories Discussion – extension to transactions with multiple steps –
not going through
Contents
3
Transactions History (Preliminary definitions) SR is NPC (stencil of proof)
Polygraph SR Subsets in P
DSR The Class Q Two-Phase locking and P3 Topography of SR, S, Q, SSR, DSR, P3 and 2PL
Restrictions on Read Write Set (when SR is in P) Schedulers of Histories Discussion – extension to transactions with multiple steps –
not going through
Contents
4
Transactions History
Transaction-Bank Example
Read (A, t)t = t - 100Write (A, t)
Read (B, t)t = t + 100Write (B, t)
Read (A, s)s = s - 100Write (A, s)
Read (C, s)s = s + 100Write (C, s)
Lucy Ricky A B C
300 600600
500 500500
300 500500
300 500600
300 + 600 + 600 = 1500
400 500500
Central Bank Registry
5
Transactions History
Transaction-Bank Example
Read (A, t)t = t - 100
Write (A, t) Read (B, t)t = t + 100Write (B, t)
Read (A, s)s = s - 100Write (A, s)
Read (C, s)s = s + 100Write (C, s)
Lucy Ricky A B C
400 600600
500 500500
400 500500400 500500
400 500600
400 + 600 + 600 = 1600
Central Bank Registry
6
Transactions History
Definition
, , ,h n V S
1 2 1 3 2 3, ,h R x R W x y R x W x y W y
1 1 2
positive integer, , , , ,
permutation of - a finite set of variables
- a funcion : 2
n n n
n
Vn
nR W R R W
V
S
1 3 2 1 2, , , ,...S R S R x S R S W S W x y
,i i iT R W
7
Transactions HistoryFrom Databases to
Programs 1 2 1 3 2 3, ,h R x R W x y R x W x y W y𝑡11← 𝑥
start
F
F
Halt
J
𝑡 31←𝑥F
J
J
y←t32
𝑡 32←f 31 (t 31 )
8
Transactions HistoryFrom Databases to
Programs 1 2 1 3 2 3, ,h R x R W x y R x W x y W y𝑡11← 𝑥
start
F
F
Halt
J
𝑡 31←𝑥F
J
J
y←t32
𝑡 32←f 31 (t 31 )
equivalent histories if and only if their program schemata are equivalent.
For:- Any set of domains for the variables - Any set of initial values- Any interpretation for the functions The values of the variables are identical after the execution in both histories.
9
Transactions History
Histories EquivalenceProposition 1. Two histories and are equivalentiff they have the same set of live transactions, and a live reads from in iff reads from in .
1 2 1 3 2 3, ,h R x R W x y R x W x y W y
1 1 1 2 1 3 2 3 2 2, , , ,n n n nh R W x y R x RW x y R x W x y W y R x y W
11
Transactions History
Histories EquivalenceProposition 1. Two histories and are equivalentiff they have the same set of live transactions, and a live reads from in iff reads from in .
Corollary. Equivalence of histories can be decided in time.
12
Transactions History
SerializabilityA history is serial if for all . immediatly precedes .
A history is serializable if there is a serial history such that
Notation:
13
Transactions History SR is NPC (stencil of proof)
Polygraph SR Subsets in P
DSR The Class Q Two-Phase locking and P3 Topography of SR, S, Q, SSR, DSR, P3 and 2PL
Restrictions on Read Write Set (when SR is in P) Schedulers of Histories Discussion – extension to transactions with multiple steps –
not going through
Contents
14
SR is NPC
Polygraph - IntroductionDefinition 1. A polygraph is a digraph together with a set of bipaths, pairs of arcs – not necessarily in A – of the form such that .
Alternatively, a family D of digraphs. A digraph is in D iff , and for bipath , contains one of .
v𝑢𝑤
15
SR is NPC
Polygraph- IntroductionDefinition 1. A polygraph is a digraph together with a set of bipaths, pairs of arcs – not necessarily in A – of the form such that .
Alternatively, a family D of digraphs. A digraph is in D iff , and for bipath , contains one of .
v𝑢𝑤
16
SR is NPC
Polygraph – Acyclicity Definition 2. A polygraph is acyclic if there is an a cyclic digraph is in D .
v𝑢𝑤
17
SR is NPC
Transactions PolygraphGiven .
If reads a variable from : Furthermore if is writing to :
𝑇 1 𝑇 2
𝑇 3𝑇 4
𝑇 5 𝑇 6
𝑇 𝑛+ 1
𝑇 𝑛+ 2
is live transactions of
𝑇 7
𝑊 4[𝑦 , 𝑧 ]𝑊 2 [𝑥 ]𝑅1 [ 𝑥 , 𝑦 ]𝑅3 [ 𝑦 ]𝑊 7 [ 𝑦 ]𝑊 5 [ 𝑧 , 𝑠 ]𝑅6 [ 𝑠 ]𝑊 6 [𝑧 ]…
18
SR is NPC
Transactions PolygraphLemma 1. Two histories are equivalent iff are identical
Lemma 2. is serializable iff is acyclic
𝑇 1 𝑇 2
𝑇 3𝑇 4
𝑇 5 𝑇 6
𝑇 𝑛+ 1
𝑇 𝑛+ 2
𝑇 7
𝑊 4[𝑦 , 𝑧 ]𝑊 2 [𝑥 ]𝑅1 [ 𝑥 , 𝑦 ]𝑅3 [ 𝑦 ]𝑊 7 [ 𝑦 ]𝑊 5 [ 𝑧 , 𝑠 ]𝑅6 [ 𝑠 ]𝑊 6 [𝑧 ]…
19
SR is NPC
The proof stencilTheorem 1. Testing if h is serializable is NP-complete, even if h has no dead transactions.
Preliminary: 3SAT is NPC
Lemma 3. 3SAT is NPC when formulas are non circular (no repeating variables)
Theorem 1 proof: reduction from 3SAT to polygraph acyclicity
20
SR is NPC
Construction of =x or
21
SR is NPC
Construction of =x or
𝑎𝑠
22
Transactions History SR is NPC (stencil of proof)
Polygraph SR Subsets in P
DSR The Class Q Two-Phase locking and P3 Topography of SR, S, Q, SSR, DSR, P3 and 2PL
Restrictions on Read Write Set (when SR is in P) Schedulers of Histories Discussion – extension to transactions with multiple steps –
not going through
Contents
23
SR Subsets in P
DSR-conflict serializability Definition 3. Let , . We write if , for some , and:a) for some orb) , or
𝑅1 [ 𝑥 ]𝑅2 [ 𝑥 ]𝑾 𝟏 [𝒙 ]𝑾 𝟐 [𝒚 ] 𝑹𝟏 [𝒚 ]𝑹𝟐 [𝒙 ]𝑊 2 [ 𝑥 ]𝑊 1 [ 𝑦 ]𝑅2 [𝑥 ]𝑹𝟏 [𝒚 ]𝑾 𝟐 [𝒙 ]𝑊 1 [ 𝑦 ]𝑅2 [ 𝑥 ]𝑊 2 [ 𝑥 ]𝑅1 [ 𝑦 ]𝑊 1 [ 𝑦 ]
Let be the transitive reflexive closure of . Since is symmetric is an equivalence relation
24
SR Subsets in P
DSR-conflict serializability Proposition 2. If then
is a proper subset of
h is D-serializable(DSR) iff there exists a serial history h such that
25
SR Subsets in P
DSR-conflict serializability We can associate with a history h a digraph D(h) as follows: is an arc if:a) and , orb) and orc) and
Theorem 2. A history h is DSR iff D(h) is acyclic.
26
SR Subsets in P
DSR-conflict serializability
Corollary 2. A history is DSR iff we can find real numbers with the following propertiesa) and , then b) and thenc) and
Corollary 1. Checking whether a history is DSR can be done in
27
SR Subsets in P
The class QDefinition 4 . A history h is in Q if there exist non integer, distinct real numbers such that:a) b) and , then c) and
28
SR Subsets in P
The class QTheorem 3. If h is in Q, then h is DSR.
We can associate with a history h a digraph D’(h) a super graph as follows: is an arc if:a) b) and orc) and
h=𝑅1𝑅2𝑅3 [ 𝑥 ]𝑊 1 [ 𝑥 ]𝑊 2 [𝑦 ,𝑧 ]𝑊 3 [𝑦 ]
29
SR Subsets in P
Two Phase locking and P3Definition 5. h is two phase locked ( iff there exist distinct non-integer real numbers (the lockpoints) s.t:a) b) and , then c) and
30
SR Subsets in P
Two Phase locking and P3
The inclusion is proper:
31
SR Subsets in P
Two Phase locking and P3Definition 6. Let G(h) be an undirected graph corresponding to D(h). A cycle - s.t. is an edge - is bad if and
32
SR Subsets in P
Two Phase locking and P3Definition 6.(continued) is a guardian of if is part of a bad cycle in G(h). h obeys the P3 protocol () if when is a guardian of we do not have
33
SR Subsets in P
SSRDefinition 7. is Serializable in the Strict Sense h if there is a serial history such that and , implies .
𝑄⊂𝑆𝑆𝑅
34
SR Subsets in P
Topography
35
Transactions History SR is NPC (stencil of proof)
Polygraph SR Subsets in P
DSR The Class Q Two-Phase locking and P3 Topography of SR, S, Q, SSR, DSR, P3 and 2PL
Restrictions on Read Write Set (when SR is in P) Schedulers of Histories Discussion – extension to transactions with multiple steps –
not going through
Contents
36
Restrictions on Read Write Set (SR is in P)
Theorem 8. If for w for then is serializable iff is DSR.
37
Restrictions on Read Write Set (SR is in P)
38
Transactions History SR is NPC (stencil of proof)
Polygraph SR Subsets in P
DSR The Class Q Two-Phase locking and P3 Topography of SR, S, Q, SSR, DSR, P3 and 2PL
Restrictions on Read Write Set (when SR is in P) Schedulers of Histories Discussion – extension to transactions with multiple steps –
not going through
Contents
39
Schedulers of
Histories 2PL and P3 correspond to simple schedulers.
A trivial scheduler will generate only serial histories.Scheduler task becomes interesting and important when he must transform the arriving schedule to a non equivalent output which is closest to the input.
Definition 8. A schedule, for (histories), is such that
40
Schedulers of
Histories Assumptions: works online (receiving transactions) Optimism – doesn’t change order of transactions
seen so far, if can be extended to a serializable history.
efficient if computable in polynomial time.
Q: Which classes of histories have efficient schedulers. NoEfficient scheduler if the input class is
in P?
41
Schedulers of
Histories Should be computed efficiently by proposed scheduler.
Check for if the output starts with - to check SR efficiently.
NoEfficient scheduler if the input class is in P?
42
Schedulers of
Histories Corollary 1. Unless P=NP, SR has no efficient
scheduler.
Corollary 2. S, 2PL, P3, Q, DSR have efficient schedulers.
43
Thank you