How to check for View Serializable and Conflict Serializable

This is a note for myself about how to check whether a schedule is view serializable, conflict serializable, or not.

There is various resources in the internet about how to do this, but the examples are a bit scattered, so in this post I just want to make a neat note on how to do it properly with several examples that can cover many possibilities as well.

Let’s get started!

For the sake of this tutorial, we will use this example:
R1(X),R2(Y),R2(Y),W2(X),W3(Y),R1(X)

or if we spread it to three different transactions, it will be:

T1 |  R1(X)                         R1(X)
T2 |        R2(Y) R2(Y) W2(X)
T3 |                          W3(Y)

How to check for Conflict Serializable?

To check for conflict serializability takes two steps.
Step #1 : Check for the conflicting actions.

(From Wikipedia)
——————————————————
Two or more actions are said to be in conflict if:

1. The actions belong to different transactions.
2. At least one of the actions is a write operation.
3. The actions access the same object (read or write).

The following set of actions is conflicting:

T1:R(X), T2:W(X), T3:W(X)

While the following sets of actions are not:

T1:R(X), T2:R(X), T3:R(X)
T1:R(X), T2:W(Y), T3:R(X)
—————————————————–

For our example, we have a conflict on X (T1 reads it and T2 writes it).
We also have a conflict on Y (T2 reads it and T3 writes it).

So it has a conflict property but is it serializable?

Step #2 : Check for a cycle in the Precedence Graph.

The easiest way to check for a cyclic transaction, is to paste the schedule to this web app.

But if you are like me, you won’t be satisfied getting answer from someone without understanding how exactly they come up with the the answer (though sometimes I don’t care either..). So let’s find out how to do exactly just that.

First, draw all the Transactions (Tx):

precedence graph - initial

Check if there is a Tx that reads an item after a different Tx writes it.

  • We have T1 that reads X after T2 writes it, so draw arrow from T2 -> T1

Check if there is a Tx that writes an item after a different Tx reads it.

  • We have T2 that writes X after T1 reads it, so draw arrow from T1 -> T2
  • We also have T3 that writes Y after T2 reads it, so draw arrow from T2 -> T3

Check if there is a Tx that writes an item after a different TX writes it.

  • not in this case

So, the final graph is :

example-1

We can see that there is a cycle between T1 and T2, so the graph is cyclic, and therefore it is not conflict serializable.

Need more example?
Graph for R1(X),R2(Y),W3(Z),W2(Y),W2(X),R1(Z),W3(Y),W2(X)
example-2-and-3

Graph for R1(X),R2(Y),R3(Z),W2(Y),W2(X),W1(Z),W3(Y),W2(X)

(same like the previous example)

How to check for View Serializable?

To check for view serializability of a schedule, you must create all possible combinations of the Transactions. So let’s say you have three transactions, then you need to check for these combinations:
< T1, T2, T3 >
< T1, T3, T2 >
< T2, T1, T3 >
< T2, T3, T1 >
< T3, T1, T2 >
< T3, T2, T1 >

Now the schedule is view serializable if:

A Tx reads an initial data in a Schedule, the same Tx also should read the initial data in one of the transaction combination.

  • For our example, at least T1 should occur before T2, because T1 reads initial value X. If T2 occurs before T1, then T1 reads X value after T2 writes. So remove these combinations:
    • < T2, T1, T3 >
    • < T2, T3, T1 >
    • < T3, T2, T1 >

A Tx reads a data after another Tx has written in a Schedule, the same Tx also should read the data after another Tx has written it in one of the transaction combination.

  • In our example, T1 reads X after T2 writes, so it means that T2 should occur before T1. But wait a minute, isn’t it we’ve just said that T1 should occur before T1 on the previous condition? That’s what a cycle in the graph also caused. We need T1 before T2 and at the same time we need T2 before T1. Because of this, none of the combinations can satisfy these two conditions, so it is not view serializable.

A Tx writes the final value for a data in a Schedule, the same Tx should also write the final data in one of the transaction combination.

  • Although we’ve said that our schedule is not view serializable, let’s just take a look which combination satisfy this condition. We know that T2 writes Y and X, but in our schedule the T3 writes the last value of Y. So the combination that satisfy these condition should have T2 occur before T3. If we are to choose the combinations, keep everything else but remove these:
    • < T1, T3, T2 >
    • < T3, T1, T2 >
    • < T3, T2, T1 >

View Serializable Example:

Now, let’s take a look an example that is view serializable
W3(Z), R2(X), W2(Y), R1(Z), W3(Y), W1(Y)

A Tx reads an initial data in a Schedule, the same Tx also should read the initial data in one of the transaction combination.

  • Here, at least T2 must occur first, though it actually doesn’t matter also because no one else writes X, so we still keep all our Tx combinations.

A Tx reads a data after another Tx has written in a Schedule, the same Tx also should read the data after another Tx has written it in one of the transaction combination.

  • Now, this means that T1 must occur after T3 because T1 reads Z after T3 writes it. So we remove
    • < T1, T2, T3 >
    • < T1, T3, T2 >
    • < T2, T1, T3 >

A Tx writes the final value for a data in a Schedule, the same Tx should also write the final data in one of the transaction combination.

  • Here, T1 must occur last after T3 or T2 because if not T3 or T2 will overwrites Y that T1 writes in our schedule. So we remove  < T3, T1, T2 >

So the two combinations left satisfy the view serializability this time, they are:

  • < T2, T3, T1 >
  • < T3, T2, T1 >

Conclusion

That’s all friends! Now you know how to check a database schedule for its view and conflict serializability. Questions, critics and comments are welcome. :D


Popularity: 45% [?]

Tags: ,

Related Posts


42 comments ↓

#1 Jeremy on 11.30.10 at 10:52 pm

Your note is useful, thanks from Hong Kong.

#2 djitz on 12.04.10 at 4:47 pm

You’re welcome Jeremy! :D

#3 Varun on 12.07.10 at 8:38 am

Good Work.
Can u pls explain view serializability example using R1(X), W1(X), R2(X), W2(X), R3(X), W3(X) instead of . Correct me if this cannot be applied for view serializability.

#4 djitz on 12.09.10 at 10:01 am

Hi Varun,

Hmm.. I think for view serializability check, we really should test the transactions if they are executed in any of these six combinations:

Because although in a schedule the transaction overlaps each other, if its result is equal to one or more of these combination, then it is view serializable. If not, then it is not view serializable. :D

#5 Elie on 01.19.11 at 2:41 am

useful note
thank you for spending the time making it . :)

#6 djitz on 01.19.11 at 10:06 am

You’re welcome Elie! :D

#7 Ash on 01.21.11 at 12:10 pm

We have T2 that reads X after T1 reads it, so draw arrow from T1 -> T2

We have T2 that WRITE X after T1 reads it, so draw arrow from T1 -> T2

#8 djitz on 01.22.11 at 5:44 pm

@Ash, thanks for catching the mistakes, I’ve fixed them.. :D

#9 rajdeep on 01.29.11 at 6:20 am

Usefull notes.thanks.

#10 A.R.Kiran on 02.08.11 at 9:10 am

thanks yaar good explanation

#11 venkat on 02.08.11 at 10:12 pm

usefull notes.
but i want an example of View Serializable which is not Conflict Serializable..

#12 djitz on 02.09.11 at 8:51 pm

hmm.. yeah, unfortunately I don’t have such example also.

Anyway, I hope my explanation is clear enough to make people able to tell when such case occur. :D

#13 sourav on 05.23.11 at 9:35 pm

today is my DBMS exam… thanks for this note….

#14 neghah on 05.23.11 at 11:48 pm

thank you so much you helped me to do my assignmet

#15 priyasmita on 05.26.11 at 5:55 am

thanks a lot,it has been extremely helpful.

#16 IT Man on 06.08.11 at 11:52 pm

Thank you very much. My teacher taught is a bullshit. All thanks to you

#17 anuran on 06.09.11 at 2:14 pm

beautifully done,good examples

#18 Saidah on 06.11.11 at 3:24 am

Many thanks for this summarize and easy explanation.

#19 Seda on 06.18.11 at 11:30 am

Thank you so much I will get the highest mark tomorrow :)

#20 Vasana on 08.18.11 at 6:27 am

Thanks a lot for your valuable lesson.

#21 Vasana on 08.18.11 at 6:55 am

http://www-stud.uni-due.de/~selastoe/?mdl=dbms&mode=precedence#graph

i think this link will help you

#22 nils on 09.11.11 at 11:23 am

thanks dude…..i was strugling for this from past 2 days. india

#23 nils on 09.11.11 at 11:25 am

Does every conflict serializable is view serializable ?

#24 djitz on 09.15.11 at 6:15 pm

yes, it is (link to Wikipedia).

#25 Nilay on 09.15.11 at 7:06 pm

Thanks a lot. . .

#26 sir42 on 09.18.11 at 1:27 am

gud work my friend..keep it up..

#27 indika on 09.22.11 at 10:21 pm

nice one dude!!very useful.thanx alot!!

#28 Shashank Bhardwaj on 10.10.11 at 10:32 am

Good, Very Good. Really Useful, So much simple language. Excelent! With Real Examples, With Easy Steps. Good.

#29 saumya on 11.02.11 at 7:21 am

thanx zillions of times…..

#30 pavan on 11.15.11 at 2:49 am

Thanks sir…..

#31 nils on 11.17.11 at 9:03 pm

Can you show how all conflict serializable schedules are view serializable ? Because as per Thomas’ write , there are some view serializable schedules which are not conflict serializable..

#32 shanu on 12.02.11 at 10:50 am

really a gud job!!

#33 Bhushan on 12.19.11 at 4:08 am

keep the good work up…. thanx buddy :)
-from India

#34 LAst day exam study! on 12.19.11 at 4:54 am

You saved my a** in the final day of the exam. Thank you so much!!! You should put a paypal donation, i would do that ! THANKS MAN!!

#35 Somen dutta on 12.30.11 at 12:57 am

Good understanding

#36 chandan on 12.30.11 at 9:30 am

Thanks very very nice explanation

#37 kamal on 01.08.12 at 6:12 pm

thaaaanks

#38 Dipak Panchasara on 01.14.12 at 9:57 pm

Hey Dude.
you really done nice job…….

Thanks a lot……….

#39 Nikhil on 01.19.12 at 11:30 pm

Pretty well explaind…
Thanks a lot :)

#40 dinesh on 04.09.12 at 10:21 am

AMAZING WORK!!!KUDOS TO DJITZ…

#41 vijeta on 08.20.12 at 12:04 pm

best notes ever very very thank u

#42 Tim on 05.04.13 at 11:01 am

Great write up save me big time

Leave a Comment