Difference between W(x) and Committed in Dirty Read Problem.

Sir, I could not understand that if a T1 has executed the W(x) then why can't it be considered as COMMITTED. As after W(x) the data is stored in secondary storage which implies that T1 is committed.

1Comment
Prashant Sharma @prashantsharma
17 Apr 2017 05:26 pm

See, for any transaction T:

There could be any number of W(X) statements => Signifying that the value of data item "X" is written.

But when you write COMMIT at the end of transaction => it tells that all the changes made by that particular transaction is made permanent and visibile to all the other users (that may or may not be accessing the the data items modified by transaction T1)

 

Now, according to you the transaction should be considered to be COMMITTED, when a transaction does , W(X).

But, Consider that the transaction T1, modifies two data items, "X" and "Y",

now,

T1 T2
R(X)  
R(Y)  
X = X - 100;  
Y = Y + 100;  
W(X)  
W(Y)  
COMMIT  

 

Now, Ask yourself this question Is this a good idea to consider that the transaction is complete, beacause it has performed W(X) or W(Y) ?

Ans. is No

W(X) => writes  the value of X

And COMMIT => tells you that the transaction is complete.

Now,

you might ask :

Why don't we just use W(X), and W(Y) , why even need to write COMMIT  ?

Because, there could be any other transaction T2, which also, wants to access the data items "X", and "Y". And due to some Transaction failure T1, had to restart (after executing W(Y)) , Now if you declare the transaction to be complete (just by doing Write operation), then when it restarts it will read the modified values.

But, if you use COMMIT, then the changes made to X, Y are not made permanent.Thus when the transaction Trestarts, it reads the original values of X and Y.

Hope this clears your doubt!

If you still have some confusion. Do not hesitate!