Concurrency Control
Concurrency Control
Introduction
• In a multi-user system, multiple users can access and use the same database at one
time, which is known as the concurrent execution of the database. It means that
the same database is executed simultaneously on a multi-user system by different
users.
• While working on the database transactions, there occurs the requirement of using
the database by multiple users for performing different operations, and in that
case, concurrent execution of the database is performed.
Introduction
• the simultaneous execution that is performed should be done in an interleaved
manner, and no operation should affect the other executing operations, thus
maintaining the consistency of the database. Thus, on making the concurrent
execution of the transaction operations, there occur several challenging problems
that need to be solved.
The conflict?
• DB operations are
• Read
• Write
• Concurrent access is quite easy if all users are just reading data. There
is no way they can interfere with one another. Though for any
practical Database, it would have a mix of READ and WRITE
operations and hence the concurrency is a challenge.
Potential problems of concurrency
• Lost Updates occur when multiple transactions select the same row and update
the row based on the value selected
• Uncommitted dependency issues occur when the second transaction selects a row
which is updated by another transaction (dirty read)
• Non-Repeatable Read occurs when a second transaction is trying to access the
same row several times and reads different data each time.
• Incorrect Summary issue occurs when one transaction takes summary over the
value of all the instances of a repeated data-item, and second transaction update
few instances of that specific data-item. In that situation, the resulting summary
does not reflect a correct result.
Lost Update problem(W-W Conflict)
• The problem occurs when two different database transactions perform the
read/write operations on the same database items in an interleaved manner (i.e.,
concurrent execution) that makes the values of the items incorrect hence making
the database inconsistent.
Lost Update Problem(w-w conflict)
• Consider the below diagram where two transactions TX and TY, are performed on
the same account A where the balance of account A is $300.
Dirty Read problem(W-R conflict)
• The dirty read problem occurs when one transaction updates an item of the
database, and somehow the transaction fails, and before the data gets rollback,
the updated database item is accessed by another transaction. There comes the
Read-Write Conflict between both transactions.
W-R Conflict
• Consider two transactions TX and TY in the below diagram performing read/write
operations on account A where the available balance in account A is $300:
Unrepeatable read problem(W-R conflict)
• Also known as Inconsistent Retrievals Problem that occurs when in a transaction,
two different values are read for the same database item.
Unrepeatable read problem
Incorrect summary problem
• Consider a situation, where one transaction is applying the aggregate function on
some records while another transaction is updating these records. The aggregate
function may calculate some values before the values have been updated and
others after they are updated.
• transaction 2 is calculating the sum of some
records while transaction 1 is updating them.
Therefore the aggregate function may
calculate some values before they have been
updated and others after they have been
updated.
Phantom Read
Why use concurrency methods
• Reasons for using Concurrency control method is DBMS:
• The system needs to control the interaction among the concurrent transactions. This
control is achieved using concurrent-control schemes.
Concurrency protocols
• Different concurrency control protocols offer different benefits between the
amount of concurrency they allow and the amount of overhead that they impose.
Following are the Concurrency Control techniques in DBMS:
• Lock-Based Protocols
• Two Phase Locking Protocol
• Timestamp-Based Protocols
• Validation-Based Protocols
Lock Based Protocol
• Lock Based Protocols in DBMS is a mechanism in which a transaction
cannot Read or Write the data until it acquires an appropriate lock.
• A lock is a data variable which is associated with a data item. This lock
signifies that operations that can be performed on the data item.
• Shared/exclusive: This type of locking mechanism separates the locks in DBMS based
on their uses. If a lock is acquired on a data item to perform a write operation, it is
called an exclusive lock.
Shared Lock (S):
A shared lock is also called a Read-only lock. With the shared lock, the data item can be shared between
transactions. This is because you will never have permission to update data on the data item.
• In this protocol, the local copies of the transaction data are updated rather
than the data itself, which results in less interference while execution of the
transaction.