Skip to content
GATEiit

GATE CSE · Databases

Transactions and concurrency control

ACID properties, schedules, conflict and view serializability, recoverable, cascadeless and strict schedules, two-phase locking, deadlock handling and timestamp ordering, with the schedule tests GATE asks.

Before you start

Concept notes

1. Transactions and ACID

A transaction is a unit of work that reads and writes data items, ending in commit or abort. Its states are active → partially committed → committed, or active → failed → aborted.

Property Meaning Ensured by
Atomicity All of the transaction happens or none of it Recovery manager (undo using the log)
Consistency A correct transaction takes the database from one consistent state to another Programmer, plus integrity constraints
Isolation Concurrent execution has the effect of some serial execution Concurrency control manager
Durability Committed changes survive crashes Recovery manager (redo using the log)

Running transactions concurrently improves throughput and response time, but uncontrolled interleaving causes anomalies:

  • Lost update: two transactions read X, both write it; one write is overwritten.
  • Dirty read (write–read conflict): reading a value written by a transaction that later aborts.
  • Unrepeatable read (read–write conflict): a transaction reads X twice and sees different values because another transaction wrote X in between.

Notation: ri(X) and wi(X) are a read and a write of X by Ti; ci and ai are its commit and abort.

2. Conflict serializability

A schedule interleaves the operations of several transactions, keeping each transaction's own order. It is serial if transactions run one after another.

Two operations conflict if they belong to different transactions, touch the same item, and at least one is a write: r–w, w–r or w–w. Swapping adjacent non-conflicting operations does not change the result.

A schedule is conflict serializable (CS) if it can be turned into a serial schedule by such swaps.

Precedence graph test:

  1. One node per transaction.
  2. Edge Ti→Tj if an operation of Ti conflicts with a later operation of Tj.
  3. The schedule is CS if and only if the graph has no cycle.

Every topological order of an acyclic precedence graph is a conflict-equivalent serial schedule, so "how many serial schedules is S conflict equivalent to?" means "count the topological sorts".

Scan each data item separately and list its operations in order; that makes the edges hard to miss.

Precedence graphr2(X) before w1(X)w2(Y) before r3(Y)w1(X) before w3(X)T2T1T3Acyclic: the only topological order is T2, T1, T3
Precedence graph of r2(X) r1(X) w2(Y) w1(X) r3(Y) w3(X). Each edge is labelled with one conflict that creates it.

3. View serializability

Two schedules S and S′ on the same transactions are view equivalent if:

  1. Initial reads: if Ti reads the initial value of X in S, it does so in S′.
  2. Reads-from: if Ti reads the value of X written by Tj in S, it does so in S′.
  3. Final writes: the transaction that writes X last in S also writes it last in S′.

S is view serializable (VS) if it is view equivalent to some serial schedule.

  • Every CS schedule is VS, but not conversely.
  • A VS schedule that is not CS always contains a blind write (a write of X without a preceding read of X in that transaction).
  • Testing VS is NP-complete in general, so it is not used to control execution; for GATE, check the three conditions against each candidate serial order.

Quick route for a question: run the precedence graph test first. If acyclic, the schedule is CS and hence VS. If cyclic and there is no blind write, it is not VS either. Only a cyclic schedule with blind writes needs the full view check.

4. Recoverable, cascadeless and strict schedules

Serializability is about correctness without failures; recoverability is about aborts.

Class Condition Prevents
Recoverable If Tj reads a value written by Ti, then Ti commits before Tj commits A committed transaction that has read data from an aborted one
Cascadeless (ACA) Transactions read only values written by committed transactions Cascading rollback
Strict No transaction reads or writes X until the last writer of X has committed or aborted Undo becomes simply restoring the before-image

Containment: strict ⊂ cascadeless ⊂ recoverable ⊂ all schedules. These classes cut across serializability: a schedule can be serializable but not recoverable, or strict but not serializable.

How to classify: find every reads-from pair (wi(X) followed later by rj(X) with no write in between).

  • If cj comes before ci (or Tj commits and Ti aborts), it is not recoverable.
  • If the read happens before ci, it is not cascadeless.
  • If some wj(X) happens after an uncommitted wi(X), it is not strict.

5. Lock-based protocols and deadlock handling

Locks: a shared (S) lock allows reading; an exclusive (X) lock allows reading and writing. S is compatible only with S; X is compatible with nothing.

Two-phase locking (2PL): each transaction has a growing phase (acquires locks, releases none) and then a shrinking phase (releases locks, acquires none). The point of the last lock acquired is the lock point; ordering transactions by lock point gives an equivalent serial order.

Variant Extra rule Guarantees
Basic 2PL None Conflict serializable; not deadlock-free; cascading rollback possible
Strict 2PL Hold X locks until commit/abort CS and strict (so cascadeless)
Rigorous 2PL Hold all locks until commit/abort CS, strict; serial order = commit order
Conservative 2PL Lock everything needed before starting Deadlock-free

Deadlock prevention with timestamps (older = smaller timestamp). When Ti requests a lock held by Tj:

  • Wait-die (non-preemptive): if Ti is older it waits; otherwise Ti dies (rolls back).
  • Wound-wait (preemptive): if Ti is older it wounds (aborts) Tj; otherwise Ti waits.

In both, a restarted transaction keeps its original timestamp, so it eventually becomes the oldest and cannot starve. Deadlocks can also be detected with a wait-for graph (a cycle means deadlock) and broken by aborting a victim.

6. Timestamp ordering

Each transaction gets a unique timestamp TS(T) when it starts; the protocol forces the serial order to be timestamp order. Each item keeps RTS(X) and WTS(X), the largest timestamps that read and wrote it.

Basic timestamp ordering:

  • T issues read(X): if TS(T)<WTS(X), abort T (it would read a value from its future). Else read and set RTS(X)=max⁡(RTS(X),TS(T)).
  • T issues write(X): if TS(T)<RTS(X) or TS(T)<WTS(X), abort T. Else write and set WTS(X)=TS(T).

An aborted transaction restarts with a new timestamp.

Thomas write rule: in the write case, if TS(T)≥RTS(X) but TS(T)<WTS(X), the write is obsolete: ignore it instead of aborting. This admits some view-serializable schedules that are not conflict serializable.

Properties: timestamp ordering is conflict serializable (basic) and deadlock-free, because no transaction ever waits. It can starve a long transaction that keeps restarting, and without extra rules its schedules need not be recoverable.

Formulas to remember

Conflict condition
different T, same item, at least one write
Conflict serializability test
S is CS  ⟺  precedence graph is acyclic
Schedule class containmentSeparately: strict ⊂ cascadeless ⊂ recoverable
Serial⊂CS⊂VS
Interleavings of two transactionsm and n operations; each keeps its own order
(m+nm)=(m+n)!m! n!
Basic TO write rule
TS(T)<RTS(X) or TS(T)<WTS(X)⇒abort T

Common mistakes

  • Adding an edge for two reads of the same item: read–read is never a conflict.
  • Drawing edges between operations of the same transaction.
  • Concluding a cyclic schedule is not view serializable without checking for blind writes.
  • Mixing up wait-die (older waits) and wound-wait (older wounds younger).
  • Assuming 2PL avoids deadlock or cascading rollback; only conservative 2PL avoids deadlock and only strict or rigorous 2PL avoids cascades.
  • Calling a schedule recoverable just because it is serializable; recoverability depends on commit order.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Precedence graph and equivalent serial order

numerical

Is S: r2(X) r1(X) w2(Y) w1(X) r3(Y) w3(X) conflict serializable? If so, give the equivalent serial order.

  1. Step 1: List the operations on X in order.

    Try it on paper first.

Example 2: Counting conflict-serializable interleavings

numerical

T1: r1(A) w1(A) r1(B) w1(B) and T2: r2(A) w2(A). How many interleavings are there, and how many are conflict serializable?

  1. Step 1: Count all interleavings.

    Try it on paper first.

Example 3: Classifying a schedule for recoverability

conceptual

Classify S1: w1(A) r2(A) w2(B) c2 c1 and S2: w1(A) r2(A) w2(B) c1 c2 as non-recoverable, recoverable, cascadeless or strict.

  1. Step 1: Find the reads-from pairs.

    Try it on paper first.

Example 4: View serializable but not conflict serializable

conceptual

Show that S: r1(A) w2(A) w1(A) w3(A) is view serializable but not conflict serializable.

  1. Step 1: Draw the precedence graph.

    Try it on paper first.

Previous year questions

15 official GATE CSE questions on this topic, newest first.

Practise these 15 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.