T10.1: Conflicting Instructions and Conflict Serializability
Topic: T10: Serializability | Priority: 🟢 Foundational Priority | Exam Frequency: 1/7 finals (2 marks: 2017 Q.5(b), plus part of 2021 Q.7(b)) Sources: Silberschatz 7e Ch. 17 (§17.6, pp. 813–816) · Lecture Deck 07 (Slides 16–19) · Classnote by Raidah (T10, p. 26)
Why This Topic Matters
Serial schedules run transactions one at a time and are naturally safe, whereas concurrent schedules interleave instructions to boost speed. How can the DBMS quickly tell if an interleaved schedule is safe? Instead of trying to understand the complex business math inside every transaction, the database looks only at read and write operations and checks whether any pair of steps conflict. Conflict serializability is the foundation for every precedence-graph problem you will solve in Unit 6.
📝 Key Definitions
Conflicting Instructions: Two instructions Ii and Ij conflict if they belong to different transactions (Ti=Tj) and access the same data item Q with at least one write(Q) operation. The three conflicting pairs are read-write, write-read, and write-write on the same item Q. Two read(Q) operations or operations on different data items never conflict.
Conflict Equivalent: Two schedules S and S′ over the same set of transactions are conflict equivalent if S can be transformed into S′ by a sequence of swaps of adjacent non-conflicting instructions. Both schedules preserve the exact relative order of every conflicting pair of operations.
Conflict Serializable: A concurrent schedule S is conflict serializable if it is conflict equivalent to at least one serial schedule. You can verify conflict serializability by checking that the precedence graph of S has no directed cycles.
1. When Do Two Instructions Conflict?
Intuitive Analogy: Looking at a Whiteboard vs. Erasing It
Imagine two students, T1 and T2, working with a number written on a classroom whiteboard (Q):
If T1 looks at the board and then T2 looks at the board (read / read), does it matter who looked first? Not at all! Both see the exact same number, and the board does not change.
Now suppose T1 looks at the board and T2 erases it to write a new number (read / write). Here, the order changes everything! If T1 looks first, T1 sees the old number. If T2 writes first, T1 sees the new number.
Similarly, if both students erase the board and write their own numbers (write / write), whoever writes second leaves the final number on the board.
That is the entire secret of conflicting instructions: order only matters when two different transactions touch the exact same data item and at least one of them writes to it.
The Three Requirements for a Conflict
Two instructions Ii and Ij conflict if and only if they meet all three conditions at once:
Different Transactions:Ii belongs to transaction Ti and Ij belongs to a different transaction Tj (i=j).
Same Data Item: Both instructions access the exact same database item Q.
At Least One Write: At least one of the two instructions is a write(Q) operation.
Here are the four possible combinations of read and write on the same item Q:
Case
Instruction Ii (Ti)
Instruction Ij (Tj)
Conflict?
Why Order Matters (or Doesn't)
1
read(Q)
read(Q)
No
Neither transaction changes Q. Swapping their order does not change what either transaction reads.
2
read(Q)
write(Q)
Yes (RW)
If Ti reads first, it sees the old value of Q. If Tj writes first, Ti sees the new value written by Tj.
3
write(Q)
read(Q)
Yes (WR)
If Ti writes first, Tj reads the updated value. If Tj reads first, Tj gets the old value.
4
write(Q)
write(Q)
Yes (WW)
Both overwrite Q. Whichever transaction writes second determines the value left in the database.
Two Golden Rules to Remember
Different Data Items Never Conflict: If Ii touches item A and Ij touches item B (A=B), they never conflict, even if both are writes. Updating account A and updating account B are completely independent actions, so you can swap their order without changing anything.
Never Swap Inside the Same Transaction: Instructions that belong to the same transaction (Ti=Tj) are locked in their program order. A transaction obviously cannot write its result before reading its input!
2. Conflict Equivalence and Conflict Serializability
When two adjacent instructions from different transactions do not conflict, swapping their order leaves the outcome of the schedule 100% unchanged: every transaction still reads the exact same inputs, and the database still ends up with the exact same final values.
Conflict Equivalence: Two schedules S and S′ are conflict equivalent if you can turn S into S′ by repeatedly swapping adjacent non-conflicting instructions.
Conflict Serializability: A concurrent schedule S is conflict serializable if it is conflict equivalent to some serial schedule.
Illustrative Mini-Example: Spotting Conflicts in a 4-Step Schedule
Consider this short schedule S over transactions T1 and T2:
Look at S′ now: all of T1's steps run first, followed by all of T2's steps! Because one valid swap turned S into the serial schedule ⟨T1,T2⟩, schedule S is conflict serializable.
Notice why we could not swap T1:read(A) past T2:write(A): both touch A and one is a write (an RW conflict), so T1 must stay ahead of T2.
3. Testing Conflict Serializability: The Precedence Graph
Swapping instructions by hand gets messy when a schedule has 15 or 20 steps. Instead, we use a precedence graph (also called a serialization graph) to spot conflicts visually.
Intuitive Meaning of a Precedence Graph Edge
Every conflicting pair of instructions acts like a one-way street sign between two transactions. If T1 reads A before T2 writes A, we cannot swap those two steps, so T1must come before T2 in any equivalent serial schedule. We record that rule by drawing an arrow T1⟶T2.
Graph Construction Rules
For a schedule S, we build a directed graph G=(V,E):
Vertices (V): Draw one node (circle) for each transaction Ti in the schedule.
Directed Edges (E): Draw a directed arrow Ti⟶Tj (i=j) whenever an operation in Ti runs before a conflicting operation in Tj on the same item Q:
WR conflict:Ti executes write(Q) before Tj executes read(Q).
RW conflict:Ti executes read(Q) before Tj executes write(Q).
WW conflict:Ti executes write(Q) before Tj executes write(Q).
The Conflict Serializability Theorem
Conflict Serializability Theorem:
A schedule S is conflict serializable if and only if its precedence graph G has no directed cycles (meaning G is a Directed Acyclic Graph, or DAG).
If there is a cycle (like T1→T2→T1), T1 would have to run both before and after T2, which is impossible in a serial schedule! Thus, a cycle proves the schedule is not conflict serializable.
If there are no cycles, we can read off the equivalent serial order using topological sorting (starting with transactions that have no incoming arrows).
4. Conflict Serializability vs. View Serializability
Conflict serializability is slightly stricter than view serializability:
Every conflict serializable schedule is automatically view serializable (and therefore preserves consistency).
A schedule can be view serializable without being conflict serializable only if it contains blind writes (where a transaction writes a value without reading it first).
Real database engines use conflict serializability because checking a precedence graph for cycles takes fast polynomial time O(V+E), whereas testing view serializability is an NP-complete problem.
Exam Variants
Year & Question
Marks
Format
Key Requirements
2017 Q.5(b)
2
Direct theory question
Define conflict serializability, list the 4 read/write cases, and mention the precedence graph test
2021 Q.7(b)
4
Theory + graph drill
Define conflict serializability (part 1), then test a 3-transaction schedule using a precedence graph (part 2)
Conflict serializability is the primary standard used by database systems to verify whether a concurrent schedule is safe. A schedule S is conflict serializable if it is conflict equivalent to a serial schedule, meaning that S can be transformed into a serial schedule by a series of swaps of adjacent non-conflicting instructions.
1. Rules for Conflicting Instructions
Two instructions Ii and Ij from different transactions (Ti=Tj) conflict if and only if they access the same data item Q and at least one of them is a write operation:
Ii=read(Q) and Ij=read(Q): Do not conflict (two reads do not modify data, so their order does not matter).
Ii=read(Q) and Ij=write(Q): Conflict (swapping them changes whether Ti reads the old or new value).
Ii=write(Q) and Ij=read(Q): Conflict (swapping them changes the value read by Tj).
Ii=write(Q) and Ij=write(Q): Conflict (swapping them changes which write stays in the database last).
(Note: Operations on different data items, such as A=B, never conflict).
2. Testing via Precedence Graph
A schedule S is conflict serializable if and only if its precedence graph (where nodes are transactions and directed edges Ti→Tj represent conflicts where Ti acts before Tj) contains no directed cycles. If the graph is acyclic, a topological sort yields the equivalent serial order.
📖 High-Yield Exercises from the Book
🎯 HYE-01 · Practice Exercise 17.5 · Why Engines Prioritize Conflict Over View Serializability
Source: Silberschatz 7e · Chapter 17 (Practice Exercise 17.5) Exam Relevance: High-Probability Section B Theory Question Key Tested Concept: Computational complexity of cycle detection vs. NP-completeness of view serializability; protocol realizability in runtime concurrency control.
Problem Statement:
Since every conflict-serializable schedule is view serializable, why do database-system designers emphasize conflict serializability rather than view serializability? Explain the algorithmic complexity and concurrency-control protocol implications of this choice.
Model Exam-Style Solution:
Although view serializability is a mathematically broader criterion (every conflict-serializable schedule is view serializable, but some view-serializable schedules containing blind writes are not conflict serializable), commercial database systems enforce conflict serializability for two decisive architectural reasons:
Computational Complexity of Testing:
Conflict Serializability: Can be tested in polynomial timeO(V+E) (linear in the size of the graph) by constructing a precedence graph G=(V,E) and testing for directed cycles using depth-first search (DFS) or topological sorting.
View Serializability: Deciding whether an arbitrary schedule is view serializable is an NP-complete problem. For n concurrent transactions, an exhaustive search would require testing view equivalence against n! possible serial schedules, which is computationally intractable for runtime scheduling in high-throughput database systems.
Protocol Enforceability (Concurrency Control Mechanisms):
Practical concurrency-control protocols (such as Two-Phase Locking (2PL) and Timestamp Ordering (TSO)) operate on local, pair-wise instruction conflicts as transactions execute concurrently.
These protocols naturally and efficiently produce conflict-serializable executions without needing to predict future reads or final writes across the entire schedule.
No efficient, general-purpose online concurrency-control protocol exists that can dynamically recognize and allow all view-serializable schedules that are not conflict-serializable (with the exception of specialized heuristics such as Thomas' Write Rule for blind writes).
💡 RUET Exam Takeaway:
In semester exams, highlight the two-pronged argument: O(V+E) polynomial cycle check vs. NP-complete search, and local conflict locking (2PL) vs. impossible runtime omniscience.
⚡ Exam Tips & Common Mistakes
Two Reads Never Conflict: Writing that read(Q) and read(Q) conflict is the single most common error on this question. Remember the whiteboard rule: two people looking at a number never change it.
Check the Variable Name First: Before checking read vs. write, check whether the two steps touch the same variable. write(A) and write(B) do not conflict because A=B.
Same Transaction = No Conflict Edge: You only check conflicts between different transactions (Ti=Tj). Never draw a self-loop T1→T1 in a precedence graph.
Checklist for 2 Marks: Define conflict equivalence + conflict serializability, list the 4 read/write cases on item Q, and state that the precedence graph must be acyclic.
🔗 Related Topics
T09.05: Concurrency Anomalies: How RW, WR, and WW conflicts produce dirty reads, unrepeatable reads, and lost updates.