What is dirty read in a transaction(DBMS)?

When many transactions are executed simultaneously then we call them concurrent transactions. Concurrency is required to increase time efficiency. If there are many transactions which are trying to access the same data, then inconsistency arises. Concurrency control is required to maintain consistency of data.

In order to run transactions concurrently, we interleave their operations. Each transaction gets a share of computing time.

Problems in transactions

This leads to the following problems −

  • Lost update problem. ( WW conflict)
  • Dirty read / temporary update. ( WR conflict)
  • Unrepeatable read / incorrect analysis problem. (RW conflict)

All these arise because isolation is broken.

Let us discuss the dirty read or temporary update.

Dirty Read

Dirty read is a read of uncommitted data. If a particular row is modified by another running application and not yet committed, we also run an application to read the same row with the same uncommitted data. This is the state we say it as a dirty read.

The one main thing is that the dirty reader has to stop reading dirty.

We can try to use the shared locks to prevent other transactions to modify the row, if one is carried out here.

Example of dirty read problem

Example 1

  • Step 1 − Consider we have an online shopping system where users can buy and view the buyer products at the same time.

  • Step 2 − Let us suppose a case in which a user tries to buy a product , and as soon as the user buys the product then the count value in update stock will change immediately.

  • Step 3 − Let us consider that there were 10 items in stock, but now they are 9.

  • Step 4 − Moreover due to this transaction, there will also be communication with the billing gateway.

  • Step 5 − Meanwhile, if there is any other user who has also done a transaction at the same time, the new user will be able to see 9 items in the stock.

  • Step 6 − But, let us suppose that the first user was unable to complete his/her transactions due to some error or insufficient funds.

  • Step 7 − Then, in this case the transaction done by the first user will roll back and now the value in stock will be 10 again.

  • Step 8 − But, when the 2nd user was doing a transaction the no items in stocks were 9.

  • Step 9 − This is called DIRTY DATA and this whole problem is called the Dirty Problem.

Example 2

Consider another example

Let T2 read the update value of X made by T1, but T1 fails and rolls back. So, T2 read an incorrect value of X.






Updated on: 08-Jul-2021

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started