Concurrency can simply be said to be executing multiple transactions at a time. It is required to increase time efficiency. If many transactions try to access the same data, then inconsistency arises. Concurrency control required to maintain consistency data.
For example, if we take ATM machines and we do not use concurrency, then multiple persons cannot draw money at a time in different places. This is where we need concurrency.
The advantages of using the concurrency control are as follows −
To run transactions concurrently, we interleave their operations. Each transaction gets a share of the computing time.
This leads to the following problems −
Lost update problem (write-write conflict)
Temporary update or dirty read problem (write-read conflict).
Unrepeatable read or incorrect analysis problem (read-write conflict).
All arises because isolation is broken.
One transaction does some changes and another transaction deletes those changes. One transaction nullifies the updates of another transaction.
Two transactions T1 and T2 read, modify, write to the same data item in an interleaved fashion for which an incorrect value is stored in x. T2 reads the value of X before T1 changes it hence the updated value resulting from T1 is lost.
The final value of x is 15, which is incorrect.
One variable has been updated in one transaction, at the same time another transaction has started and deleted the value of the variable where the variable is not getting updated or committed. That has been done on the first transaction; this gives us false values or the previous values of the variables; this is a major problem.
T2 reads the update value of X made by T1, but T1 fails and rolls back. So, T2 reads an incorrect value of X.
One transaction is updating multiple different variables and another transaction is in a process to update those variables. The problem occurs is inconsistency of the same variable in different instances.
T1 consists of two parts – subtract 5 from X and add 5 to Y.
In T2, the value of X is updated but the value of Y is not updated. The sum variable stores an incorrect value. Following protocols are used to control concurrency and preserve consistency.