Concurrency Control on Relational Databases

40
CONCURRENCY CONTROL ON RELATIONAL DATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

description

Concurrency Control on Relational Databases. Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann. Outline. Goal and Overview Examine Three Approaches to CC on RD: 1. Predicate-Oriented Concurrency Control 2. Relational Update Transactions Syntax and Semantics - PowerPoint PPT Presentation

Transcript of Concurrency Control on Relational Databases

Page 1: Concurrency Control on Relational Databases

CONCURRENCY CONTROL ON RELATIONAL DATABASESSeminar: Transaction Processing (Bachelor)SS 2009

Dennis Stratmann

Page 2: Concurrency Control on Relational Databases

2

Concurrency Control on Relational Databases

OUTLINE

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

Page 3: Concurrency Control on Relational Databases

Concurrency Control on Relational Databases

3

GOAL AND OVERVIEW

Page 4: Concurrency Control on Relational Databases

4

Concurrency Control on Relational Databases

GOAL AND OVERVIEW

Semantic approach to Concurrency Control Possible to exploit semantic knowledge at

higher abstraction level

Page 5: Concurrency Control on Relational Databases

5

Concurrency Control on Relational Databases

GOAL AND OVERVIEW

Three Approaches to CC on RD: Predicate-Oriented Concurrency Control Relational Update Transactions Exploiting Transaction Program Knowledge

Page 6: Concurrency Control on Relational Databases

Concurrency Control on Relational Databases

6

THREE APPROACHES TO CC ON RD:

1. Predicate-Oriented Concurrency Control

Page 7: Concurrency Control on Relational Databases

7

Concurrency Control on Relational Databases

1. PREDICATE-ORIENTED CC ON RD

Relational Database

Page 8: Concurrency Control on Relational Databases

8

Concurrency Control on Relational Databases

1. PREDICATE-ORIENTED CC ON RD

Lock entire Relation

Page 9: Concurrency Control on Relational Databases

9

Concurrency Control on Relational Databases

1. PREDICATE-ORIENTED CC ON RD

Lock individual Tuples

Page 10: Concurrency Control on Relational Databases

Concurrency Control on Relational Databases

10

1. PREDICATE-ORIENTED CC ON RD

Phantom Problem: Transaction 1:

Transaction 2:

Emp Name Department

Position Salary

Jones Service Clerk 20 000Meier Service Clerk 22 000Paulus Service Manager 42 000Smyth Toys Cashier 25 000Brown Sales Clerk 28 000Albert Sales Manager 38 000

DELETE FROM Emp WHERE Department = ‘Service’ AND Position = ‘Manager’

INSERT INTO Emp VALUES (‘Smith’, ‘Service’, ‘Manager’, 40000)

SELECT Name, Position, SalaryFROM EmpWHERE Department = ‘Service’

UPDATE EmpSET Department = ‘Sales’WHERE Department = ‘Service’AND Position <> ‘Manager’

INSERT INTO EmpVALUES (‘Sone’, ‘Serivce’, ‘Clerk’, 13000)

Page 11: Concurrency Control on Relational Databases

11

Concurrency Control on Relational Databases

1. PREDICATE-ORIENTED CC ON RD

Predicate Locking

Page 12: Concurrency Control on Relational Databases

12

Concurrency Control on Relational Databases

1. PREDICATE-ORIENTED CC ON RD

Transaction 1: Ca: Department = ‘Service‘ Position =

‘Manager‘

Cb: Name = ‘Smith‘ Department = ‘Service‘ Position = ‘Manager‘ Salary = ‘40000‘

Cc1: Department = ‘Service‘ Position ‘Manager‘

Cc2: Department = ‘Sales‘ Position ‘Manager‘

Cd: Name = ‘Stone‘ Department = ‘Service‘ Position = ‘Clerk‘ Salary = ‘13000‘

DELETE FROM Emp WHERE Department = ‘Service’ AND Position = ‘Manager’

INSERT INTO Emp VALUES (‘Smith’, ‘Service’, ‘Manager’, 40000)

UPDATE EmpSET Department = ‘Sales’WHERE Department = ‘Service’AND Position <> ‘Manager’

INSERT INTO EmpVALUES (‘Sone’, ‘Serivce’, ‘Clerk’, 13000)

Page 13: Concurrency Control on Relational Databases

13

Concurrency Control on Relational Databases

1. PREDICATE-ORIENTED CC ON RD

Transaction 2:

Cq: Department = ‘Service‘

Transaction 3:

Cp: Department = ‘Sales‘

Example: H(Ca) H(Cq) ∅ H(Cb) H(Cq) ∅ H(Cc1) H(Cq) ∅ H(Cc2) H(Cq) = ∅ H(Cd) H(Cq) ∅

SELECT Name, Position, SalaryFROM EmpWHERE Department = ‘Service’

SELECT Name, Position, SalaryFROM EmpWHERE Department = ‘Sales’

H(Ca) H(Cp) = ∅ H(Cb) H(Cp) = ∅ H(Cc1) H(Cp) = ∅ H(Cc2) H(Cp) ∅ H(Cd) H(Cp) = ∅

Page 14: Concurrency Control on Relational Databases

14

Concurrency Control on Relational Databases

1. PREDICATE-ORIENTED CC ON RD

Scheduler

Page 15: Concurrency Control on Relational Databases

Concurrency Control on Relational Databases

15

THREE APPROACHES TO CC ON RD:

2. Relational Update Transactions

Page 16: Concurrency Control on Relational Databases

Concurrency Control on Relational Databases

16

2. RELATIONAL UPDATE TRANSACTIONSSYNTAX AND SEMANTICS

IDM Transaction Model Insertion: iR(C) Deletion: dR(C) Modify:

mR(C1;C2) Semantics is called

effect

Page 17: Concurrency Control on Relational Databases

17

Concurrency Control on Relational Databases

2. RELATIONAL UPDATE TRANSACTIONSSYNTAX AND SEMANTICS

Transaction Equivalence Two IDM Transactions t and t’ are equivalent,

if eff(t) = eff(t’) Written: t t’

Commutativity Rules Simplification Rules

Page 18: Concurrency Control on Relational Databases

18

Concurrency Control on Relational Databases

2. RELATIONAL UPDATE TRANSACTIONSHISTORIES AND FINAL STATE SERIALIZABILITY

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’

FSRIDM denotes class of all Final State Serializable histories

Page 19: Concurrency Control on Relational Databases

19

Concurrency Control on Relational Databases

2. RELATIONAL UPDATE TRANSACTIONSHISTORIES AND FINAL STATE SERIALIZABILITY

Example:

t1 = d(3)m(1;2)m(3;4)

t2 = d(3)m(2;3)

s = d2(3)d1(3)m1(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’

Page 20: Concurrency Control on Relational Databases

20

Concurrency Control on Relational Databases

2. RELATIONAL UPDATE TRANSACTIONSHISTORIES AND FINAL STATE SERIALIZABILITY

s = d2(3)d1(3)m1(1;2)m2(2;3)m1(3;4)

s / t1t2 or s / t2t1 s FSRIDM

t1 t1‘ = d(3)m(1;2)

s‘

= d2(3)d1(3)m1(1;2)m2(2;3) t1t2

Page 21: Concurrency Control on Relational Databases

21

Concurrency Control on Relational Databases

2. RELATIONAL UPDATE TRANSACTIONSCONFLICT SERIALIZABILITY

A history s for a set T of n transactions is conflict serializable, if s tp(1)...tp(n) using only the Commutativity Rules

CSRIDM denotes class of all Conflict Serializable histories

Conflict Graph G(s) = (T,E) History s CSRIDM, if G(s) is acyclic

Page 22: Concurrency Control on Relational Databases

22

Concurrency Control on Relational Databases

2. RELATIONAL UPDATE TRANSACTIONSCONFLICT SERIALIZABILITY

Consider s = m2(1;2) m1(2;3) m2(3;2)

G(s) is cyclic, so s is not in CSRIDM On the other hand,

s m1(2;3) m2(1;2) m2(3;2) t1 t2

s is in FSRIDM CSRIDM FSRIDM

t1

t2

Page 23: Concurrency Control on Relational Databases

23

Concurrency Control on Relational Databases

2. RELATIONAL UPDATE TRANSACTIONSEXTENDED CONFLICT SERIALIZABILITY

Sometimes, the context in which a conflict occurs can make a difference:Example: Let

s = d1(0) m1(0;1) m2(1;2) m1(2;3) G(s) is cyclic, but s m2(1;2) d1(0) m1(0;1) m1(2;3) t2 t1

Intuitively the conflict involving m1(0;1) does not exist (due to d1(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

ECSRIDM denotes class of all Extended Conflict Serializable histories

Page 24: Concurrency Control on Relational Databases

24

Concurrency Control on Relational Databases

2. RELATIONAL UPDATE TRANSACTIONSEXTENDED CONFLICT SERIALIZABILITY

CSRIDM ECSRIDM FSRIDM

FSRIDM

CSRIDM

Page 25: Concurrency Control on Relational Databases

Concurrency Control on Relational Databases

25

THREE APPROACHES TO CC ON RD:

3. Exploiting Transaction Program Knowledge

Page 26: Concurrency Control on Relational Databases

26

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

Page 27: Concurrency Control on Relational Databases

27

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

TRANSACTION CHOPPING

Transaction Chopping Short Transactions need less locks Short Transactions cause potentially less lock contention

Chopping depends on concurrent Transactions

Page 28: Concurrency Control on Relational Databases

28

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

TRANSACTION CHOPPING

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

Page 29: Concurrency Control on Relational Databases

29

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

TRANSACTION CHOPPING

Deadlock / Rollback situation

Atomicity of original Transaction needs to be preserved

Page 30: Concurrency Control on Relational Databases

Concurrency Control on Relational Databases

30

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

TRANSACTION CHOPPING

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

Page 31: Concurrency Control on Relational Databases

31

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

TRANSACTION CHOPPING

t1 = r1(A1)w1(A1)r1(B1)w1(B1)t2 = r2(A3)w2(A3)r2(B1)w2(B1)t3 = r3(A4)w3(A4)r3(B2)w3(B2)t4 = r4(A2)t5 = r5(A4)t6 = r6(A1)r6(A2)r6(A3)r6(B1)r6(A4)r6(A5)r6(B2)

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;

Page 32: Concurrency Control on Relational Databases

32

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

TRANSACTION CHOPPING Test if a given chopping is correct with a Chopping Graph Example

t6 = r6(A1)r6(A2)r6(A3)r6(B1)r6(A4)r6(A5)r6(B2) Chop into two pieces:

t61 = r61(A1)r61(A2)r61(A3)r61(B1)t62 = r62(A4)r62(A5)r62(B2)

Corresponding Chopping Graph:

s: siblingc: conflict

A chopping is correct if the associated graph does not contain an sc cycle.

Page 33: Concurrency Control on Relational Databases

33

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

TRANSACTION CHOPPING

Further in the example:t1 = r1(A1)w1(A1)r1(B1)w1(B1)

Chop into two pieces:t11 = r1(A1)w1(A1)t12 = r1(B1)w1(B1)

Corresponding Chopping Graph:

Making chopping finer can introduce sc cycles

Page 34: Concurrency Control on Relational Databases

34

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

APPLICABILITY OF CHOPPING

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

SELECT AccountNo, Balance FROM AccountsWHERE City = ‘Konstanz’

UPDATE Accounts SET Balance = Balance * 1.05WHERE City = ‘Stuttgart’

Page 35: Concurrency Control on Relational Databases

35

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

APPLICABILITY OF CHOPPING

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

SELECT AccountNo, Balance FROM AccountsWHERE AccountType = ‘savings’ AND City = :x

UPDATE Accounts SET Balance = Balance * 1.05WHERE AccountType = ‘checking’ AND City = :y

Page 36: Concurrency Control on Relational Databases

36

Concurrency Control on Relational Databases

3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

APPLICABILITY OF CHOPPING

Rewrite SQL statement to a parameter-less statementSELECT AccountNo, Balance FROM AccountsWHERE AccountType = ‘savings’ AND City = :x;

If not found thenSELECT AccountNo, Balance FROM AccountsWHERE AccountTyoe = ‘checking’ AND City = :x;fi;

SELECT AccountNo, Balance FROM AccountsWHERE AccountType = ‘savings’;SELECT AccountNo, Balance FROM AccountsWHERE AccountTyoe = ‘checking’;

Page 37: Concurrency Control on Relational Databases

Concurrency Control on Relational Databases

37

SUMMARY

Page 38: Concurrency Control on Relational Databases

38

Concurrency Control on Relational Databases

SUMMARY

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 (FSRIDM)•Conflict Serializability ([E]CSRIDM)

Exploiting Transaction Program Knowledge •Decomposition of Transactions into small pieces•Only in limited settings ready for practical use

Page 39: Concurrency Control on Relational Databases

39

Concurrency Control on Relational Databases

THANKS FOR LISTENING

Page 40: Concurrency Control on Relational Databases

40

Concurrency Control on Relational Databases

QUESTIONS & ANSWERS