Introduction

A transaction is a unit of program execution that reads and possibly updates database items and must behave as one indivisible step: either all of its effects persist or none do, and other transactions see it as if it ran alone. A funds transfer that debits one account and credits another is the standard example: stopping half-way, or interleaving it carelessly with another transfer, leaves the database wrong.

The transaction model used by every later concurrency topic is the read and write operations, the ACID properties and the component of the system responsible for each, the transaction states, and the anomalies that uncontrolled interleaving causes. The same model is enough to tell which property or component is at fault in a scenario and which state transitions are possible.

Prerequisites

None within the GATE syllabus.

Core concepts

Operations. A transaction TiT_i accesses data items (a row, a block, a field) through:

  • Ri(X)R_i(X), read: copy item XX from the database (via the buffer) into a local variable;
  • Wi(X)W_i(X), write: copy a local value back to item XX in the buffer, from where it reaches disk later;
  • CiC_i commit and AiA_i abort.

Computation on local variables is invisible to the database; only reads and writes matter for correctness of interleavings.

The ACID properties and who enforces them:

PropertyMeaningEnsured by
Atomicityall operations of a transaction take effect, or none dorecovery system (undo using the log)
Consistencya transaction run alone takes a consistent database to a consistent onethe programmer, helped by integrity constraints
Isolationconcurrent execution has the effect of some serial executionconcurrency-control system
Durabilityeffects of a committed transaction survive later failuresrecovery system (redo using the log, stable storage)

Storage model. Atomicity and durability are defined against three kinds of storage. Volatile storage (main memory, the buffer) loses its contents in a system crash. Nonvolatile storage (disk, flash) survives a crash but can fail. Stable storage is an abstraction that never loses data, approximated by keeping several copies on independent nonvolatile devices. The log that recovery relies on must reach stable storage before a transaction is declared committed; this is why a write executed by Wi(X)W_i(X) is not yet durable when it is only in the buffer.

Transaction states (the five states of Korth, Silberschatz and Sudarshan):

State diagram of a transaction: active, partially committed, committed, failed and aborted, with the event that causes each transition.
Figure 1. Transaction states: active, partially committed, failed, aborted and committed; committed and aborted are the terminated states.

After an abort the system may restart the transaction (as a new transaction) if the failure was not caused by its own logic, or kill it. A committed transaction cannot be undone by aborting; its effects can only be reversed by a separate compensating transaction.

How it works: why concurrency needs control

Running transactions concurrently improves throughput (CPU and disk work overlap) and response time (short transactions need not wait behind long ones). Without control, interleaving produces these anomalies:

  • Lost update: two transactions read the same value and both write; the first write is overwritten.
  • Dirty read (temporary update): a transaction reads another transaction's still-uncommitted value, regardless of whether that writer later commits or aborts. A later abort makes the dependency especially harmful.
  • Incorrect summary (inconsistent analysis): an aggregate reads some items before and some after another transaction's updates.
  • Unrepeatable read: a transaction reads the same item twice and gets two different values because another transaction wrote it in between.

The rest of the concurrency notes define which interleavings are acceptable (Schedules and Serializability) and protocols that allow only those.

Mathematical explanation

A schedule is an interleaving of the operations of a set of transactions that keeps each transaction's own order. A serial schedule runs the transactions one after another; with nn transactions there are n!n! serial schedules. Isolation is formalised as serializability: the schedule must be equivalent to some serial schedule. Consistency of each transaction alone, plus serializability, gives a consistent final state, because a serial schedule is a sequence of consistency-preserving steps.

The number of all schedules grows quickly: transactions with n1,…,nkn_1, \ldots, n_k operations have (n1+⋯+nk)!n1!⋯nk!\frac{(n_1 + \cdots + n_k)!}{n_1! \cdots n_k!} interleavings. Two transactions of 3 operations each already have 2020 schedules, of which only 2 are serial.

Worked examples

Example 1: atomicity. T1T_1 transfers 100 from A=500A = 500 to B=300B = 300: R1(A)R_1(A), A:=A−100A := A - 100, W1(A)W_1(A), R1(B)R_1(B), B:=B+100B := B + 100, W1(B)W_1(B). If the system crashes after W1(A)W_1(A) reaches disk but before W1(B)W_1(B), the database shows A=400A = 400, B=300B = 300: the total drops from 800 to 700. Atomicity requires the recovery system to undo W1(A)W_1(A).

Example 2: lost update. X=100X = 100. T1T_1: X:=X−10X := X - 10; T2T_2: X:=X+20X := X + 20. The interleaving R1(X) R2(X) W1(X) W2(X)R_1(X)\, R_2(X)\, W_1(X)\, W_2(X) ends with X=120X = 120; both serial orders give 110110. The update of T1T_1 is lost. Of the 6 interleavings, the 2 serial ones give 110, the 2 in which T2T_2 writes last after both reads give 120, and the 2 in which T1T_1 writes last after both reads give 90 (the update of T2T_2 is lost).

Example 3: dirty read. X=100X = 100. T1T_1 executes W1(X)W_1(X) with value 90. T2T_2 executes R2(X)R_2(X) (reads 90), W2(X)W_2(X) with value 110, and commits. Then T1T_1 aborts. Undoing T1T_1 restores its before-image X=100X = 100, which also erases the write of the committed T2T_2; not undoing it leaves 110, a value computed from a write that officially never happened. Either way a committed transaction is wrong, so the schedule must be prevented (Recoverability calls it nonrecoverable).

Example 4: incorrect summary. A=50A = 50, B=50B = 50. T1T_1 moves 10 from AA to BB while T3T_3 sums the two. With R3(A)R_3(A) (reads 50) before T1T_1 runs and R3(B)R_3(B) (reads 60) after, T3T_3 reports 110110, but every consistent state has total 100.

Example 5: unrepeatable read. T2T_2 reads X=100X = 100; T1T_1 writes X=90X = 90 and commits; T2T_2 reads XX again and sees 90.

Example 6: which property? A system that keeps committed results only in volatile memory violates durability. Two correct transfers that interleave into a wrong total violate isolation. A transfer program that credits 100 but debits 10 violates consistency, and no DBMS component can repair it.

Example 7: counting schedules. T1T_1 has 2 operations and T2T_2 has 3: there are 5!/(2! 3!)=105!/(2!\,3!) = 10 schedules, 2 of them serial. Three transactions of 2 operations each have 6!/(2! 2! 2!)=906!/(2!\,2!\,2!) = 90 schedules and 3!=63! = 6 serial ones.

Related material. SQL lets a transaction weaken isolation. The SQL standard defines four isolation levels by the phenomena they allow: READ UNCOMMITTED allows dirty reads, nonrepeatable reads and phantoms; READ COMMITTED prevents dirty reads; REPEATABLE READ also prevents nonrepeatable reads; SERIALIZABLE prevents all three. (Korth 17.8; Elmasri and Navathe 20.6.)

Important properties and observations

  • Atomicity and durability are the recovery system's job; isolation is concurrency control's; consistency is the programmer's.
  • Commit point: once committed, a transaction's effects are permanent; abort is impossible.
  • Failed is not aborted: failed means normal execution cannot continue; aborted means rollback is complete.
  • Concurrency is worth it for throughput and response time, but needs control.
  • Anomalies arise only from conflicting accesses to the same item with at least one write.

Common misconceptions.

  • "Consistency is guaranteed by the DBMS." It depends on the transaction being correct; the DBMS checks only declared constraints.
  • "Partially committed means committed." The commit record may not be durable yet; a failure still leads to abort.
  • "Concurrent execution always gives the same result as some serial order." Only if it is controlled; Example 2 gives a result no serial order gives.

GATE examination perspective

  • Match property to component. Atomicity and durability to recovery, isolation to concurrency control.
  • State diagram. Which transitions exist (for example, there is no transition from committed to aborted).
  • Identify the anomaly. Given a short interleaving, identify the anomaly and compute the final values.
  • Count schedules. Total interleavings and serial schedules.

Summary

Sources

  1. A. Silberschatz, H. F. Korth, S. Sudarshan, Database System Concepts, 7th ed., McGraw-Hill, 2019 (2020 copyright), 17.1 Transaction Concept, 17.2 A Simple Transaction Model, 17.3 Storage Structure, 17.4 Transaction Atomicity and Durability, 17.5 Transaction Isolation, 17.8 Transaction Isolation Levels.
  2. R. Elmasri, S. B. Navathe, Fundamentals of Database Systems, 7th ed., Pearson, 20.1 Introduction to Transaction Processing, 20.2 Transaction and System Concepts, 20.3 Desirable Properties of Transactions, 20.6 Transaction Support in SQL.

Next steps