1. Gyanastra
  2. Database Systems
  3. Schedules and Serializability
  4. Schedule: Definition and Types
Free lesson, no account needed 6 min read 6 practice questions after it
Asked in past papers1 time
  • GATE CSE2004

Database Systems · Schedules and Serializability

Schedule: Definition and Types

Overview

A schedule is the order in which the operations of multiple transactions are executed.
When several transactions run concurrently, many different orderings are possible, and only some of them produce correct results — so understanding schedules is the basis for judging serializability and correctness under concurrency.

Key concepts

  • Schedule: the order in which the operations of various transactions are executed, when more than one transaction has to be run.
  • Single transaction case: with only one transaction there is no choice — operations run top to bottom, so no variety of schedules exists. Multiple schedules become possible only with two or more transactions.
  • Interleaving: the only freedom in a schedule is the relative order of operations belonging to different transactions.
  • Internal order is fixed: within a single transaction the order of its operations must be preserved; an arrangement that reorders them is not a schedule at all.
  • Phantom tuple / phantom phenomenon: a row that appears or disappears between two reads of the same query inside a transaction; this is one of the concurrency problems a wrong schedule can produce.
  • No concurrency control: if transactions are simply allowed to interleave and operate, the system may execute in any of the possible schedules.
  • Correctness depends on the operations: independent transactions (no common data item) may give correct results under all schedules; dependent transactions (common data items) may give wrong answers under some interleavings.
Figure. T1 always runs A1 then A2 and T2 always runs B1 then B2. Exactly six interleavings are valid; S7 is rejected because A2 precedes A1.

How it works

  1. With many transactions arriving, the server can order their operations in many ways:
    • take one transaction and run all its operations, then start the next transaction; or
    • run some operations of one transaction, then some of another, come back to the first, then back to the second, and so on. Both are schedules; they differ only in the interleaving order.
  2. Example set-up: transaction T1 has two operations A1, A2 (A1 before A2); transaction T2 has two operations B1, B2 (B1 before B2).
    Two operations per transaction is only an assumption to keep the explanation simple — in general a transaction has many more operations.
    Completing T1 requires A1 and A2; completing T2 requires B1 and B2; so four operations in total must be arranged.
  3. Enumerate the possibilities (all six, and no more — this can be tested and verified):
    • A1, A2, then B1, B2
    • B1, B2, then A1, A2
    • A1, then B1, then A2, then B2
    • A1, then B1, B2, then A2
    • B1, then A1, then B2, then A2
    • B1, then A1, A2, then B2
  4. Reject invalid arrangements: A2, B1, B2, A1 can never be a schedule, because in T1, A1 must be done first and A2 afterwards; that order cannot be altered.
    In every valid schedule above, T1 always runs A1 then A2 and T2 always runs B1 then B2.
  5. Count: for two transactions with two operations each, exactly six schedules are possible.
  6. Check correctness: it depends on what type of operations the transactions perform.
    • No intersection (independent transactions): all the schedules may produce correct results.
    • Dependent transactions: some interleavings may lead to wrong answers — the earlier concurrency problems, e.g. the phantom-tuple/phantom-phenomenon type of problem.
      Any schedule that leads to one of those problems is a wrong schedule.

Formulas

  • Number of schedules (interleavings) of nn transactions: (k1+k2+⋯+kn)!k1!×k2!×⋯×kn!\frac{(k_1 + k_2 + \dots + k_n)!}{k_1! \times k_2! \times \dots \times k_n!} where kik_i = number of operations in transaction TiT_i (the order of operations inside each transaction is fixed).
  • For the example: two transactions × two operations each → 4!2!×2!=244=6\frac{4!}{2! \times 2!} = \frac{24}{4} = 6

Worked examples

Two transactions T1(A1, A2) and T2(B1, B2) — all valid schedules:

ScheduleOrder of operationsHow it interleaves
S1A1 A2 B1 B2T1 completely, then T2 completely
S2B1 B2 A1 A2T2 completely, then T1 completely
S3A1 B1 A2 B2strict one-by-one alternation starting with T1
S4A1 B1 B2 A2start T1, finish T2, then finish T1
S5B1 A1 B2 A2strict alternation starting with T2
S6B1 A1 A2 B2start T2, finish T1, then end T2

Invalid arrangement (not a schedule):

AttemptOrderWhy rejected
S7A2 B1 B2 A1A2 is executed before A1, violating the internal order A1 → A2 of T1

Correctness check of the six schedules:

  • If T1 and T2 operate on completely different data items → all six may give correct results.
  • If they operate on the same data item → some of these six orders reproduce the earlier concurrency problems and hence give wrong results; which ones are wrong depends on the operations involved.

Revision summary

  • A schedule is the order of execution of the operations of multiple transactions.
  • One transaction ⇒ only one possible schedule (top to bottom); more than one transaction ⇒ many possible schedules.
  • Total operations = 4 (two from each transaction) ⇒ exactly 6 valid schedules, and no more.
  • The only freedom is interleaving across transactions; the order of operations inside a transaction is fixed — violating it (A2 before A1) means it is not a schedule at all.
  • With no concurrency control, the DBMS may execute any of the possible schedules.
  • Independent transactions → all schedules fine; dependent transactions → some schedules give wrong answers (e.g. the phantom phenomenon).
  • Exam tip: be able to list and count the schedules for two transactions with two operations each, and to state instantly why an arrangement that reorders operations inside one transaction is invalid.

Previous-year exam insights

  • A schedule is serializable if it is conflict-equivalent (or view-equivalent) to some serial schedule; conflict serializability is tested by drawing the precedence (serialization) graph — an edge Ti→Tj whenever an operation of Ti conflicts with a later operation of Tj — and the schedule is conflict-serializable iff this graph is acyclic.
  • Two operations conflict only if they belong to different transactions, access the same data item, and at least one of them is a write (R-W, W-R, W-W); R-R never conflicts.
  • A serial schedule (one transaction completely before the next) is always correct/serializable; a schedule is serial iff no operations of different transactions interleave.
  • Recoverability classes: a schedule is recoverable if every transaction commits only after all transactions it read from have committed; it is cascadeless (avoids cascading rollback) if it reads only committed data; it is strict if it neither reads nor writes an item until the last transaction that wrote it has committed.
    Strict ⇒ cascadeless ⇒ recoverable.
  • The number of serial schedules of n transactions is n!, while the number of all possible interleavings (with fixed internal order) is (Σki)!/(k1!k2!…kn!); the number of conflict-serializable schedules is generally smaller than the total and must be counted via the acyclic precedence graphs.
  • Blind writes and view serializability: every conflict-serializable schedule is view-serializable, but not conversely; view-serializable schedules that are not conflict-serializable can only arise when there are blind writes (a write not preceded by a read of the same item in that transaction).
Pages 1–2 of 2