Topic : Problems with Concurrent Execution
Ms. Shruthi Stephen
Department of Computer Science [UG]
Kristu Jayanti College (Autonomous)
Bengaluru
What is concurrent execution?
concurrent execution refers to the ability to execute multiple
transactions or operations at the same time. This is a fundamental
concept in DBMS designed to ensure that many users or applications
can interact with the database simultaneously, improving system
throughput, resource utilization, and response time.
Problems with Concurrent Execution
Lost update problem (W - W)
T1 T2
R(X)
X= X+10
R(X)
X = X+5
W(X)
W(X)
Dirty Read Problem (W - R)
T1 T2
R(X)
X=X+10
W(X)
R(X)
X= X+10
W(X)
Commit
Fail
Unrepeatable Read problem (R - W)
T1 T2
R(A)
R(A)
A = A+10
W(A)
Commit
R(A)
W(A)
Commit
Incorrect Summary Problem
Imagine you are running an online shopping website, and you need to display a total
sales amount for the day. You have multiple transactions occurring simultaneously —
customers are buying products, making payments, and the system calculates the total
sales.
Scenario:
● Transaction T1: You want to generate the total sales summary for the day. So, you
calculate the sum of all the payments made by customers during the day.
● Transaction T2: Another customer purchases a product at the same time and their
payment is added to the total sales.
Let’s say:
● The total sales before T2's payment is 5000.
● T2 makes a new purchase of 200 (so now, the total sales should be 5200).
But here’s where the problem happens:
● T1 starts its calculation at 5000, then it reads the data and
processes the result.
● T1 does not see T2's update immediately (because T1 and
T2 are happening concurrently), and therefore T1 finishes
calculating the total sales without including the new 200
from T2.
● T1 then presents the incorrect summary: it shows the
total sales as 5000 instead of the correct 5200.
Concurrency Control Techniques
Lock Based Protocol
Shared Lock (S)
Exclusive Lock (X)
Shared Lock protocol
● Shared Locks can only read the data without performing any changes in
the db
● Other transaction will only be able to read the data from the first
transaction
● Iif other transactions need to manipulate the data, then T1 should be
unlocked
Exclusive Lock
● If a particular transaction is under exclusive lock then
both read and write operation can be performed but at
the same time other transactions won't be able to
perform any other operations
● Other transactions will only be able to perform
operations if T1 unlocks
Two Phase Locking Protocol
This type of protocol mainly consists of two phases
Growing phase : I will obtain lock but it wont release
Shrinking phase : It will release the lock but it may not
obtain new lock
Transaction which is not two phase protocol
What is meant by Lock Upgrade and Downgrade
Upgrade Lock
Suppose if the data is in the shared Lock and other transactions needs to
perform write operation so we need to upgrade the lock into Exclusive lock
Downgrade
Suppose if the data needs to only accessed by the other transaction, we
need to downgrade the exclusive lock into shared lock
Problems with 2PL
● Unnecessary or early lock
● Deadlock
● Cascading rollback
Early Lock
Consider the example
T1 T2
LOCK X(A)
R(A)
A=A+10
LOCK S(A)
LOCK X(B)
R(B)
B=B+10
EXPLANATION
In the above example, T2 will not be able to read the
data from T1 as it is not getting unlocked so T2 needs
to wait till T1 gets unlocked.
Deadlock
T1 T2
LOCK X(B)
R(B)
W(B)
LOCK S(A)
R(A)
LOCK X (B)
LOCK X(A)
Cascading rollback
Timestamp Protocol
In this protocol we are evaluation the transactions based
on the order of their arrival so in this case deadlock will not
come.
Timestamp is denoted as
TS(Ti) [Ti means the number of transaction]
TRANSACTIONS T1 T2 T3
Timestamp 10
(Older)
20 30
(Youngest)
R(A)
R(A)
R(A)
Read Time Stamp (X)
It is the youngest transaction, which performs the read operation
Write Time Stamp (X)
It is the youngest transaction, which performs the Write operation
OPTIMISTIC CONCURRENCY CONTROL /
VALIDATION PROTOCOL
In this protocol instead of using actual data, it is
stored in a temporary variable then in the end after
the validation and all it will pass the value to the
original data then it gets permanently stored in the db
This protocol is followed by 3 phases:
● Read phase :In this phase the actual data can be stored in a temporary
variable
● Validation phase : After the validation and all it will check whether the
transaction is serializable or not wrt to the temporary var.
● Write phase : If the validation state gets completed, the value in the
temporary var will get stored permanently in the db, otherwise it will get
rollback (when it fails)
Each phase has different timestamps:
Start : It contains the time when Ti starts the execution
Validation : It contains the validation time when the read phase come
to an end
Finish: it contains the time when Ti finishes the write phase
Thank you

Problems occurred in concurrent transaction

  • 1.
    Topic : Problemswith Concurrent Execution Ms. Shruthi Stephen Department of Computer Science [UG] Kristu Jayanti College (Autonomous) Bengaluru
  • 2.
    What is concurrentexecution? concurrent execution refers to the ability to execute multiple transactions or operations at the same time. This is a fundamental concept in DBMS designed to ensure that many users or applications can interact with the database simultaneously, improving system throughput, resource utilization, and response time.
  • 3.
    Problems with ConcurrentExecution Lost update problem (W - W) T1 T2 R(X) X= X+10 R(X) X = X+5 W(X) W(X)
  • 4.
    Dirty Read Problem(W - R) T1 T2 R(X) X=X+10 W(X) R(X) X= X+10 W(X) Commit Fail
  • 5.
    Unrepeatable Read problem(R - W) T1 T2 R(A) R(A) A = A+10 W(A) Commit R(A) W(A) Commit
  • 6.
    Incorrect Summary Problem Imagineyou are running an online shopping website, and you need to display a total sales amount for the day. You have multiple transactions occurring simultaneously — customers are buying products, making payments, and the system calculates the total sales. Scenario: ● Transaction T1: You want to generate the total sales summary for the day. So, you calculate the sum of all the payments made by customers during the day. ● Transaction T2: Another customer purchases a product at the same time and their payment is added to the total sales. Let’s say: ● The total sales before T2's payment is 5000. ● T2 makes a new purchase of 200 (so now, the total sales should be 5200).
  • 7.
    But here’s wherethe problem happens: ● T1 starts its calculation at 5000, then it reads the data and processes the result. ● T1 does not see T2's update immediately (because T1 and T2 are happening concurrently), and therefore T1 finishes calculating the total sales without including the new 200 from T2. ● T1 then presents the incorrect summary: it shows the total sales as 5000 instead of the correct 5200.
  • 8.
    Concurrency Control Techniques LockBased Protocol Shared Lock (S) Exclusive Lock (X)
  • 9.
  • 10.
    ● Shared Lockscan only read the data without performing any changes in the db ● Other transaction will only be able to read the data from the first transaction ● Iif other transactions need to manipulate the data, then T1 should be unlocked
  • 11.
  • 12.
    ● If aparticular transaction is under exclusive lock then both read and write operation can be performed but at the same time other transactions won't be able to perform any other operations ● Other transactions will only be able to perform operations if T1 unlocks
  • 13.
  • 14.
    This type ofprotocol mainly consists of two phases Growing phase : I will obtain lock but it wont release Shrinking phase : It will release the lock but it may not obtain new lock
  • 15.
    Transaction which isnot two phase protocol
  • 16.
    What is meantby Lock Upgrade and Downgrade Upgrade Lock Suppose if the data is in the shared Lock and other transactions needs to perform write operation so we need to upgrade the lock into Exclusive lock Downgrade Suppose if the data needs to only accessed by the other transaction, we need to downgrade the exclusive lock into shared lock
  • 17.
    Problems with 2PL ●Unnecessary or early lock ● Deadlock ● Cascading rollback
  • 18.
    Early Lock Consider theexample T1 T2 LOCK X(A) R(A) A=A+10 LOCK S(A) LOCK X(B) R(B) B=B+10
  • 19.
    EXPLANATION In the aboveexample, T2 will not be able to read the data from T1 as it is not getting unlocked so T2 needs to wait till T1 gets unlocked.
  • 20.
    Deadlock T1 T2 LOCK X(B) R(B) W(B) LOCKS(A) R(A) LOCK X (B) LOCK X(A)
  • 22.
  • 23.
    Timestamp Protocol In thisprotocol we are evaluation the transactions based on the order of their arrival so in this case deadlock will not come. Timestamp is denoted as TS(Ti) [Ti means the number of transaction]
  • 24.
    TRANSACTIONS T1 T2T3 Timestamp 10 (Older) 20 30 (Youngest) R(A) R(A) R(A)
  • 25.
    Read Time Stamp(X) It is the youngest transaction, which performs the read operation Write Time Stamp (X) It is the youngest transaction, which performs the Write operation
  • 26.
    OPTIMISTIC CONCURRENCY CONTROL/ VALIDATION PROTOCOL In this protocol instead of using actual data, it is stored in a temporary variable then in the end after the validation and all it will pass the value to the original data then it gets permanently stored in the db
  • 27.
    This protocol isfollowed by 3 phases: ● Read phase :In this phase the actual data can be stored in a temporary variable ● Validation phase : After the validation and all it will check whether the transaction is serializable or not wrt to the temporary var. ● Write phase : If the validation state gets completed, the value in the temporary var will get stored permanently in the db, otherwise it will get rollback (when it fails)
  • 28.
    Each phase hasdifferent timestamps: Start : It contains the time when Ti starts the execution Validation : It contains the validation time when the read phase come to an end Finish: it contains the time when Ti finishes the write phase
  • 29.