Download presentation
Presentation is loading. Please wait.
Published byLydia Strickland Modified over 9 years ago
1
C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann
2
O UTLINE Goal and Overview Examine Three Approaches to CC on RD: 1. Predicate-Oriented Concurrency Control 2. Relational Update Transactions Syntax and Semantics Histories and Final State Serializability Conflict Serializability Extended Conflict Serializability 3. Exploiting Transaction Program Knowledge Transaction Chopping Applicability of Chopping Summary Questions & Answers 2 Concurrency Control on Relational Databases
3
G OAL AND O VERVIEW 3 Concurrency Control on Relational Databases
4
G OAL AND O VERVIEW Semantic approach to Concurrency Control Possible to exploit semantic knowledge at higher abstraction level 4 Concurrency Control on Relational Databases
5
G OAL AND O VERVIEW Three Approaches to CC on RD: Predicate-Oriented Concurrency Control Relational Update Transactions Exploiting Transaction Program Knowledge 5 Concurrency Control on Relational Databases
6
T HREE A PPROACHES TO CC ON RD: 1. Predicate-Oriented Concurrency Control 6 Concurrency Control on Relational Databases
7
1. P REDICATE -O RIENTED CC ON RD Relational Database 7 Concurrency Control on Relational Databases
8
1. P REDICATE -O RIENTED CC ON RD Lock entire Relation 8 Concurrency Control on Relational Databases
9
1. P REDICATE -O RIENTED CC ON RD Lock individual Tuples 9 Concurrency Control on Relational Databases
10
1. P REDICATE -O RIENTED CC ON RD Concurrency Control on Relational Databases 10 Phantom Problem: Transaction 1: Transaction 2: DELETE FROM Emp WHERE Department = ‘Service’ AND Position = ‘Manager’ DELETE FROM Emp WHERE Department = ‘Service’ AND Position = ‘Manager’ INSERT INTO Emp VALUES (‘Smith’, ‘Service’, ‘Manager’, 40000) INSERT INTO Emp VALUES (‘Smith’, ‘Service’, ‘Manager’, 40000) SELECT Name, Position, Salary FROM Emp WHERE Department = ‘Service’ SELECT Name, Position, Salary FROM Emp WHERE Department = ‘Service’ UPDATE Emp SET Department = ‘Sales’ WHERE Department = ‘Service’ AND Position <> ‘Manager’ UPDATE Emp SET Department = ‘Sales’ WHERE Department = ‘Service’ AND Position <> ‘Manager’ INSERT INTO Emp VALUES (‘Sone’, ‘Serivce’, ‘Clerk’, 13000) INSERT INTO Emp VALUES (‘Sone’, ‘Serivce’, ‘Clerk’, 13000)
11
1. P REDICATE -O RIENTED CC ON RD Predicate Locking 11 Concurrency Control on Relational Databases
12
1. P REDICATE -O RIENTED CC ON RD Transaction 1: C a : Department = ‘Service‘ Position = ‘Manager‘ C b : Name = ‘Smith‘ Department = ‘Service‘ Position = ‘Manager‘ Salary = ‘40000‘ C c1 : Department = ‘Service‘ Position ‘Manager‘ C c2 : Department = ‘Sales‘ Position ‘Manager‘ C d : Name = ‘Stone‘ Department = ‘Service‘ Position = ‘Clerk‘ Salary = ‘13000‘ 12 Concurrency Control on Relational Databases DELETE FROM Emp WHERE Department = ‘Service’ AND Position = ‘Manager’ DELETE FROM Emp WHERE Department = ‘Service’ AND Position = ‘Manager’ INSERT INTO Emp VALUES (‘Smith’, ‘Service’, ‘Manager’, 40000) INSERT INTO Emp VALUES (‘Smith’, ‘Service’, ‘Manager’, 40000) UPDATE Emp SET Department = ‘Sales’ WHERE Department = ‘Service’ AND Position <> ‘Manager’ UPDATE Emp SET Department = ‘Sales’ WHERE Department = ‘Service’ AND Position <> ‘Manager’ INSERT INTO Emp VALUES (‘Sone’, ‘Serivce’, ‘Clerk’, 13000) INSERT INTO Emp VALUES (‘Sone’, ‘Serivce’, ‘Clerk’, 13000)
13
1. P REDICATE -O RIENTED CC ON RD Transaction 2: C q : Department = ‘Service‘ Transaction 3: C p : Department = ‘Sales‘ Example: H( C a ) H( C q ) ∅ H( C b ) H( C q ) ∅ H( C c1 ) H( C q ) ∅ H(C c2 ) H(C q ) = ∅ H(C d ) H(C q ) ∅ 13 Concurrency Control on Relational Databases SELECT Name, Position, Salary FROM Emp WHERE Department = ‘Service’ SELECT Name, Position, Salary FROM Emp WHERE Department = ‘Service’ SELECT Name, Position, Salary FROM Emp WHERE Department = ‘Sales’ SELECT Name, Position, Salary FROM Emp WHERE Department = ‘Sales’ H( C a ) H( C p ) = ∅ H( C b ) H( C p ) = ∅ H( C c1 ) H( C p ) = ∅ H( C c2 ) H( C p ) ∅ H(C d ) H(C p ) = ∅
14
1. P REDICATE -O RIENTED CC ON RD Scheduler 14 Concurrency Control on Relational Databases
15
T HREE A PPROACHES TO CC ON RD: 2. Relational Update Transactions 15 Concurrency Control on Relational Databases
16
2. R ELATIONAL U PDATE T RANSACTIONS S YNTAX AND S EMANTICS Concurrency Control on Relational Databases 16 IDM Transaction Model Insertion:i R (C) Deletion:d R (C) Modify:m R (C 1; C 2 ) Semantics is called effect
17
2. R ELATIONAL U PDATE T RANSACTIONS S YNTAX AND S EMANTICS Transaction Equivalence Two IDM Transactions t and t ’ are equivalent, if eff(t) = eff(t ’ ) Written: t t ’ Commutativity Rules Simplification Rules 17 Concurrency Control on Relational Databases
18
2. R ELATIONAL U PDATE T RANSACTIONS H ISTORIES AND F INAL S TATE S ERIALIZABILITY A history s is serial, if all Transactions appear strictly one after the other A history s is Final State Serializable if s s ’ for some history s ’ FSR IDM denotes class of all Final State Serializable histories 18 Concurrency Control on Relational Databases
19
2. R ELATIONAL U PDATE T RANSACTIONS H ISTORIES AND F INAL S TATE S ERIALIZABILITY Example: 19 Concurrency Control on Relational Databases t1 = d(3)m(1;2)m(3;4) t 2 = d(3)m(2;3) s = d2(3)d1(3)m 1 (1;2)m2(2;3)m1(3;4) s ’ = d(3)m(1;4)m(2;4)m(3;4)eff(s) = eff(s ’ ) s s ’
20
2. R ELATIONAL U PDATE T RANSACTIONS H ISTORIES AND F INAL S TATE S ERIALIZABILITY t1 = d(3)m(1;2)m(3;4) t 2 = d(3)m(2;3) s = d2(3)d1(3)m 1 (1;2)m2(2;3)m1(3;4)s / t1t2 or s / t2t1 s FSRIDMt1 t1‘ = d(3)m(1;2)s ‘ = d2(3)d1(3)m 1 (1;2)m2(2;3) t1t 2 20 Concurrency Control on Relational Databases
21
2. R ELATIONAL U PDATE T RANSACTIONS C ONFLICT S ERIALIZABILITY A history s for a set T of n transactions is conflict serializable, if s t p(1)...t p(n) using only the Commutativity Rules CSR IDM denotes class of all Conflict Serializable histories Conflict Graph G(s) = (T,E) History s CSR IDM, if G(s) is acyclic 21 Concurrency Control on Relational Databases
22
2. R ELATIONAL U PDATE T RANSACTIONS C ONFLICT S ERIALIZABILITY Consider s = m 2 (1;2) m 1 (2;3) m 2 (3;2) G(s) is cyclic, so s is not in CSR IDM On the other hand, s m 1 (2;3) m 2 (1;2) m 2 (3;2) t 1 t 2 s is in FSR IDM CSR IDM FSR IDM 22 Concurrency Control on Relational Databases t1t1 t2t2
23
2. R ELATIONAL U PDATE T RANSACTIONS E XTENDED C ONFLICT S ERIALIZABILITY Sometimes, the context in which a conflict occurs can make a difference: Example : Let s = d 1 (0) m 1 (0;1) m 2 (1;2) m 1 (2;3) G(s) is cyclic, but s m 2 (1;2) d 1 (0) m 1 (0;1) m 1 (2;3) t 2 t 1 Intuitively the conflict involving m 1 (0;1) does not exist (due to d 1 (0) ) ! A history s for a set T of n transactions is extended conflict serializable, if Extended Conflict Graph EG(s) = (T,E) is acyclic ECSR IDM denotes class of all Extended Conflict Serializable histories 23 Concurrency Control on Relational Databases
24
2. R ELATIONAL U PDATE T RANSACTIONS E XTENDED C ONFLICT S ERIALIZABILITY CSR IDM ECSR IDM FSR IDM 24 Concurrency Control on Relational Databases FSRIDM ECSRIDM CSRIDM
25
T HREE A PPROACHES TO CC ON RD: 3. Exploiting Transaction Program Knowledge 25 Concurrency Control on Relational Databases
26
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE 26 Concurrency Control on Relational Databases
27
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE T RANSACTION C HOPPING Transaction Chopping Short Transactions need less locks Short Transactions cause potentially less lock contention Chopping depends on concurrent Transactions 27 Concurrency Control on Relational Databases
28
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE T RANSACTION C HOPPING Definition of Transaction Chopping Every database operation invoked by the chopped transactions is contained in exactly one piece, and the order of operation invocations is preserved 28 Concurrency Control on Relational Databases
29
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE T RANSACTION C HOPPING Deadlock / Rollback situation Atomicity of original Transaction needs to be preserved 29 Concurrency Control on Relational Databases
30
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE T RANSACTION C HOPPING Concurrency Control on Relational Databases 30 Three types of Transactions: 1. A Transaction updating a single Customer’s Account as well as the corresponding Branch 2. A Transaction reading a Customer’s Account Balance 3. A Transaction comparing the grand Total of all Account Balances with the Sum of the Branch Balances
31
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE T RANSACTION C HOPPING t 1 = r 1 (A 1 )w 1 (A 1 )r 1 (B 1 )w 1 (B 1 ) t 2 = r 2 (A 3 )w 2 (A 3 )r 2 (B 1 )w 2 (B 1 ) t 3 = r 3 (A 4 )w 3 (A 4 )r 3 (B 2 )w 3 (B 2 ) t 4 = r 4 (A 2 ) t 5 = r 5 (A 4 ) t 6 = r 6 (A 1 )r 6 (A 2 )r 6 (A 3 )r 6 (B 1 )r 6 (A 4 )r 6 (A 5 )r 6 (B 2 ) 31 Concurrency Control on Relational Databases SELECT Balance INTO :oldbalance FROM Accounts WHERE AccountNo = A1; UPDATE Accounts SET Balance = :newbalance WHERE AccountNo = A1; SELECT Total INTO :oldtotal FROM Branches WHERE BranchNo = B1; UPDATE Branches SET TOTAL = :newtotal WHERE Branches = B1; SELECT Balance INTO :oldbalance FROM Accounts WHERE AccountNo = A1; UPDATE Accounts SET Balance = :newbalance WHERE AccountNo = A1; SELECT Total INTO :oldtotal FROM Branches WHERE BranchNo = B1; UPDATE Branches SET TOTAL = :newtotal WHERE Branches = B1;
32
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE T RANSACTION C HOPPING Test if a given chopping is correct with a Chopping Graph Example t 6 = r 6 (A 1 )r 6 (A 2 )r 6 (A 3 )r 6 (B 1 )r 6 (A 4 )r 6 (A 5 )r 6 (B 2 ) Chop into two pieces: t 61 = r 61 (A 1 )r 61 (A 2 )r 61 (A 3 )r 61 (B 1 ) t 62 = r 62 (A 4 )r 62 (A 5 )r 62 (B 2 ) Corresponding Chopping Graph: s: sibling c: conflict A chopping is correct if the associated graph does not contain an sc cycle. 32 Concurrency Control on Relational Databases
33
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE T RANSACTION C HOPPING Further in the example: t 1 = r 1 (A 1 )w 1 (A 1 )r 1 (B 1 )w 1 (B 1 ) Chop into two pieces: t 11 = r 1 (A 1 )w 1 (A 1 ) t 12 = r 1 (B 1 )w 1 (B 1 ) Corresponding Chopping Graph: Making chopping finer can introduce sc cycles 33 Concurrency Control on Relational Databases
34
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE A PPLICABILITY OF C HOPPING Applicability of Chopping To apply chopping algorithm, semantic knowledge is necessary Semantic knowledge derived form predicates Real World Example: High Level conflict Record-Level conflict 34 Concurrency Control on Relational Databases SELECT AccountNo, Balance FROM Accounts WHERE City = ‘Konstanz’ SELECT AccountNo, Balance FROM Accounts WHERE City = ‘Konstanz’ UPDATE Accounts SET Balance = Balance * 1.05 WHERE City = ‘Stuttgart’ UPDATE Accounts SET Balance = Balance * 1.05 WHERE City = ‘Stuttgart’
35
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE A PPLICABILITY OF C HOPPING Gain chopping relevant information from parameterized SQL statements: The chopping method is in limited settings ready for practical use, if No control-flow branching is used No loops are used No If-then-else constructs are used 35 Concurrency Control on Relational Databases SELECT AccountNo, Balance FROM Accounts WHERE AccountType = ‘savings’ AND City = :x SELECT AccountNo, Balance FROM Accounts WHERE AccountType = ‘savings’ AND City = :x UPDATE Accounts SET Balance = Balance * 1.05 WHERE AccountType = ‘checking’ AND City = :y UPDATE Accounts SET Balance = Balance * 1.05 WHERE AccountType = ‘checking’ AND City = :y
36
3. E XPLOITING T RANSACTION P ROGRAM K NOWLEDGE A PPLICABILITY OF C HOPPING Rewrite SQL statement to a parameter-less statement 36 Concurrency Control on Relational Databases SELECT AccountNo, Balance FROM Accounts WHERE AccountType = ‘savings’ AND City = :x; If not found then SELECT AccountNo, Balance FROM Accounts WHERE AccountTyoe = ‘checking’ AND City = :x; fi; SELECT AccountNo, Balance FROM Accounts WHERE AccountType = ‘savings’ AND City = :x; If not found then SELECT AccountNo, Balance FROM Accounts WHERE AccountTyoe = ‘checking’ AND City = :x; fi; SELECT AccountNo, Balance FROM Accounts WHERE AccountType = ‘savings’; SELECT AccountNo, Balance FROM Accounts WHERE AccountTyoe = ‘checking’; SELECT AccountNo, Balance FROM Accounts WHERE AccountType = ‘savings’; SELECT AccountNo, Balance FROM Accounts WHERE AccountTyoe = ‘checking’;
37
S UMMARY 37 Concurrency Control on Relational Databases
38
S UMMARY Predicate-Oriented Concurrency Control Trade-off between locking entire relation and locking individual tuples NP complete to test Satisfiability Relational Update Transactions Commutativity based Serializability ( FSR IDM ) Conflict Serializability ([ E ] CSR IDM ) Exploiting Transaction Program Knowledge Decomposition of Transactions into small pieces Only in limited settings ready for practical use 38 Concurrency Control on Relational Databases
39
T HANKS FOR LISTENING 39 Concurrency Control on Relational Databases
40
Q UESTIONS & A NSWERS 40 Concurrency Control on Relational Databases
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.