Conflict serializability in DBMS Theory - Time & Space Complexity
When checking if a schedule of database transactions is conflict serializable, we want to know how hard it is to analyze the schedule as it grows.
We ask: How does the effort to verify conflict serializability increase as the number of operations grows?
Analyze the time complexity of checking conflict serializability for a schedule.
-- Given a schedule with n operations
-- Steps to check conflict serializability:
-- 1. Identify conflicting operation pairs
-- 2. Build a precedence graph
-- 3. Check the graph for cycles
-- Pseudocode outline:
FOR each pair of operations (i, j) in schedule
IF operations conflict AND i precedes j THEN
Add edge i -> j in graph
END FOR
Check graph for cycles
This code builds a graph from conflicting operations and checks if the graph has cycles to decide conflict serializability.
Look for repeated steps that take most time.
- Primary operation: Comparing every pair of operations to find conflicts.
- How many times: For n operations, pairs are about n x n, so roughly n² times.
As the number of operations grows, the number of pairs to check grows much faster.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 100 |
| 100 | 10,000 |
| 1000 | 1,000,000 |
Pattern observation: Doubling the number of operations roughly quadruples the work needed.
Time Complexity: O(n2)
This means the checking effort grows roughly with the square of the number of operations in the schedule.
[X] Wrong: "Checking conflict serializability only needs to look at each operation once."
[OK] Correct: Because conflicts depend on pairs of operations, you must compare many pairs, not just single operations.
Understanding how conflict serializability checking scales helps you reason about database concurrency and correctness in real systems.
What if we only checked conflicts between operations on the same data item? How would the time complexity change?
Practice
conflict serializability ensure in database transactions?Solution
Step 1: Understand the goal of conflict serializability
It aims to keep the database consistent by ensuring concurrent transactions behave like they ran sequentially.Step 2: Compare options with the definition
Only Transactions produce the same result as if they were executed one after another correctly states that the final result is as if transactions ran one after another.Final Answer:
Transactions produce the same result as if they were executed one after another -> Option AQuick Check:
Conflict serializability = Sequential result [OK]
- Confusing conflict serializability with locking all data
- Thinking it speeds up transactions by skipping steps
- Assuming only one user can run transactions at a time
Solution
Step 1: Recall the method to test conflict serializability
It involves creating a precedence graph where nodes are transactions and edges show conflicts.Step 2: Understand the graph's role
If the graph has no cycles, the schedule is conflict serializable.Final Answer:
Build a precedence graph and check for cycles -> Option AQuick Check:
Precedence graph + no cycles = conflict serializable [OK]
- Thinking counting transactions shows serializability
- Confusing isolation levels with conflict serializability
- Assuming locking all data guarantees serializability
T1: Read(A), Write(A)T2: Read(A), Write(A)Which schedule is conflict serializable?
Solution
Step 1: Analyze schedules for conflicts
Schedules where one transaction runs fully before the other have no conflicts and are serializable.Step 2: Check interleaved schedule
Interleaving reads and writes on the same data causes conflicts and cycles in the precedence graph.Final Answer:
T1 followed by T2 -> Option DQuick Check:
Non-interleaved = serializable [OK]
- Assuming interleaved schedules are always serializable
- Ignoring write-write conflicts on same data
- Thinking any order of reads is conflict free
T1: Read(X), Write(X)T2: Read(X), Write(X)The schedule is:
Read(X) by T1, Read(X) by T2, Write(X) by T2, Write(X) by T1.
What is the problem with this schedule?
Solution
Step 1: Build the precedence graph
T1 reads X before T2 writes X, so edge T1 -> T2; T2 writes X before T1 writes X, so edge T2 -> T1.Step 2: Detect cycle in graph
Edges T1 -> T2 and T2 -> T1 form a cycle, meaning schedule is not conflict serializable.Final Answer:
It is not conflict serializable due to a cycle in the precedence graph -> Option CQuick Check:
Cycle in graph = not conflict serializable [OK]
- Confusing deadlock with conflict serializability
- Assuming reads before writes always mean serializable
- Thinking schedule is serial when it is interleaved
T1: Read(A), Write(A)T2: Read(B), Write(B)T3: Read(A), Write(B)If the schedule is:
Read(A) by T1, Read(B) by T2, Read(A) by T3, Write(A) by T1, Write(B) by T3, Write(B) by T2,
Is this schedule conflict serializable? If yes, what is a possible serial order?
Solution
Step 1: Identify conflicts and build precedence graph
T3 reads A before T1 writes A -> T3 -> T1.
T2 reads B before T3 writes B -> T2 -> T3.
T3 writes B before T2 writes B -> T3 -> T2.Step 2: Check for cycles and find serial order
Cycle T2 -> T3 -> T2 exists, so the schedule is not conflict serializable.Final Answer:
No, schedule is not conflict serializable due to cycles -> Option BQuick Check:
Precedence graph has cycle = not serializable [OK]
- Missing edges like T2 read B before T3 write B
- Missing edges in the precedence graph
- Confusing read-write order causing edges
Ready to prove it?
Pass the test and this pattern moves unknown
