Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC-608 Database Systems

Similar presentations


Presentation on theme: "CPSC-608 Database Systems"— Presentation transcript:

1 CPSC-608 Database Systems
Fall 2018 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #36

2 Tranactions What can affect transaction ACID?
Atomicity: either all steps of a transaction happen, or none happen Consistency: a transaction transforms a consistent DB into a consistent DB Isolation: execution of a transaction is isolated from that of other transactions Durability: if a transaction commits, its effects persist. Database T1 …… Tn What can affect transaction ACID? Accident system failures may destroy Atomicity and Durability, thus Consistency; Concurrent executions of transactions (which is highly desired) may affect Isolation, thus Consistency.

3 DBMS Graduate Database lock table DDL language DDL complier file
administrator DDL complier lock table DDL language file manager logging & recovery concurrency control transaction manager database programmer index/file manager buffer manager query execution engine DML complier main memory buffers DML (query) language secondary storage (disks) DBMS Graduate Database

4 DBMS Graduate Database lock table DDL language DDL complier file
administrator DDL complier lock table DDL language file manager logging & recovery concurrency control transaction manager database programmer index/file manager buffer manager query execution engine DML complier main memory buffers DML (query) language secondary storage (disks) DBMS Graduate Database

5 Observation. In a schedule of a collection of transactions, if for every transaction T, the actions of T are scheduled consecutively without interlacing with actions from other transactions, then surely all transactions satisfy the Isolation condition.

6 Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Observation. In a schedule of a collection of transactions, if for every transaction T, the actions of T are scheduled consecutively without interlacing with actions from other transactions, then surely all transactions satisfy the Isolation condition.

7 Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Observation. In a schedule of a collection of transactions, if for every transaction T, the actions of T are scheduled consecutively without interlacing with actions from other transactions, then surely all transactions satisfy the Isolation condition. T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2

8 Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Observation. In a schedule of a collection of transactions, if for every transaction T, the actions of T are scheduled consecutively without interlacing with actions from other transactions, then surely all transactions satisfy the Isolation condition. Such a schedule is called a serial schedule. T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2

9 Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Observation. In a schedule of a collection of transactions, if for every transaction T, the actions of T are scheduled consecutively without interlacing with actions from other transactions, then surely all transactions satisfy the Isolation condition. Such a schedule is called a serial schedule. A serial schedule can be given by a permutation of the transactions that indicates the order of the execution: T1T2 · · · Tk. T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2

10 Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Observation. In a schedule of a collection of transactions, if for every transaction T, the actions of T are scheduled consecutively without interlacing with actions from other transactions, then surely all transactions satisfy the Isolation condition. Such a schedule is called a serial schedule. A serial schedule can be given by a permutation of the transactions that indicates the order of the execution: T1T2 · · · Tk Thus, if a schedule is “equivalent” to a serial schedule, then it ensures Isolation. T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2

11 Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Observation. In a schedule of a collection of transactions, if for every transaction T, the actions of T are scheduled consecutively without interlacing with actions from other transactions, then surely all transactions satisfy the Isolation condition. Such a schedule is called a serial schedule. A serial schedule can be given by a permutation of the transactions that indicates the order of the execution: T1T2 · · · Tk Thus, if a schedule is “equivalent” to a serial schedule, then it ensures Isolation. (two schedules S1 and S2 are “equivalent” if starting with any initial DB state, they always result in the same DB state.) T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2

12 Scheduling: Examples Constraint: A=B T1: Read(A) A  A+100 Write(A)
Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Scheduling: Examples

13 Schedule A T1 T2 Read(A); A  A+100 Write(A); Read(B); B  B+100;
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule A A serial schedule T1 T2 Read(A); A  A+100 Write(A); Read(B); B  B+100; Write(B); Read(A);A  A2; Read(B);B  B2;

14 Schedule A A B 25 25 T1 T2 Read(A); A  A+100 125 Write(A);
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule A A serial schedule A B 25 25 125 250 T1 T2 Read(A); A  A+100 Write(A); Read(B); B  B+100; Write(B); Read(A);A  A2; Read(B);B  B2;

15 Another serial schedule
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule B Another serial schedule T1 T2 Read(A);A  A2; Write(A); Read(B);B  B2; Write(B); Read(A); A  A+100 Read(B); B  B+100;

16 Another serial schedule
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule B Another serial schedule A B 25 25 50 150 T1 T2 Read(A);A  A2; Write(A); Read(B);B  B2; Write(B); Read(A); A  A+100 Read(B); B  B+100;

17 Schedule C T1 T2 Read(A); A  A+100 Write(A); Read(A);A  A2;
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule C A non-serial schedule T1 T2 Read(A); A  A+100 Write(A); Read(A);A  A2; Read(B); B  B+100; Write(B); Read(B);B  B2;

18 Schedule C A B 25 25 T1 T2 Read(A); A  A+100 125 Write(A);
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule C A non-serial schedule A B 25 25 125 250 T1 T2 Read(A); A  A+100 Write(A); Read(A);A  A2; Read(B); B  B+100; Write(B); Read(B);B  B2;

19 Another non-serial schedule
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule D Another non-serial schedule T1 T2 Read(A); A  A+100 Write(A); Read(A);A  A2; Read(B);B  B2; Write(B); Read(B); B  B+100;

20 Another non-serial schedule
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule D Another non-serial schedule A B 25 25 125 250 50 150 T1 T2 Read(A); A  A+100 Write(A); Read(A);A  A2; Read(B);B  B2; Write(B); Read(B); B  B+100;

21 Same as Schedule D but with new T2’
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule E Same as Schedule D but with new T2’ T1 T2’ Read(A); A  A+100 Write(A); Read(A);A  A1; Read(B);B  B1; Write(B); Read(B); B  B+100;

22 Same as Schedule D but with new T2’
Constraint: A=B T1: Read(A) A  A+100 Write(A) Read(B) B  B+100 Write(B) T2: Read(A) A  A2 B B2 Schedule E Same as Schedule D but with new T2’ A B 25 25 125 25 T1 T2’ Read(A); A  A+100 Write(A); Read(A);A  A1; Read(B);B  B1; Write(B); Read(B); B  B+100;

23 Want schedules that are “good”, regardless of
initial state and transaction semantics

24 Want schedules that are “good”, regardless of
initial state and transaction semantics Only look at order of read and writes

25 Want schedules that are “good”, regardless of
initial state and transaction semantics Only look at order of read and writes Example: Schedule C T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2;

26 Want schedules that are “good”, regardless of
initial state and transaction semantics Only look at order of read and writes Example: Schedule C = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C

27 Action Swapping

28 Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C A B 125 250

29 Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C A B 125 250

30 Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) swap
T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C A B 125 250

31 Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
SA= r1(A)w1(A)r1(B)w1(B)r2(A)w2(A)r2(B)w2(B) T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C A B 125 250

32 Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
A serial schedule SA= r1(A)w1(A)r1(B)w1(B)r2(A)w2(A)r2(B)w2(B) T1 T2 T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C A B 125 250

33 Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
A serial schedule SA= r1(A)w1(A)r1(B)w1(B)r2(A)w2(A)r2(B)w2(B) T1 T2 T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C T T2 Read(A); A  A+100 Write(A); Read(B); B  B+100; Write(B); Read(A); A  A2; Read(B); B  B2; Schedule A A B 125 250 A B 125 250

34 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D

35 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
If we want it to be equivalent to the schedule T1T2 T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D

36 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
If we want it to be equivalent to the schedule T1T2 T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D

37 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
If we want it to be equivalent to the schedule T1T2 T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D

38 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
If we want it to be equivalent to the schedule T2T1 T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D

39 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
If we want it to be equivalent to the schedule T2T1 T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D

40 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
If we want it to be equivalent to the schedule T2T1 T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D

41 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
Thus, SD is equivalent to neither T1T2 nor T2T1. T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D

42 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
Thus, SD is equivalent to neither T1T2 nor T2T1. T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D A B 125 250 50 150

43 Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B)
Thus, SD is equivalent to neither T1T2 nor T2T1. Thus, a schedule may NOT be equivalent to any serial schedule, and Isolation may not be preserved. T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B2; Write(B); Read(B); B  B+100; Schedule D A B 125 250 50 150

44 Serializability A schedule is serializable if it is equivalent to a serial schedule.

45 A schedule is serializable if it is equivalent to a serial schedule.
Serializability A schedule is serializable if it is equivalent to a serial schedule. T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C A B 125 250 SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)

46 A schedule is serializable if it is equivalent to a serial schedule.
Serializability A schedule is serializable if it is equivalent to a serial schedule. T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C A B 125 250 swap SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)

47 Serializability A schedule is serializable if it is equivalent to a serial schedule. T T2 Read(A); A  A+100 Write(A); Read(A); A  A2; Read(B); B  B+100; Write(B); Read(B); B  B2; Schedule C A B 125 250 Schedule A T T2 Read(A); A  A+100 Write(A); Read(B); B  B+100; Write(B); Read(A); A  A2; Read(B); B  B2; A B 125 250 swap SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) SA = r1(A)w1(A)r1(B)w1(B)r2(A)w2(A)r2(B)w2(B) T1 T2

48 Conflict-Serializability
(A sufficient condition for serializability)

49 Conflict-Serializability
(A sufficient condition for serializability) Consider: T1: … r1(*)r1(*) … … w1(*)r1(*) … … r1(*)w1(*) … … w1(*)w1(*) …

50 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: … r1(*)w1(*) … swap? … w1(*)w1(*) … swap?

51 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap?

52 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2:

53 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2:

54 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2:

55 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2:

56 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2:

57 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2: … r1(A)r2(A) … swap? … r1(A)w2(A) … … w1(A)r2(A) … … w1(A)w2(A) …

58 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2: … r1(A)r2(A) … swap? … r1(A)w2(A) … … w1(A)r2(A) … … w1(A)w2(A) …

59 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2: … r1(A)r2(A) … swap? … r1(A)w2(A) … … w1(A)r2(A) … … w1(A)w2(A) …

60 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2: … r1(A)r2(A) … swap? … r1(A)w2(A) … … w1(A)r2(A) … … w1(A)w2(A) …

61 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … T1, T2: … r1(A)r2(A) … swap? … r1(A)w2(A) … … w1(A)r2(A) … … w1(A)w2(A) …

62 Conflict-Serializability
(A sufficient condition for serializability) Consider: … r1(*)r1(*) … swap? … w1(*)r1(*) … swap? T1: Violate T1’s logic! … r1(*)w1(*) … swap? … w1(*)w1(*) … swap? … r1(A)r2(B) … swap? … r1(A)w2(B) … … w1(A)r2(B) … … w1(A)w2(B) … Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write T1, T2: … r1(A)r2(A) … swap? … r1(A)w2(A) … … w1(A)r2(A) … … w1(A)w2(A) …

63 Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Conflict-Serializability (A sufficient condition for serializability) Thus: Swapping two non-conflicting actions gives an equivalent schedule.

64 Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Conflict-Serializability (A sufficient condition for serializability) Thus: Swapping two non-conflicting actions gives an equivalent schedule. A schedule S1 is conflict-serializable if it can be converted into a serial schedule by swapping non-conflicting actions.

65 Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Conflict-Serializability (A sufficient condition for serializability) Thus: Swapping two non-conflicting actions gives an equivalent schedule. A schedule S1 is conflict-serializable if it can be converted into a serial schedule by swapping non-conflicting actions. swap SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) SA = r1(A)w1(A)r1(B)w1(B)r2(A)w2(A)r2(B)w2(B) T1 T2

66 Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Conflict-Serializability (A sufficient condition for serializability) Thus: Swapping two non-conflicting actions gives an equivalent schedule. A schedule S1 is conflict-serializable if it can be converted into a serial schedule by swapping non-conflicting actions. A conflict-serializable schedule is serializable.

67 Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Conflict-Serializability (A sufficient condition for serializability) Thus: Swapping two non-conflicting actions gives an equivalent schedule. A schedule S1 is conflict-serializable if it can be converted into a serial schedule by swapping non-conflicting actions. A conflict-serializable schedule is serializable. A serializable schedule may not be conflict-serializable.

68 Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Conflict-Serializability (A sufficient condition for serializability) Thus: Swapping two non-conflicting actions gives an equivalent schedule. A schedule S1 is conflict-serializable if it can be converted into a serial schedule by swapping non-conflicting actions. A conflict-serializable schedule is serializable. A serializable schedule may not be conflict-serializable. S1 = w1(A)w2(A)w3(A)w2(B)w1(B)w3(B) S2 = w1(A)w1(B)w2(A)w2(B)w3(A)w3(B)

69 Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Conflict-Serializability (A sufficient condition for serializability) Thus: Swapping two non-conflicting actions gives an equivalent schedule. A schedule S1 is conflict-serializable if it can be converted into a serial schedule by swapping non-conflicting actions. A conflict-serializable schedule is serializable. A serializable schedule may not be conflict-serializable. How do we know if a schedule is conflict-serializable?

70 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle.

71 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B)

72 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B) 1 2 3

73 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B) 1 2 3

74 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B) 1 2 3

75 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B) 1 2 3

76 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B) 1 2 3 S2: r2(A)r1(B)w2(A)r2(B)r3(A)w1(B)w3(A)w2(B)

77 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B) 1 2 3 S2: r2(A)r1(B)w2(A)r2(B)r3(A)w1(B)w3(A)w2(B) 1 2 3

78 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability conflict-serializable Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B) 1 2 3 S2: r2(A)r1(B)w2(A)r2(B)r3(A)w1(B)w3(A)w2(B) 1 2 3 Not conflict-serializable

79 Testing Conflict-Serializability
Two actions conflict if either they are by the same transaction, or they are by two transactions on the same element and at least one of the actions is write Testing Conflict-Serializability conflict-serializable Algorithm TestCS. Input: a schedule S Build a directed graph GS; Each transaction is a node in GS; If two actions a1 and a2 conflict, where a1 and a2 are by T1 and T2, resp., and a1 is before a2 in S, then add an edge from T1 to T2 in GS; S is conflict-serializable if and only if GS contains no cycle. S1: r2(A)r1(B)w2(A)r3(A)w1(B)w3(A)r2(B)w2(B) 1 2 3 S2: r2(A)r1(B)w2(A)r2(B)r3(A)w1(B)w3(A)w2(B) 1 2 3 Not conflict-serializable Why does the algorithm work? Claim: If GS is acyclic, then S is equivalent to any serial schedule obtained by topologically sorting GS. Proof. Let T1T2 … Tk be a topological order of GS. Since there is no edge into T1, for each action a in T1, there is no action from other transactions that conflict a and appears in S before a. Therefore, the actions of T1 can be all swapped with non-conflict actions and move to the front of the schedule, resulting in an equivalent schedule. Now by induction we can also convert the rest of the schedule into an equivalent serial schedule.


Download ppt "CPSC-608 Database Systems"

Similar presentations


Ads by Google