Testing Serializability of a Schedule

 

๐Ÿ” Concept: Testing Serializability of a Schedule


๐Ÿ“Œ What is the Goal?

To determine whether a given schedule (interleaving of transactions) behaves like a serial execution.


๐Ÿง  Basic Idea

Instead of rearranging operations, we:

๐Ÿ‘‰ Build a precedence graph
๐Ÿ‘‰ Check for dependency cycles


๐Ÿ“Š Precedence Graph

  • Nodes → Transactions (T1, T2, …)
  • Edges → Dependency due to conflicting operations

⚠️ What are Conflicts?

Two operations conflict if:

  • They belong to different transactions
  • They access the same data item
  • At least one is a write

Types:

  • Write → Read
  • Read → Write
  • Write → Write

๐Ÿ”— Meaning of an Edge

If:

Ti → Tj

๐Ÿ‘‰ Transaction Ti must execute before Tj


๐Ÿ”„ Final Decision

✅ No Cycle

  • Schedule is conflict serializable
  • Equivalent serial order exists

❌ Cycle Exists

  • Schedule is not serializable
  • No valid serial execution possible

๐Ÿงฉ Why Cycles Matter?

A cycle means:

Ti depends on Tj AND Tj depends on Ti

๐Ÿ‘‰ Circular dependency → impossible ordering


๐ŸŽฏ Key Insight

The algorithm works by:

  • Build a dependency graph
  • If dependencies form a loop → impossible
  • If no loop → transactions can be ordered safely


  • ๐Ÿงพ Algorithm : Testing Conflict Serializability

    Steps

    1. For each transaction Ti in schedule S, create a node labeled Ti in the precedence graph.
    2. For each case where Tj executes read_item(X) after Ti executes write_item(X), create an edge:

      TiTj
    3. For each case where Tj executes write_item(X) after Ti executes read_item(X), create an edge:

      TiTj
    4. For each case where Tj executes write_item(X) after Ti executes write_item(X), create an edge:

      TiTj
    5. The schedule S is conflict serializable if and only if the precedence graph has no cycles.

    Step 1: Create nodes

    For each transaction Ti in schedule S, create a node Ti.

    ✅ Meaning:

    • Each transaction becomes a node in the graph
    • Example: T1, T2, T3 → nodes

    Step 2: Write → Read conflict

    If Tj reads X after Ti writes X, add edge (Ti → Tj).

    ๐Ÿ“Œ Condition:

    Ti: W(X) → Tj: R(X)

    ✅ Meaning:

    • Tj is reading a value written by Ti
      ๐Ÿ‘‰ So Ti must come before Tj

    Step 3: Read → Write conflict

    If Tj writes X after Ti reads X, add edge (Ti → Tj).

    ๐Ÿ“Œ Condition:

    Ti: R(X) → Tj: W(X)

    ✅ Meaning:

    • Tj overwrites a value read by Ti
      ๐Ÿ‘‰ So Ti must come before Tj

    Step 4: Write → Write conflict

    If Tj writes X after Ti writes X, add edge (Ti → Tj).

    ๐Ÿ“Œ Condition:

    Ti: W(X) → Tj: W(X)

    ✅ Meaning:

    • Two writes on same data
      ๐Ÿ‘‰ Order must be preserved

    ๐Ÿšซ Important:

    • Ignore Read–Read (R–R) → no conflict

    Step 5: Check for cycles

    Schedule is serializable if and only if graph has no cycles.


    ๐Ÿ”„ What is a Cycle?

    A cycle is a loop like:

    T1 → T2 → T3 → T1

    ❌ Meaning:

    • T1 must come before T2
    • T2 before T3
    • T3 before T1

    ๐Ÿ‘‰ Impossible → Not Serializable


    ✅ If NO cycle:

    • Schedule is conflict serializable
    • We can find a valid serial order

    ๐Ÿงฉ If No Cycle → How to Find Serial Order?

    Use the graph:

    • Follow direction of edges
    • Arrange transactions so that:

      Ti → Tj ⇒ Ti comes before Tj

    ๐Ÿ‘‰ This is called topological ordering


    Key Insight

    ๐Ÿ‘‰ Each edge means:

    Ti → Tj ⇒ Ti must execute before Tj

    ๐Ÿ‘‰ If all such constraints can be satisfied → serializable



    ๐Ÿ“Š Summary Table


    StepAction
    1        Create node for each transaction
    2        Add edges for conflicts (W-R, R-W, W-W)
    3        Check graph
    4        Cycle? → ❌ Not serializable
            No cycle? → ✅ Serializable


    Example





    Problem

    (i) Schedule S1: check whether the schedule conflict serializable

    R1(X), R2(X), R1(Y), R2(Y), R3(Y), W1(X), W2(Y)

    ๐Ÿ”น Step 1: Transactions

    T1, T2, T3


    ๐Ÿ”น Step 2–4: Find conflicts and add edges

    On data item X:

    • R2(X) before W1(X) → Read–Write conflict
      → Edge: T2 → T1

    On data item Y:

    • R1(Y) before W2(Y) → Read–Write conflict
      → Edge: T1 → T2
    • R3(Y) before W2(Y) → Read–Write conflict
      → Edge: T3 → T2

    ๐Ÿ”น Step 5: Precedence Graph

    Edges:

    • T2 → T1
    • T1 → T2
    • T3 → T2





    ๐Ÿ” Check Cycle

    We have:

    T1 → T2 → T1 ❌ (cycle)

    ❌ Final Answer (S1):

    Not conflict serializable


    (ii) Schedule S2

    R1(X), R2(X), R2(Y), W2(Y), R1(Y), W1(X)

    ๐Ÿ”น Step 1: Transactions

    T1, T2


    ๐Ÿ”น Step 2–4: Find conflicts

    On X:

    • R2(X) before W1(X) → Read–Write conflict
      → Edge: T2 → T1

     On Y:

    • W2(Y) before R1(Y) → Write–Read conflict
      → Edge: T2 → T1

    ๐Ÿ”น Step 5: Precedence Graph

    Edges:

    • T2 → T1

    ๐Ÿ” Check Cycle

    • No cycle

    ✅ Final Answer (S2):

    Conflict serializable

    Equivalent serial order:

    T2 → T1


    Comments

    Popular posts from this blog

    Database Management Systems DBMS PCCST402 Semester 4 KTU CS 2024 Scheme

    Data Models, Schemas and Instances

    Introduction to Database Management System -DBMS