Polygraph to check View Serializability in DBMS

10 Jun, 2022
Prerequisite – Concurrency Control -Introduction, Conflict Serializability, Transaction Isolation Levels in DBMS Serializability: If any transaction (non-serial) produce a outcome which is equal to the outcome of that schedule’s transaction executed serially then we can call that transaction schedule a Serializable schedule. 
Note that the main objective of serializability is to find non-serial schedules that allow transactions to execute concurrently without interference and produce a database state that could be produced by a serial execution. These are following types of schedules: 
 
Serial scheduleConflict SerializabilityView SerializabilityNon-serial schedule
Serial schedule
Conflict Serializability
View Serializability
Non-serial schedule
View Serializability – A schedule is called View Serializable, if it’s view equivalent to a serial schedule (no overlapping transaction allowed). These are following condition to be a View Serializability: 
 
In both the schedules read of initial value of data item and write of final value of data item by transaction must be same.W->R conflict must be same in both schedules.
In both the schedules read of initial value of data item and write of final value of data item by transaction must be same.
W->R conflict must be same in both schedules.
Now, lets consider following examples. 
Example: Suppose there is two schedule one is non-serial and another one is serial schedule.  
    Schedule 1              Schedule 2      
  --------------          ---------------
   T1      T2               T1      T2
  --------------          ---------------
  r1(A)                    r1(A)
  A=A+10                   A=A+10
  w1(A)                    w1(A)
  r1(B)                            r2(A)
  B=B*10                           A=A+10
  w1(B)                            w2(a)
          r2(A)            r1(B)                            
          A=A+10           B=B*10      
          w2(A)            w2(B)      
          r2(B)                    r2(B)
          B=B*10                   B=B*10
          w2(B)                    w2(B)  
Checking view serializable or not:  
    Comparison Table
---------------------------
Schedule 1    Schedule 2
---------------------------
A   T1 T2         T1 T2
B   T1 T2         T1 T2 
So Schedule 2 is view equivalent to Schedule 1. 
Using polygraph when the number of transactions is more than 2: Suppose we have 3 transactions T1, T2, and T3. Possible combinations of those transactions are: 
 
--------------
 T1   T2   T3
 T1   T3   T2
 T2   T1   T3
 T2   T3   T1
 T3   T1   T2
 T3   T2   T1
-------------- 
1. A Tn reads an initial data in a schedule the same Tn also should read the initial data in one of the transaction combinations. That means T1 should occur before T2, so we have to remove these combinations:  
--------------
 T2   T1   T3
 T2   T3   T1
 T3   T2   T1
-------------- 
2. A Tn reads a data after another Tn has written in a schedule, the same Tn also should read after another Tn has written it in one of transaction combination. 
3. A Tn writes the final value for a data in a schedule, the same Tn should also write the final data in one of the transaction combinations. That means T2 occur before T3, so we have to remove these combinations:  
--------------
 T1   T3   T2
 T3   T1   T2
 T3   T2   T1
-------------- 
Example:  
Schedule = w3(x),r2(x),w2(y),r1(z),w3(y),w1(y) 
 
  T1   T2    T3
----------------
            w(x)
     r2(x)
     w2(y)
r1(z)
           w3(y)
w1(y)
---------------- 
Here T3 must occur first, though it actually does not matter because of no one else writes X, we will keep all the possible transaction combination in the first step. 
T1 must occur after T3 because T1 reads Z after T3 writes it. So here we remove those three combinations of transaction where T1 is before than T3.  
Available combination:
 T2 T3 T1
 T3 T1 T2
 T3 T2 T1 
T2 must occur last cause if not T3 or T2 will overwrite y that T1 writes in our schedule, so we remove from available combination where T1 is not occurring last.  
Available combination:
 T2 T3 T1
 T3 T2 T1 
Note that we use Polygraph when a blind write is available in any transaction.  
sooda367
bhawnachelani123
DBMS-Transactions and Concurrency Control
Picked
Technical Scripter 2018
DBMS
GATE CS
DBMS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.