Neural Sync Active
27 - Serializability
Registry Synced
27 - Serializability
651 words
3 min read
Reading compass
Now · 🎯 Learning Objectives
27 - Serializability
🎯 Learning Objectives
After reading this topic, you will be able to:
- Determine if two operations conflict
- Build a precedence graph and test conflict serializability
- Distinguish conflict from view serializability
- Understand recoverability and cascadeless schedules
📖 Core Content
27.1 Conflict Serializability
Conflicting Operations
Two operations conflict if:
- They belong to different transactions
- They operate on the same data item
- At least one is a write
| T1 | T2 | Conflict? |
|---|---|---|
| read(A) | read(A) | No (both read) |
| read(A) | write(A) | Yes (write-read) |
| write(A) | read(A) | Yes (read-write) |
| write(A) | write(A) | Yes (write-write) |
Precedence Graph
- Create a node for each transaction
- Add edge Ti→Tj if an operation in Ti conflicts with and precedes an operation in Tj
- If the graph has a cycle, the schedule is NOT conflict serializable
- If acyclic, conflict serializable (any topological ordering gives an equivalent serial schedule)
27.2 Worked Example
Schedule: r1(A),w1(A),r2(A),w2(A),r1(B),w1(B),r2(B),w2(B)
Conflicts:
- w1(A)→r2(A): T1→T2
- w1(A)→w2(A): T1→T2
- r2(A)→w1(B)? No (different data)
- w2(A)→w1(B)? No
- w1(B)→r2(B): T1→T2 Graph: T1→T2 (no cycle). Schedule is conflict serializable (equivalent to T1 then T2).
27.3 View Serializability
Two schedules S1 and S2 are view equivalent if:
- Same initial reads: Each data item's first read is from the same transaction
- Same final writes: Each data item's last write is by the same transaction
- Same reads from writes: If Tj reads a value written by Ti in S1, the same holds in S2 View serializability: A schedule is view serializable if it's view equivalent to some serial schedule. Key fact: Every conflict serializable schedule is view serializable, but NOT vice versa. View serializable schedules that aren't conflict serializable involve blind writes (write without prior read).
27.4 Recoverability
| Schedule Type | Definition | Preferred? |
|---|---|---|
| Recoverable | If Tj reads from Ti, Tj commits after Ti commits | Required |
| Cascadeless | Tj reads from Ti only after Ti commits | Preferred |
| Strict | Tj reads/writes data only after Ti (which wrote it) commits | Ideal |
Cascading rollback: When one transaction's abort causes a chain of aborts.
Example of non-recoverable:
- T1: write(A), T2: read(A), T2: commit, T1: abort
- T2 read uncommitted data from T1, then committed, then T1 aborted → T2's read is now invalid! This database is inconsistent.
📐 Key Formula
| Concept | Test |
|---|---|
| Conflict serializable | Precedence graph is acyclic |
| View serializable | No blind writes? Check initial/final reads/writes |
| Recoverable | If Ti reads from Tj, Ti commits after Tj |
⚠️ Common Pitfall
The Mistake: Thinking reads never conflict.
Why: Two reads don't conflict, but a read conflicts with a write (write-read conflict). R-W conflicts matter for serializability.
📝 Practice Questions
Q1. What makes two operations conflict?
AnswerThree conditions: (1) different transactions, (2) same data item, (3) at least one is a write.
Q2. Draw the precedence graph for: r1(A), w2(A), w1(A), r2(A)
AnswerConflicts:
- r1(A) → w2(A): T1→T2 (read-write)
- w2(A) → w1(A): T2→T1 (write-write)
- w2(A) → r2(A): Same transaction, ignore
- w1(A) → r2(A): T1→T2 (write-read)
Edges: T1→T2, T2→T1. This is a CYCLE! Schedule is NOT conflict serializable.
Q3. What's the difference between recoverable and cascadeless schedules?
Answer
- Recoverable: If Ti reads from Tj, Ti commits after Tj. No dirty reads from uncommitted transactions.
- Cascadeless: Ti reads from Tj only AFTER Tj commits. Prevents cascading rollbacks entirely.
Q4. Find the number of possible concurrent schedules for T1(2 ops), T2(2 ops), T3(1 op).
AnswerTotal operations = 5. Number of schedules = 2!2!1!5!=4120=30. (All permutations divided by internal order within each transaction.)
🔗 Cross-References
- Next Topic: 28 - Concurrency Control
- Previous Topic: 26 - Transactions & ACID
- Related: 28 - Concurrency Control (protocols to ensure serializability)
- Textbook: Chapter 14 (Transactions), Chapter 15 (Concurrency Control) Join Discord Previous26 - Transactions & ACIDNext28 - Concurrency Control