Thursday, 21 April 2016

Concurrency Anomalies - Incorrect Summary Problem

Need for concurrency control, Concurrency Anomalies, Concurrent Execution Problems
Incorrect Summary / Inconsistent Analysis problem

This problem is caused when one of the transactions is executing an aggregate operation on several data items, and other transactions are updating one or more of those data items. This causes a inconsistent database state.

Example:

Consider the schedule S1 given below, in which, transaction T1 transfers money from account A to account B and in the mean time, transaction T2 calculates the sum of 3 accounts namely, A, B, and C. The third column shows the account balances and calculated values after every instruction is executed.

Transaction T1
Transaction T2
A = 1000, B = 1000, C = 1000




read(A);
A := A – 50;
write(A);






read(B);
B := B + 50;
write(B);
commit;
sum = 0;
avg = 0;
read(C);
sum := sum + C;



read(A);
sum := sum + A;
read(B);
sum := sum + B;
avg := sum/3;
commit;
sum  = 0
avg = 0
T2 read: C = 1000
sum = 1000
T1 read: A = 1000

T1 write: A = 950
T2 read: A = 950
sum = 1950
t2 read: B = 1000
sum = 2950
avg = 983.33

T2 read: B = 1000

T2 write: B = 1050

Discussion:

Transaction T2 reads the value of account A after A is updated and reads B before B is updated. [The portion that violates in T2 is highlighted in green color]. Hence, the aggregate operation is end up with an inconsistent result.
If all the instructions in T1 are executed before T2 starts, then A will be 950, B will be 1050 and average value will be 1000.
If all the instructions in T1 are executed after T1 finishes, then A will be 950, B will be 1050 and average value will be 1000.
But, due to this interleaved execution, the final value of A is 950, B is 1050, and average is 983.33 which is wrong.
This problem is called as Inconsistent analysis or Incorrect summary problem. This is caused due to the interleaved execution of multiple simultaneous transactions that are working on same data items.

******************

Go to Transaction Management in DBMS home page









No comments:

Post a Comment

SQL exercises for beginners one

SQL Exercises for Beginners / Simple SQL Exercises with Answers / Solved SQL exercises / SQL solved exercises with simple conditions / So...