Concurrency control deals with interleaved execution of more than one transaction on a shared database. Interleaving increases system throughput and resource utilisation but may produce incorrect results unless controlled. This chapter explains transactions, schedules, serializability, anomalies, recovery-related schedule properties and the main concurrency-control protocols used in practice.
A transaction is a sequence of logically related database operations that must be executed as a unit to preserve database consistency. Typical low-level operations used to describe transactions are:
Note: A write operation in a transaction often updates a buffer first; the buffer may not be flushed to disk immediately. This is why dirty read anomalies can occur unless the concurrency protocol prevents them.
Example - a simple debit transaction on account A:
If A = 5000 initially, the sequence yields A = 4000 after W(A). If the transaction fails before W(A), the database still holds A = 5000; recovery or roll-back must ensure atomic behaviour.
Transactions are characterised by the ACID properties. Each is essential to maintain correctness in multi-user environments.
A schedule is an interleaving (sequence) of operations from a set of transactions. Schedules describe the order in which operations of concurrent transactions are executed by the DBMS.
Consider T1: debit Rs.1000 from A and T2: credit Rs.500 to A, with initial A = 5000.
Final value 5500 shows T1's effect was lost. This inconsistency must be prevented by concurrency control protocols.
Table 1 Some schedule classes are defined to ensure recoverability and avoid undesirable cascaded aborts. These properties are important when devising concurrency control mechanisms.
Serializability is the principal correctness criterion for concurrent schedules. A concurrent schedule is correct if its outcome is equivalent to some serial execution of the same transactions.
To test conflict serializability construct a precedence graph (also called a conflict graph):
Given a schedule S, identify all read/write and write/write conflicts and build the graph. If a cycle exists, S is not conflict serialisable.
Database textbooks list canonical anomalies to classify concurrency problems. Some important ones are:
Several protocols enforce serialisability (or weaker guarantees) while allowing concurrent execution. The most commonly used are locking protocols, timestamp ordering, and optimistic (validation) concurrency control.
Locking is the most widely used technique. Two basic lock modes are:
Transactions must acquire locks before accessing data and release them later according to the locking protocol.
Two-phase locking (2PL) enforces serialisability by forcing each transaction to operate in two phases:
When all transactions follow 2PL, schedules are guaranteed to be conflict serialisable.
Locking can cause deadlock, where two or more transactions wait forever for locks held by each other. Common approaches to handle deadlocks:
To allow locking at different granularities (database, table, page, row), DBMSs use intention locks (e.g., IS, IX) to indicate that a transaction intends to acquire finer-grained locks. Multi-granularity locking protocols enable concurrency control efficiently over large data structures.
Timestamp ordering assigns each transaction a unique timestamp when it starts. The protocol ensures the execution order is consistent with timestamp order using read and write timestamps associated with each data item. If an operation violates timestamp order, either the operation is aborted or the write may be discarded based on rules.
Thomas's write rule: An optimisation for timestamp ordering that allows ignoring obsolete writes (if a write is older than the last read by a newer transaction) without aborting the writing transaction. This can increase concurrency while preserving serialisability under certain conditions.
Optimistic methods allow transactions to execute without restrictions and validate at commit time whether serialisability would be violated. Typical validation has three phases:
Optimistic methods work well for workloads with low conflict rates.
Consider three transactions Ti, Tj and Tk where Tj reads a value written by Ti and Tk reads a value written by Tj. If Ti aborts, both Tj and Tk may need to be rolled back if they had read uncommitted values - this is a cascading abort. Cascadeless and strict schedules prevent such chains and simplify recovery.
When choosing a concurrency control strategy DBMS designers trade off between:
Most commercial DBMSs use variants of locking (strict or rigorous 2PL) with deadlock detection; some systems use MVCC (multi-version concurrency control) which combines timestamp ideas to provide high concurrency for read-heavy workloads.
Q. Consider the following transaction involving two bank accounts x and y:
1. read(x);
2. x := x - 50;
3. write(x);
4. read(y);
5. y := y + 50;
6. write(y);
The constraint that the sum of the accounts x and y should remain constant is that of?
(a) Atomicity
(b) Consistency
(c) Isolation
(d) Durability
Ans: (b)
Solution: As discussed in properties of transactions, consistency properties says that sum of accounts x and y should remain constant before starting and after completion of transaction. So, the correct answer is B.
This chapter presented transactions and schedules, explained why concurrent execution needs careful control, and defined serialisability as the main correctness criterion. It introduced conflict and view serialisability, the precedence-graph test, recoverability/cascading/strict schedules, and the major concurrency control families: locking (2PL variants), timestamp ordering (and Thomas's rule), and optimistic validation. Practical DBMS design chooses protocols based on workload characteristics, recovery needs and desired concurrency.
62 videos|101 docs|35 tests |
| 1. What is concurrency control in DBMS? | ![]() |
| 2. Why is concurrency control important in DBMS? | ![]() |
| 3. What are the different types of concurrency control techniques in DBMS? | ![]() |
| 4. How does two-phase locking (2PL) work as a concurrency control technique in DBMS? | ![]() |
| 5. What is optimistic concurrency control in DBMS? | ![]() |