c oncurrency c ontrol on r elational d atabases seminar: transaction processing (bachelor) ss 2009...

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

Upload: lydia-strickland

Post on 17-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

CONCURRENCY CONTROL ON RELATIONAL DATABASES

Seminar: Transaction Processing (Bachelor)

SS 2009

Dennis Stratmann

Page 2: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES 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

Page 3: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

3

GOAL AND OVERVIEW

Page 4: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 5: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 6: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

6

THREE APPROACHES TO CC ON RD:

1. Predicate-Oriented Concurrency Control

Page 7: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

7

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Relational Database

Page 8: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

8

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Lock entire Relation

Page 9: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

9

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Lock individual Tuples

Page 10: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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)

Page 11: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

11

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Predicate Locking

Page 12: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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)

Page 13: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 14: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

14

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s1. PREDICATE-ORIENTED CC ON RD

Scheduler

Page 15: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

15

THREE APPROACHES TO CC ON RD:

2. Relational Update Transactions

Page 16: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 17: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 18: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 19: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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’

Page 20: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 21: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 22: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 23: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 24: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

24

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s2. RELATIONAL UPDATE TRANSACTIONS

EXTENDED CONFLICT SERIALIZABILITY

CSRIDM ECSRIDM FSRIDM

FSRIDM

CSRIDM

Page 25: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

25

THREE APPROACHES TO CC ON RD:

3. Exploiting Transaction Program Knowledge

Page 26: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

26

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s3. EXPLOITING TRANSACTION PROGRAM KNOWLEDGE

Page 27: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 28: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 29: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 30: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 31: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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;

Page 32: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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.

Page 33: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 34: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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’

Page 35: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 36: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 37: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

37

SUMMARY

Page 38: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

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

Page 39: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

39

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

THANKS FOR LISTENING

Page 40: C ONCURRENCY C ONTROL ON R ELATIONAL D ATABASES Seminar: Transaction Processing (Bachelor) SS 2009 Dennis Stratmann

40

Concu

rrency

Contro

l on R

ela

tional D

ata

base

s

QUESTIONS & ANSWERS