Fine. Now,
let's see the next problem
due to concurrent execution, right, which is dirty read problem.
Okay.
Dirty-read problem. it is also known as write-read conflict.
We have seen write-write conflict in the previous video.
Right.
This is write-read conflict.
Reading an uncommitted data is called as dirty read, right, dirty read.
So, we should always a avoid dirty reads.
Ok, so let me explain this with the explain you with this example.
So what is, what's happening here is T1 in transaction T1,
we are going to read the value of A, let us assume the balance of account A is thousand dollars at this
point of time.
Right? Now what we're doing here. What transaction T1 is doing is, it is going to read this value
of thousand in the register, right.
It has read this value.
Let us assume this register R1 and T1 is having this thousand fine and it is going to make this as
900, fine.
And it is going to write this value in the hard disk, right? Write
this value in the hard disk.
Because of which, it has become 900 fine.
Now what's happening here is, transaction T2 is reading the value of A, right?
It is going to read this value.
Why?
Because this is the value which is present in the hard disk.
So from this I can say that this can also be said as transaction.
B2 is reading the update of T1, right? T1 is writing something and that is being read by T2, right, that
is being read by T2.
So T1 has read this value,
now T2 is going to read this value, fine. T2 has read this value and it has placed in the register, fine.
Now one thing what can happen is see, we are having commit in T1 over here.
Right, now what could happen here is let us assume T2 has read this value fine, now after some time this
transaction fails.
Let us assume at some point over here, this transaction fails, Now what will happen, if a transaction
fails.
What we will do? We will rollback, right?
We will rollback which means we will start this transaction from the beginning.
Right? We will start this transaction from the beginning. But, see if we start this transaction from the beginning,
It is as same as, this transaction has not happened till this point, right?
Which means we are going to start this transaction again.
But what has happened because of this, this transaction has read
the wrong value, right, wrong value.
Why this is wrong value?
Because T1 has not updated it. T1 is able to start this transaction again and after completing this transaction
this value would become 900.
But T2 has read this wrong value, right.
Let us assume T2 has read this value and after some T1 got failed. Now, because of this failure we are going
to rollback this transaction, but, T2 doesn't know that right?
So what T2 will do, it has read the value of 900 and it will calculate the interest which is 4 percent.
4 percent of 900 is nothing but 54.
So this will be added with 9.
This will be added, made as 954 fine? And 954 fine, and, let us assume that this value of 954 is
being written over here. Right?
It is being written over here. So because of this, what will happen, see this can be done in a lot of ways.
Okay.
It really depends on when this transaction fails.
Okay.
Let us assume that we are going to write this value of 954 over here.
This operation is being performed.
Okay.
954.
And let us assume at this point of time, transaction
T1 fails. Okay, at this point of time, transaction T1 fails.
So because of this what will happen and transaction T1 will start from the beginning and it will read
this value of 954.
Right? It will read this value of 954.
So there is definitely some problem over here.
Right?
See this update is definitely wrong.
Okay.
This is going to be done one more time which means this 954 will be read by T1 and
it will be made as 854. Right? 854.
So after completing both the transactions, see we are done with both the transactions. This transaction is done,
fine.
This transaction is also done.
Now
now,
once both the transactions are done we are getting 854 as the result, which is definitely wrong.
Why?
See what we are supposed to get?
If we would have followed serial schedule then T1 should have made thousand as nine
hundred fine and T2 should have made this 900 this nine,
this nine T2 should have made this 900 as 954, right.
This is the value which we are supposed to get after completing both the transactions but we have got
854 which is definitely wrong.
Why did this happen?
Because we have done this transaction two times.
So this is definitely an incorrect value, right? So this schedule is going to produce inconsistent result.
Right?
So such a schedule should not be accepted, right, such a schedule should not be accepted.
So what I want to tell you is, in case if a transaction is trying to read the update of another transaction
then this transaction should wait for this transaction to commit.
Ok, this transaction to commit.
Let us assume that.
Let us assume that this transaction didn't read it and let us assume we are having commit over here.
Ok, commit over here.
Now tell me,
will there be any problem over here?
will there be any problem, in that case what will happen. In that case,
let me start from the beginning.
Ok.
So, we are having the value of thousand, fine? for A in the hard disk.
Now we are going to read this value, into the register fine because of which, it has become thousand.
Fine.
This is R1 and it has been made us nine nine hundred.
Fine.
And this value of nine hundred has been written in the hard disk, fine.
And this value has been made as permanent because of this commit. Ok? Because of this commit,
Fine.
Now,
let us assume this transaction is reading this this value. Ok?
This value has been read by this transaction and it has been pasted in the register R2, fine.
Now, let us assume, six percent interest has been added to this, right? See this is 6 percent right.
So sorry for this.
This is 6 percent.
Okay.
It doesn't matter anyway.
So 6 percent of 900 is nothing but 54.
Right.
So.
So it is 0.06 into 900.
So both the zeros will get cancelled and this point will go away, because of this
we get 954.
So this 900 will be made as 954, fine because of this, fine.
Now what happens if this transaction fails somewhere over here.
In that case, we will perform rollback.
But because of that rollback, B will be heading to this position, right.
B will be heading to this position.
If we head to this position, what'll happen?
There is nothing wrong in it right.
There is nothing wrong in it because we don't have any operations to perform.
So we are done with both the transactions and after completing both the transactions we are ending up
with the value of nine hundred and fifty four. See, we will end up with the value of 954.
Why?
Because of this write of A.
This 954 will be written over here.
This 900 has been read by, written by this transaction.
Right. Now, because of this write, this 954 will be written over here.
So after completing both the transactions we are getting the correct value of 954.
Right, so this is the consistent result.
Now why we got a consistent result over here because this transaction has waited for this transaction
to commit before reading.
In case if this transaction would have read this value, this update of the T1, if T2 has read the update
of T1 without waiting for commit, then there is a chance of inconsistency, right,
in case if the transaction fails. Let us assume we have commit over here.
Now if transaction fails over here then there is a,
there is inconsistency. Right? Now in case because, why this problem happened because this transaction
did not wait for this transaction to commit, before that it has read the value, right? Now in case if this transaction
T2 would have waited for T1 to commit and in case if it would have been, if it would have
read the value after commit, then we would not have got this problem, right?
So what I want to tell you is, reading an uncommitted update is what we mean by dirty-read, right, or reading
an uncommitted write. See,
this is this is uncommitted
write.
Right.
We have performed, right.
And this has not committed.
But we are still reading this uncommitted write.
Right?
This is what we mean by dirty-read.
We should always avoid dirty-read.
Right?
If we don't avoid dirty-read then we will get inconsistency.
Fine.
We should
avoid dirty-reads that is a transaction T2
which is about to read the update of another transaction
T1. So, T1 has made an update and this transaction is waiting for, waiting to read this update, fine.
Read the update of another transaction T1, it should wait for T1. This transaction T2 should wait
for T1 to commit.
If it doesn't wait for T1 to commit
and if it reads the value then that is that is dirty-read and because of which we will get inconsistent
results.
So we have seen two problems right.
One thing is write-write conflict and another one is write-read conflict.
What is write-write conflict? In case if we are having 2 writes of the same data items across two different
transactions then there should be read in between.
Right.
Else there we will get inconsistent results or it is called as
lost-update problem which means the second write will
overwrite
the first write because of which the first write made by a transaction is being lost.
Right.
So we say it as lost-update problem.
So what what do you mean by dirty-read problem?
If a transaction is trying to read the update of another transaction then this transaction should wait
for this transaction to commit before reading else we will get inconsistency. See,
again we are having the same data item over here.
Right?
Let us assume it is reading, it is writing B and it is reading A, will there be any problem?
This is not write-read conflict. Right?
This is not write-read conflict. The data item has to be same.
The data item has to be same and there should not be any commit over
here. In order to say that, here we are having write-write write-
read conflict. Ok? In case, if we have commit over here,
then there is no write-read conflict for the schedule right.
Also in case if the data items are different over here then there is no write-
read conflict for the schedule, ok? What they might give you is they might give you a schedule something
like this and they will ask whether we are having write-read conflict for the schedule or not.
And you are supposed to find out that okay I think it is very simple now.