
Understanding Database Systems: ACID Properties, Transactions, and Serializability
Explore the essential concepts of database systems, including ACID properties, transaction management, and conflict-serializability. Learn about the key principles governing database operations and the factors that can impact transaction integrity.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
CSCE-608 Database Systems Spring 2025 Instructor: Jianer Chen Office: PETR 428 Phone: 845-4259 Email: chen@cse.tamu.edu Notes 38: Conflict serializable schedules
Tranactions 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. 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. Database
lock table DDL DDL language concurrency database file logging & administrator complier control manager recovery transaction manager index/file buffer manager manager query database execution programmer DML (query) DML engine main language complier memory secondary buffers storage DBMS (disks) Graduate Database
Action Swapping swap 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 Schedule A Schedule C A B 25 25 A B 25 25 T1 Read(A); A A+100 Write(A); Read(B); B B+100; Write(B); T2 T1 Read(A); A A+100 Write(A); Read(B); B B+100; Write(B); T2 125 125 Read(A); A A 2; Write(A); 125 250 Read(A); A A 2; Write(A); Read(B); B B 2; Write(B); 250 125 Read(B); B B 2; Write(B); 250 250 250 250 250 250
Serializability A schedule is serializable if it is equivalent to a serial schedule. Schedule C Schedule A A B 25 25 A B 25 25 T1 Read(A); A A+100 Write(A); Read(B); B B+100; Write(B); T2 T1 Read(A); A A+100 Write(A); Read(B); B B+100; Write(B); T2 125 125 Read(A); A A 2; Write(A); 125 250 Read(A); A A 2; Write(A); Read(B); B B 2; Write(B); 250 125 Read(B); B B 2; Write(B); 250 250 250 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) T2 T1
Conflict-Serializability (A sufficient condition for serializability) Consider: swap? swap? T1: w1(*)r1(*) swap? r1(*)r1(*) swap? Violate T1 s logic! w1(*)w1(*) r1(*)w1(*)
Conflict-Serializability (A sufficient condition for serializability) Consider: swap? swap? T1: w1(*)r1(*) swap? r1(*)r1(*) swap? Violate T1 s logic! w1(*)w1(*) r1(*)w1(*) swap? swap? T1, T2: w1(A)r2(B) swap? r1(A)r2(B) swap? w1(A)w2(B) r1(A)w2(B)
Conflict-Serializability (A sufficient condition for serializability) Consider: swap? swap? T1: w1(*)r1(*) swap? r1(*)r1(*) swap? Violate T1 s logic! w1(*)w1(*) r1(*)w1(*) swap? swap? T1, T2: w1(A)r2(B) swap? r1(A)r2(B) swap? w1(A)w2(B) swap? r1(A)w2(B) swap? w1(A)r2(A) swap? r1(A)r2(A) swap? w1(A)w2(A) r1(A)w2(A)
Conflict-Serializability (A sufficient condition for serializability) Consider: swap? swap? T1: w1(*)r1(*) swap? r1(*)r1(*) swap? Violate T1 s logic! w1(*)w1(*) r1(*)w1(*) swap? swap? T1, T2: w1(A)r2(B) swap? r1(A)r2(B) swap? w1(A)w2(B) swap? r1(A)w2(B) swap? w1(A)r2(A) swap? r1(A)r2(A) swap? w1(A)w2(A) r1(A)w2(A)
Conflict-Serializability (A sufficient condition for serializability) Consider: swap? swap? T1: w1(*)r1(*) swap? r1(*)r1(*) swap? Violate T1 s logic! w1(*)w1(*) r1(*)w1(*) swap? swap? T1, T2: w1(A)r2(B) swap? r1(A)r2(B) swap? w1(A)w2(B) swap? r1(A)w2(B) swap? w1(A)r2(A) swap? r1(A)r2(A) swap? w1(A)w2(A) r1(A)w2(A)
Conflict-Serializability (A sufficient condition for serializability) Consider: swap? swap? T1: w1(*)r1(*) swap? r1(*)r1(*) swap? Violate T1 s logic! w1(*)w1(*) r1(*)w1(*) swap? swap? T1, T2: w1(A)r2(B) swap? r1(A)r2(B) swap? w1(A)w2(B) swap? r1(A)w2(B) swap? w1(A)r2(A) swap? r1(A)r2(A) swap? w1(A)w2(A) r1(A)w2(A)
Conflict-Serializability (A sufficient condition for serializability) Consider: swap? swap? T1: w1(*)r1(*) swap? r1(*)r1(*) swap? Violate T1 s logic! w1(*)w1(*) r1(*)w1(*) swap? swap? T1, T2: w1(A)r2(B) swap? r1(A)r2(B) swap? w1(A)w2(B) swap? r1(A)w2(B) swap? w1(A)r2(A) swap? r1(A)r2(A) swap? w1(A)w2(A) r1(A)w2(A)
Conflict-Serializability (A sufficient condition for serializability) Consider: swap? swap? T1: w1(*)r1(*) swap? r1(*)r1(*) swap? Violate T1 s logic! w1(*)w1(*) r1(*)w1(*) swap? swap? 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: w1(A)r2(B) swap? r1(A)r2(B) swap? w1(A)w2(B) swap? r1(A)w2(B) swap? w1(A)r2(A) swap? r1(A)r2(A) swap? w1(A)w2(A) r1(A)w2(A)
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.
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.
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) T2 T1
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.
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.
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)
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?
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. S is conflict-serializable if and only if GS contains no cycle.
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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)
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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)
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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
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 1. Build a directed graph GS; 2. Each transaction is a node in GS; 3. 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; 4. 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.
Enforcing Conflict-Serializability Using locking protocol T1 T2 Tn lock table scheduler
Enforcing Conflict-Serializability Using locking protocol T1 T2 Tn lock table scheduler Two new actions: lock: (transaction Ti exclusively locks the element A) unlock: (transaction Ti releases the lock on the element A) li(A) ui(A)
Enforcing Conflict-Serializability Using locking protocol T1 T2 Tn lock table scheduler Two new actions: lock: (transaction Ti exclusively locks the element A) unlock: (transaction Ti releases the lock on the element A) li(A) ui(A) A transaction can lock an unlocked element, and must release (unlock) it later. A transaction cannot access a locked element until it is released by the transaction holding the lock.
A transaction can lock an unlocked element, and must release (unlock) it later. A transaction cannot access a locked element until it is released by the transaction holding the lock. Locking is not enough for conflict-serializability Schedule D A B 25 25 T1 T2 Read(A); A A+100 Write(A); Read(B); B B+100; Write(B); Read(A); A A 2; Write(A); Read(B); B B 2; Write(B); 125 250 50 150 250 150
A transaction can lock an unlocked element, and must release (unlock) it later. A transaction cannot access a locked element until it is released by the transaction holding the lock. Locking is not enough for conflict-serializability Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l1(B); Read(B); B B+100; Write(B); u1(B); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); 125 250 50 150 250 150
A transaction can lock an unlocked element, and must release (unlock) it later. A transaction cannot access a locked element until it is released by the transaction holding the lock. Locking is not enough for conflict-serializability Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l1(B); Read(B); B B+100; Write(B); u1(B); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); 125 Inconsistent, so isolation was destroyed 250 50 150 250 150
Two phase locking (2PL) (for transactions) Ti: ... li(A) li(B) ui(B) ui(A) ... no unlocks no locks In a transaction, all lockings precede all unlockings
Two phase locking (2PL) (for transactions) Ti: ... li(A) li(B) ui(B) ui(A) ... no unlocks no locks # of locks held by Ti time growing phase shrinking phase In a transaction, all lockings precede all unlockings
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); 125 250 50 l1(B); Read(B); B B+100; Write(B); u1(B); 150 250 150
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); 125 250 50 l1(B); Read(B); B B+100; Write(B); u1(B); 150 250 150 not conflict-serializable even with locks
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); l1(B); Read(B); B B+100; Write(B); u1(B); Try to apply 2PL On the transactions
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); l1(B); Read(B); B B+100; Write(B); u1(B); Try to apply 2PL On the transactions
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); l1(B); Read(B); B B+100; u1(A); Write(B); u1(B); Try to apply 2PL On the transactions
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); u2(A); l1(B); Read(B); B B+100; u1(A); Write(B); u1(B); Try to apply 2PL On the transactions
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); u2(A); 125 l1(B); Read(B); B B+100; u1(A); Write(B); u1(B);
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); u2(A); blocked, so delayed 125 l1(B); Read(B); B B+100; u1(A); Write(B); u1(B);
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l1(B); Read(B); B B+100; u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); u2(A); blocked, so delayed 125 Write(B); u1(B);
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l1(B); Read(B); B B+100; u1(A); l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); u2(A); blocked, so delayed 125 Write(B); u1(B);
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l1(B); Read(B); B B+100; u1(A); 125 l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); u2(A); Write(B); u1(B);
2PL enforces conflict-serializability In a transaction, all lockings precede all unlockings Schedule D A B 25 25 T1 T2 l1(A); Read(A); A A+100 Write(A); u1(A); l1(B); Read(B); B B+100; u1(A); 125 l2(A); Read(A); A A 2; Write(A); u2(A); l2(B); Read(B); B B 2; Write(B); u2(B); u2(A); 250 Write(B); u1(B);