Transaction Schedules in Database

What is transaction schedule?

  • Transaction schedule is a sequence of database instructions.
  • A transaction includes read and write database object for executing the actions.
  • In transaction schedules, after finishing the first transaction, the execution of second transaction starts.
  • 'R' denotes “Read” operation and 'W' denotes “Write” operation performed by the transaction.
  • If the transaction fails or succeeds, it must specify its final action as a commit or abort.
Example :

Consider two transactions T1 and T2.
T1 : Deposits Rs. 1000 to both accounts X and Y.
T2 : Doubles the balance of account X and Y.

T1

Read (X)
X ← X + 1000
Write (X)
Read (Y)
Y ← Y + 1000
Write (Y)


T2

Read (X)
X ← X * 2
Write (X)
Read (Y)
Y ← Y * 2
Write (Y)


Now, if we perform Serial schedule of the above transaction, it can be represented as below,

Serial Schedule 1

serial schedule 1 table

In the above Serial Schedule 1, first we execute Transaction T2 and then execute T1. This can be represented as T1 → T2.

Serial Schedule 2

serial schedule 2 table

In the above Serial Schedule 2, first we execute T1 and then T2 transaction, represented by T2 → T1.

This will execute the Serial Schedule in following way:

Step 1: Account X initially has Rs. 1000 and Y has Rs. 1000. Transaction T1 will update X as Rs. 2000 and Y as Rs. 2000.

Step 2: T2 will read updated values of X and Y. T2 will update value of X as Rs. 4000 and Y as Rs. 4000.

The consistency constraint X + Y should remain unchanged. So at the end of T2, X + Y i.e 4000 + 4000 = 8000 remains unchanged.

Hence, we see that the execution of this schedule keeps database in consistent state.