Is S: R1(A) R2(B) W1(A) R3(A) W2(B) R3(B) conflict serializable? If so, give every equivalent serial order.
A transaction is a logical unit of work that must be atomic, consistent, isolated and durable (ACID). Schedules interleave transactions; conflict and view serializability decide which interleavings are correct, and recoverability decides which survive aborts.
A transaction is a unit of program execution that accesses and possibly updates data items and must be treated as indivisible. For theory we model it as a sequence of read(X) and write(X) operations on data items, ending with commit (make the changes permanent) or abort (undo them). In SQL a transaction starts implicitly with the first statement (or explicitly with BEGIN / START TRANSACTION) and ends with COMMIT or ROLLBACK.
T1: read(A) -- A = 2000
A := A - 500
write(A) -- A = 1500
read(B) -- B = 1000
B := B + 500
write(B) -- B = 1500
commitBEGIN TRANSACTION;
UPDATE account SET balance = balance - 500 WHERE acc_no = 'A';
UPDATE account SET balance = balance + 500 WHERE acc_no = 'B';
COMMIT; -- or ROLLBACK; to undo both updates
-- Most clients run in AUTOCOMMIT mode: without BEGIN, each statement is its own transaction.
-- SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; and SET TRANSACTION READ ONLY; tune its behaviour.Two things threaten this simple program. Failures — a crash, a power cut, an error — can stop it halfway, after the debit but before the credit. Concurrency — other transactions running at the same time for throughput and response time — can interleave their reads and writes with T1's. The DBMS's transaction manager exists to make both threats invisible, and the ACID properties say exactly what that means.
| Property | Meaning | In the transfer | Ensured by |
|---|---|---|---|
| Atomicity | All operations happen, or none do | A crash after write(A) must not leave A debited and B uncredited — the debit is undone | Recovery manager (log-based undo) |
| Consistency | A transaction takes the database from one consistent state to another | A + B = 3000 before and after; balances never negative | Application programmer + integrity constraints |
| Isolation | Concurrent execution has the same effect as some serial execution; intermediate states are invisible | A report computing A + B in the middle of the transfer must not see 2500 | Concurrency-control manager (locks, timestamps) |
| Durability | Once committed, changes survive any later failure | After 'transfer successful', a crash must not lose the transfer | Recovery manager (log forced at commit, redo) |
Consistency is the odd one out: the DBMS checks declared constraints, but only the programmer can guarantee that the transaction's logic is correct (a transfer that debits 500 but credits 50 breaks consistency without violating any constraint). Atomicity plus isolation plus correct individual transactions together give consistency of the whole system.
A committed transaction's effects can be reversed only by running another, compensating transaction (for example a reverse transfer) — the system never 'un-commits'. Observable external writes, such as dispensing cash at an ATM, are therefore delayed until the transaction commits.
A schedule (history) is a sequence of operations from a set of transactions that keeps the order of operations within each transaction. In a serial schedule the transactions run one after another with no interleaving; in a concurrent (non-serial) schedule their operations are interleaved. Serial schedules are always correct (each transaction is correct on its own) but waste the CPU while one transaction waits for disk; concurrency improves throughput and response time.
Not every concurrent schedule is acceptable. The goal of concurrency control is to allow only schedules equivalent to some serial schedule — serializable schedules. The two standard notions of 'equivalent' are conflict equivalence and view equivalence.
Two operations conflict if they belong to different transactions, access the same data item, and at least one is a write. So R1(A)–W2(A), W1(A)–R2(A) and W1(A)–W2(A) conflict; R1(A)–R2(A) and W1(A)–W2(B) do not. Swapping two adjacent non-conflicting operations never changes the result; schedules that can be turned into each other by such swaps are conflict equivalent, and a schedule conflict-equivalent to a serial one is conflict serializable.
In practice a DBMS does not build schedules and then test them — by the time a cycle appeared, the transactions would already have run. Instead, a concurrency-control protocol (two-phase locking, timestamp ordering, validation) is designed so that every schedule it allows is guaranteed to be serializable. The precedence graph is the tool for proving such protocols correct and for answering exam questions.
Two schedules are view equivalent if (1) each transaction reads the initial value of every item in both or in neither, (2) each read reads the value written by the same transaction in both (the same reads-from relation), and (3) the final write of every item is by the same transaction in both. A schedule view-equivalent to a serial schedule is view serializable.
Every conflict-serializable schedule is view serializable, but not conversely; the extra view-serializable schedules always contain blind writes. Testing view serializability is NP-complete, whereas the precedence-graph test is polynomial — which is why practical protocols aim for conflict serializability.
Serializability ignores failures. If T2 reads a value written by T1 and T1 later aborts, T2 has used data that never officially existed. Recoverability classes describe how badly a schedule behaves when that happens (Cᵢ = commit of Tᵢ).
| Class | Rule | Example | Verdict |
|---|---|---|---|
| Non-recoverable | A transaction commits before a transaction it read from | W1(A) R2(A) C2 C1 | If T1 aborts, committed T2 cannot be undone — forbidden |
| Recoverable | Tj commits only after every Ti it read from has committed | W1(A) R2(A) C1 C2 | Safe, but T1 aborting would force T2 to abort too |
| Cascadeless (ACA) | Transactions read only committed values | W1(A) C1 R2(A) C2 | No cascading rollback possible |
| Strict | No read or write of an item until the last writer has committed or aborted | W1(A) C1 W2(A) C2 | Undo can simply restore before-images |
A cascading rollback happens when one abort forces others: T1 writes A, T2 reads A, T3 reads T2's output, and then T1 aborts — T2 and T3 must abort as well. Cascadeless schedules prevent this; strict schedules additionally forbid overwriting uncommitted data (W1(A) W2(A) C1 C2 is cascadeless but not strict). Strict two-phase locking, covered in the next topic, produces strict schedules.
| Anomaly | Pattern | Example |
|---|---|---|
| Lost update | W–W: two transactions read the same value and both write, one overwriting the other | R1(A) R2(A) W1(A) W2(A): both read 2000, T1 writes 1500, T2 writes 2100 — T1's debit is lost |
| Dirty read (temporary update) | W–R: reading a value written by an uncommitted transaction | T1 writes A = 1500, T2 reads 1500, T1 aborts — T2 used a value that never existed |
| Unrepeatable read | R–W–R: a transaction reads an item twice and another committed transaction changed it in between | T1 reads Hari's salary 22000, T2 updates it to 24000 and commits, T1 reads 24000 |
| Phantom | A repeated query returns new rows inserted (or loses rows deleted) by another transaction | T1 counts Clerks (3), T2 inserts a Clerk and commits, T1 counts again (4) |
| Incorrect summary | An aggregate mixes values before and after another transaction's updates | A report sums all balances while a transfer is half done |
| Time | T1 (withdraw 500) | T2 (deposit 100) | A in the database |
|---|---|---|---|
| t1 | read(A) → 2000 | 2000 | |
| t2 | read(A) → 2000 | 2000 | |
| t3 | A := 2000 − 500; write(A) | 1500 | |
| t4 | A := 2000 + 100; write(A) | 2100 | |
| t5 | commit | commit | 2100 — should be 1600 |
The first three are row-level problems that locking individual items can prevent; phantoms concern sets of rows defined by a predicate, so preventing them needs predicate, index-range or table-level locking. SQL's isolation levels are defined precisely by which of dirty read, unrepeatable read and phantom they allow — see the concurrency-control topic.
Try the problem first, then reveal the working one step at a time.
Is S: R1(A) R2(B) W1(A) R3(A) W2(B) R3(B) conflict serializable? If so, give every equivalent serial order.
(a) T1 has 3 operations and T2 has 2. How many schedules are possible and how many are non-serial? (b) Three transactions with 2 operations each?
Classify: S1: W1(A) R2(A) C2 C1; S2: W1(A) R2(A) C1 C2; S3: W1(A) C1 R2(A) C2; S4: W1(A) W2(A) C1 C2.
Show that S: R1(A) W2(A) W1(A) W3(A) is view serializable but not conflict serializable.
Draw the precedence graph of S: R3(Y) R1(X) W1(X) R2(Y) W3(Y) R2(X) W2(X) and give the equivalent serial schedule, if any.
T1 has 4 operations and T2 has 3. How many schedules are possible? How many are serial?
Classify S: R1(A) W1(A) R2(A) W2(A) C2 C1 as non-recoverable, recoverable, cascadeless or strict, and explain what goes wrong if T1 aborts at the end.
Name the ACID property violated in each case: (a) after a crash, account A is debited but B is not credited; (b) A holds ₹2000 and B ₹1000, and a report shows A + B = 2500 during a transfer of ₹500 from A to B; (c) the customer was told 'transfer successful' but after a restart the transfer is gone; (d) a buggy transfer debits ₹500 and credits ₹50.
Identify the anomaly: T1 reads Indu's salary (20000) to compute a bonus, T2 raises it to 22000 and commits, T1 reads the salary again for a report and gets 22000.
12 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.