Sub topic 5
Conflicting Operations and Conflict Equivalence
Prerequisites
Assume you know basic relational database operations, such as reading and updating rows. You should also know that a transaction is a sequence of operations that should behave as one logical unit. A schedule is the order in which operations from one or more transactions execute.
This chapter uses the notation Ri(X) for “transaction Ti reads item X” and Wi(X) for “transaction Ti writes item X.”
When operations conflict
Two operations conflict when all three conditions hold:
- They belong to different transactions.
- They access the same data item.
- At least one operation is a write.
A read followed by another read does not conflict. Both transactions only observe the item, so their order does not affect the database result.
The three types of conflicts are:
| Conflict | Example | Why order matters |
|---|---|---|
| Read-write | `R1(X)` and `W2(X)` | T1 may read the old or new value |
| Write-read | `W1(X)` and `R2(X)` | T2 may read the value before or after T1's write |
| Write-write | `W1(X)` and `W2(X)` | The final value may depend on which write occurs last |
Operations on different items do not conflict, even when they belong to different transactions. For example, R1(A) and W2(B) can be swapped without changing either transaction's access to its item.
Conflict equivalence
Two schedules are conflict equivalent if they contain the same operations and preserve the order of every conflicting pair.
Consider these schedules:
S1: R1(X), W1(X), R2(X), W2(X)
S2: R1(X), R2(X), W1(X), W2(X)Both schedules contain the same four operations. However, they are not conflict equivalent. In S1, W1(X) occurs before R2(X). In S2, R2(X) occurs before W1(X). These operations conflict, so changing their order changes the relationship between the transactions.
Now consider:
S3: R1(A), R2(B), W1(A), W2(B)
S4: R2(B), R1(A), W2(B), W1(A)These schedules are conflict equivalent. The operations on A keep the same order relative to each other, and the operations on B also keep the same order. The operations involving different items can move around one another because they do not conflict.
A reliable checking method
To compare two schedules:
- List every operation in each schedule.
- Pair operations from different transactions.
- Keep only pairs that access the same item and include a write.
- Record the order of each remaining pair in both schedules.
- If any conflicting pair reverses order, the schedules are not conflict equivalent.
Conflict equivalence ignores the order of nonconflicting operations. This idea lets a database system reason about whether an interleaved execution preserves the important ordering constraints of another schedule.
> callout note > Do not call two operations conflicting merely because they access the same item. Two reads of the same item do not conflict. A write must be present.
Exercise
Are R1(X), R2(X), W1(X) and R2(X), R1(X), W1(X) conflict equivalent?
Show answer
No. R2(X) and W1(X) conflict. Their order is reversed between the schedules.