C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009...

Preview:

Citation preview

CONCURRENCY CONTROL ON RELATIONAL DATABASES

Seminar: Transaction Processing (Bachelor)

SS 2009

Dennis Stratmann

2

Concu

rrency

Contro

l on R

ela

tional D

ata

base

sOUTLINE

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

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

3

GOAL AND OVERVIEW

4

Concu

rrency

Contro

l on R

ela

tional D

ata

base

sGOAL AND OVERVIEW

Semantic approach to Concurrency Control Possible to exploit semantic knowledge at

higher abstraction level

5

Concu

rrency

Contro

l on R

ela

tional D

ata

base

sGOAL AND OVERVIEW

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

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

6

THREE APPROACHES TO CC ON RD:

1. Predicate-Oriented Concurrency Control

7

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Relational Database

8

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Lock entire Relation

9

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Lock individual Tuples

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

10

1. PREDICATE-ORIENTED CC ON RD

Phantom Problem: Transaction 1:

Transaction 2:

Emp Name Department

Position Salary

Jones Service Clerk 20 000

Meier Service Clerk 22 000

Paulus Service Manager 42 000

Smyth Toys Cashier 25 000

Brown Sales Clerk 28 000

Albert 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)

11

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Predicate Locking

12

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. 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)

13

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. 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) = ∅

14

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Scheduler

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

15

THREE APPROACHES TO CC ON RD:

2. Relational Update Transactions

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

16

2. RELATIONAL UPDATE TRANSACTIONSSYNTAX AND SEMANTICS

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

mR(C1;C2)

Semantics is called effect

17

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

SYNTAX AND SEMANTICS

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

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

Commutativity Rules Simplification Rules

18

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

HISTORIES 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

19

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

HISTORIES 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’

20

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

HISTORIES AND FINAL STATE SERIALIZABILITYt1

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

t2

= d(3)m(2;3)

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) t1

t2

21

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

CONFLICT 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

22

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

CONFLICT 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

23

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

EXTENDED 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

24

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

EXTENDED CONFLICT SERIALIZABILITY

CSRIDM ECSRIDM FSRIDM

FSRIDM

CSRIDM

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

25

THREE APPROACHES TO CC ON RD:

3. Exploiting Transaction Program Knowledge

26

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

27

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. 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

28

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. 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

29

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

TRANSACTION CHOPPING

Deadlock / Rollback situation

Atomicity of original Transaction needs to be preserved

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

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

31

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. 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;

32

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. 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: sibling

c: conflict

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

33

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. 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

34

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. 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’

35

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. 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

36

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. 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’;

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

37

SUMMARY

38

Concu

rrency

Contro

l on R

ela

tional D

ata

base

sSUMMARY

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

39

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

THANKS FOR LISTENING

40

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

QUESTIONS & ANSWERS

Recommended