Algorithm Search⌘K

Definitionintro

Schedule (transaction history)

Also called transaction schedule, history of transactions.

An interleaving of the read, write, commit and abort actions of several transactions that keeps the order within each transaction.

A schedule (also called a history) is a sequence of the read, write, commit and abort actions of several transactions that holds every action once and keeps the order of the actions inside each transaction. It is the object that a database scheduler produces and that the correctness classes judge: serializability asks whether the schedule has the effect of some serial order, and the recovery classes (recoverable, cascadeless and strict schedules) ask whether aborts can be handled safely. The model keeps only which item each action touches and whether it reads or writes; the values and the program logic are abstracted away.

Definition

Items and actions. Fix a set DD of data items x,y,z,…x, y, z, \ldots. For a transaction index ii, an action is one of ri(x)r_i(x) (a read of xx), wi(x)w_i(x) (a write of xx), cic_i (commit) and aia_i (abort). This is the page model or read-write model: ri(x)r_i(x) returns the current value of xx, and wi(x)w_i(x) sets a new value that may depend on everything that TiT_i has read before.

Transaction. A transaction TiT_i is a finite sequence of reads and writes of TiT_i, followed by at most one terminal action cic_i or aia_i. Bernstein, Hadzilacos and Goodman allow a partial order inside a transaction instead of a sequence; every definition below carries over if "the order of TiT_i" means that partial order.

Schedule. Let T={T1,…,Tn}\mathcal{T} = \{T_1, \ldots, T_n\}. A complete schedule (history) over T\mathcal{T} is a sequence SS of actions such that:

  1. every action of every TiT_i occurs in SS exactly once, and SS has no other actions;
  2. for all actions p,qp, q of the same TiT_i: if pp comes before qq in TiT_i, then pp comes before qq in SS;
  3. every TiT_i has a terminal action.

A schedule is a prefix of a complete schedule. So in a schedule a transaction may still be active (no terminal action yet), and no action of TiT_i follows cic_i or aia_i. We write p<Sqp <_S q when pp comes before qq in SS. Weikum and Vossen use "history" for a complete schedule and "schedule" for a prefix; many texts use the two words as synonyms.

Derived notions. For a schedule SS:

  • TiT_i is committed in SS if ci∈Sc_i \in S, aborted if ai∈Sa_i \in S, and active otherwise.
  • The committed projection C(S)C(S) is the subsequence of SS that keeps exactly the actions of the committed transactions. The serializability classes are defined on C(S)C(S).
  • SS is serial if, for every two transactions Ti≠TjT_i \ne T_j, all actions of TiT_i come before all actions of TjT_j or the other way round.
  • Two actions conflict if they belong to different transactions, touch the same item, and at least one of them is a write.
  • TiT_i reads xx from TjT_j in SS (i≠ji \ne j) if wj(x)<Sri(x)w_j(x) <_S r_i(x), aj̸<Sri(x)a_j \not<_S r_i(x), and every wk(x)w_k(x) with wj(x)<Swk(x)<Sri(x)w_j(x) <_S w_k(x) <_S r_i(x) has ak<Sri(x)a_k <_S r_i(x). An abort restores the value that its transaction overwrote, so a write of an aborted transaction stops counting from the moment of the abort. The recovery classes are defined with this relation.

Counting. If TiT_i has lil_i actions and N=l1+⋯+lnN = l_1 + \cdots + l_n, then the number of complete schedules over T\mathcal{T} is the multinomial coefficient

N!l1! l2!⋯ln!,\frac{N!}{l_1!\, l_2! \cdots l_n!},

and exactly n!n! of them are serial. Proof. Map a schedule to the word u1⋯uNu_1 \cdots u_N where uku_k is the index of the transaction of the kk-th action. Condition 2 means that the actions of TiT_i fill the positions with uk=iu_k = i in their own order, so the word fixes the schedule. Every word with lil_i letters ii arises. The number of such words is the multinomial coefficient. A serial schedule is fixed by the order of its nn blocks, and different orders give different schedules, so there are n!n! of them. □\square

Examples and non-examples

All schedules of two small transactions. Let T1=r1(x) w1(x) c1T_1 = r_1(x)\ w_1(x)\ c_1 and T2=r2(x) w2(x) c2T_2 = r_2(x)\ w_2(x)\ c_2, two transactions that each add 1 to xx. There are 6!/(3! 3!)=206!/(3!\,3!) = 20 complete schedules. Two are serial. Eight are conflict serializable: the two serial ones, and six in which one transaction finishes its read and write of xx before the other reads xx, but commits later. In the other twelve, both transactions read xx before either one writes it, so one of the two updates is lost.

A schedule with an active transaction. S=r1(x) w2(x) r2(y) c2 w1(y)S = r_1(x)\ w_2(x)\ r_2(y)\ c_2\ w_1(y) is a schedule but not a complete one: T1T_1 is active. Its committed projection is C(S)=w2(x) r2(y) c2C(S) = w_2(x)\ r_2(y)\ c_2.

Reads-from across an abort. In S=w1(x) w2(x) r3(x) a2 c1 c3S = w_1(x)\ w_2(x)\ r_3(x)\ a_2\ c_1\ c_3, the read r3(x)r_3(x) comes after w2(x)w_2(x) and before a2a_2, so T3T_3 reads xx from T2T_2, and it has seen a value that the abort later erases. The committed projection is C(S)=w1(x) r3(x) c1 c3C(S) = w_1(x)\ r_3(x)\ c_1\ c_3, and in C(S)C(S) the same read seems to read from T1T_1. So C(S)C(S) is serial, but SS is not recoverable: T3T_3 committed after reading from a transaction that aborted. Correctness needs both kinds of condition.

Non-examples.

  • With T1=r1(x) w1(x) c1T_1 = r_1(x)\ w_1(x)\ c_1, the sequence w1(x) r1(x) c1w_1(x)\ r_1(x)\ c_1 is not a schedule over {T1}\{T_1\}, because it breaks condition 2: the program of T1T_1 reads before it writes.
  • r1(x) c1 w1(y)r_1(x)\ c_1\ w_1(y) is not a schedule: an action of T1T_1 follows its terminal action.
  • w1(x) c1 a1w_1(x)\ c_1\ a_1 is not a schedule: a transaction ends at most once.
  • r1(x) r1(x) c1r_1(x)\ r_1(x)\ c_1 over T1=r1(x) c1T_1 = r_1(x)\ c_1 is not a schedule over {T1}\{T_1\}: an action occurs twice. (It is a schedule over a different transaction that reads xx twice.)
  • Serializability, conflict serializability and view serializability are properties of C(S)C(S). They say whether the committed work has the effect of a serial order.
  • Recoverable, cascadeless and strict schedules are properties of the whole of SS, with its aborts. They say whether an abort can be handled without undoing a commit, without forcing other aborts, or by restoring before images. They are independent of serializability, as the reads-from example shows.
  • Prefix closure. A class of schedules is prefix closed if every prefix of a member is a member. A scheduler that decides online must aim at such a class, since it sees only a prefix. The recovery classes and conflict serializability of C(S)C(S) are prefix closed; view serializability is not. For example, w1(x) w2(x) w2(y) c2 w1(y) c1w_1(x)\ w_2(x)\ w_2(y)\ c_2\ w_1(y)\ c_1 is not view serializable (the last write of xx asks for T1T_1 before T2T_2, the last write of yy for the opposite), but it is a prefix of the same schedule followed by w3(x) w3(y) c3w_3(x)\ w_3(y)\ c_3, which is view equivalent to T1T2T3T_1 T_2 T_3.
  • Concurrency control is the problem of building a scheduler: a program that receives actions one by one and outputs a schedule in a chosen class, by running, delaying or rejecting each action. Isolation levels are weaker classes that a scheduler may aim at instead.
  • Multiversion schedules add a version function that says which write each read sees. They are judged by multiversion serializability.
  • Histories in distributed computing. A history for linearizability is a sequence of invocation and response events of operations on shared objects, with real time. It is a different model: there are no transactions over many items, and the real-time order matters.

References

  1. Philip A. Bernstein, Vassos Hadzilacos and Nathan Goodman, Concurrency Control and Recovery in Database Systems, Addison-Wesley, 1987, Chapter 1 (transactions, recoverability) and Chapter 2 (histories as partial orders, committed projections, the reads-from relation)
  2. Gerhard Weikum and Gottfried Vossen, Transactional Information Systems, Morgan Kaufmann, 2001, Chapter 3 (the page model, transactions, histories and schedules, committed projection)
  3. K. P. Eswaran, J. N. Gray, R. A. Lorie and I. L. Traiger, The notions of consistency and predicate locks in a database system, Communications of the ACM 19(11), 1976, pages 624 to 633, the model of transactions as sequences of actions and of schedules as their interleavings

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/W8A3HT/text.yaml