CPSC-608 Database Systems

Slides:



Advertisements
Similar presentations
Chapter 15: Transactions Transaction Concept Transaction Concept Concurrent Executions Concurrent Executions Serializability Serializability Testing for.
Advertisements

Cs4432concurrency control1 CS4432: Database Systems II Lecture #22 Concurrency Control Professor Elke A. Rundensteiner.
Em Spatiotemporal Database Laboratory Pusan National University File Processing : Transaction Management 2004, Spring Pusan National University Ki-Joune.
CPSC-608 Database Systems Fall 2009 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #2.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #9.
Chapter 7 Transactions 7.1 Transaction Concept 7.2 Transaction State 7.3 Implementation of Atomicity and Durability 7.4 Concurrent Executions 7.5 Serializability.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #6.
Transaction Processing General Overview Where we ‘ve been... DBA skills for relational DB’s: Logical Schema Design  E/R diagrams  Decomposition.
©Silberschatz, Korth and Sudarshan15.1Database System ConceptsTransactions Transaction Concept Transaction State Implementation of Atomicity and Durability.
Database Management Systems I Alex Coman, Winter 2006
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #13.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #5.
Concurrency Control 18.1 – 18.2 Chiu Luk CS257 Database Systems Principles Spring 2009.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #9.
Cs4432concurrency control1 CS4432: Database Systems II Lecture #21 Concurrency Control Professor Elke A. Rundensteiner.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #12.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #14.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes 1.
Cs4432concurrency control1 CS4432: Database Systems II Concurrency Control.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #6.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes 1.
CS4432: Database Systems II Transaction Management Motivation 1.
TRANSACTIONS. Objectives Transaction Concept Transaction State Concurrent Executions Serializability Recoverability Implementation of Isolation Transaction.
02/23/2005Yan Huang - CSCI5330 Database Implementation – Transaction Transaction.
CS 162 Discussion Section Week 9 11/11 – 11/15. Today’s Section ●Project discussion (5 min) ●Quiz (10 min) ●Lecture Review (20 min) ●Worksheet and Discussion.
Introduction to Data Management CSE 344 Lecture 23: Transactions CSE Winter
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Transaction Processing Chapter Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various data.
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
Chapter 15: Transactions Loc Hoang CS 157B. Definition n A transaction is a discrete unit of work that must be completely processed or not processed at.
Chapter 14 Transactions Yonsei University 1 st Semester, 2015 Sanghyun Park.
CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #5.
©Silberschatz, Korth and Sudarshan14.1Database System Concepts - 6 th Edition Chapter 14: Transactions Transaction Concept Transaction State Concurrent.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 14: Transactions.
Scholastic Dishonesty
Database System Implementation CSE 507
Database System Implementation CSE 507
Concurrency Control.
Chapter 15: Transactions
Transaction Management and Concurrency
Chapter 14: Transactions
Chapter 13: Transactions
Database Management System
CPSC-608 Database Systems
Transactions.
March 21st – Transactions
Temple University – CIS Dept. CIS661 – Principles of Data Management
Transactions.
Chapter 15: Transactions
Transactions B.Ramamurthy Ch.13 11/22/2018 B.Ramamurthy.
Transactions Sylvia Huang CS 157B.
Lecture 21: Concurrency & Locking
Chapter 14: Transactions
CS162 Operating Systems and Systems Programming Review (II)
Transaction Management Overview
Chapter 14: Transactions
CPSC-608 Database Systems
CPSC-608 Database Systems
Scholastic Dishonesty
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
C. Faloutsos Transactions
Temple University – CIS Dept. CIS616– Principles of Data Management
CPSC-608 Database Systems
UNIT -IV Transaction.
Presentation transcript:

CPSC-608 Database Systems Fall 2018 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #36

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.

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

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

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.

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.

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

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

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

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

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

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

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;

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

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;

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

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;

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

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;

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

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;

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

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

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

Want schedules that are “good”, regardless of initial state and transaction semantics Only look at order of read and writes Example: Schedule C 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;

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) 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; Schedule C

Action Swapping

Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) 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; Schedule C A B 25 25 125 250 250 250

Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) 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; Schedule C A B 25 25 125 250 250 250

Action Swapping SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B) swap 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; Schedule C A B 25 25 125 250 250 250

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) 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; Schedule C A B 25 25 125 250 250 250

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 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; Schedule C A B 25 25 125 250 250 250

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 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; Schedule C 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; Schedule A A B 25 25 125 250 250 250 A B 25 25 125 250 250 250

Action Swapping SD = r1(A)w1(A)r2(A)w2(A)r2(B)w2(B)r1(B)w1(B) 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; Schedule D

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 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; Schedule D

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 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; Schedule D

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 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; Schedule D

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 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; Schedule D

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 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; Schedule D

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 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; Schedule D

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. 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; Schedule D

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. 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; Schedule D A B 25 25 125 250 50 150 250 150

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. 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; Schedule D A B 25 25 125 250 50 150 250 150

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

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. 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; Schedule C A B 25 25 125 250 250 250 SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)

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. 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; Schedule C A B 25 25 125 250 250 250 swap SC = r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)

Serializability A schedule is serializable if it is equivalent to a 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; Schedule C A B 25 25 125 250 250 250 Schedule A 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; A B 25 25 125 250 250 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

Conflict-Serializability (A sufficient condition for serializability)

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

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

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?

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:

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:

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:

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: √

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: √ √

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

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

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) … √

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) … √

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) … √

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) … √

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.

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.

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

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.

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.

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)

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?

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.

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)

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

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

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

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

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)

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

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

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.