Concurrency Control in DBMS: Locks, 2PL & Multiple Granularity With Examples

DBMS Chapter 23 · Concurrency Traffic Control
Concurrency Control in DBMS: Locks, 2PL & Multiple Granularity With Examples

Concurrency control is the set of techniques a DBMS uses to let many transactions run at the same time without producing incorrect results. Locking is one of the most important methods. Shared locks protect reads, exclusive locks protect writes, Two-Phase Locking (2PL) controls when locks are acquired and released, and multiple-granularity locking lets the DBMS lock large or small parts of the database using intention locks such as IS, IX and SIX. This chapter explains all of these ideas from zero with compatibility tables, solved schedules, a lock simulator and simple examples.

Locks from zero S / X compatibility Basic, strict & rigorous 2PL IS / IX / SIX Multiple granularity Checked: 19 September 2026
Quick answer first

What Is Concurrency Control in DBMS?

Concurrency Control in DBMS: Locks, 2PL & Multiple Granularity With Examples

Concurrency control manages simultaneous transactions so that the database remains correct even when transaction operations are interleaved. Its goal is to get the speed advantage of concurrent execution without problems such as lost updates, dirty reads and inconsistent results.

Many TransactionsT1, T2, T3 can run together.
Shared DataTransactions may access the same rows or pages.
Control RulesLocks, timestamps or MVCC coordinate access.
Correct ResultConcurrency should preserve required correctness.

Concurrency control is closely connected to Transactions & ACID Properties, Serializability in DBMS and Deadlock in DBMS.

Why control is needed

Problems Caused by Uncontrolled Concurrency

Lost UpdateOne transaction overwrites another transaction's update.
Dirty ReadA transaction reads data written by another transaction that has not committed.
Non-Repeatable ReadThe same row gives a different committed value when read again.
Phantom ReadA repeated condition query sees a different set of rows.
Concurrency is useful only when correctness is controlled.
Part 01 · locking

What Is a Lock in DBMS?

A lock is a control placed on a database item that restricts how other transactions can access that item while the lock is held.

A transaction normally requests an appropriate lock before reading or writing protected data. The lock manager checks whether that request is compatible with existing locks.

T1 requests lock on X
DBMS checks current lock table
If compatible -> grant
If incompatible -> T1 waits or another policy is applied
Two main lock modes

Shared Lock and Exclusive Lock

Shared Lock (S)

Used mainly for reading.

Several transactions can hold shared locks on the same item at the same time.

T1: S-lock(X)
T2: S-lock(X)

Allowed

Exclusive Lock (X)

Used when a transaction needs to modify an item.

An X lock conflicts with both S and X locks held by other transactions.

T1: X-lock(X)
T2: S-lock(X)

T2 must wait
S = read together · X = exclusive access for update
Basic compatibility

S and X Lock Compatibility Matrix

Existing LockRequested SRequested X
SYESNO
XNONO

Two readers can safely share the same item, but a writer needs exclusive access.

Interactive learning

Lock Compatibility Console

Select the lock already held and the lock another transaction wants. The tool shows whether the pair is compatible.

Existing lock

Requested lock

Compatible S with S is allowed because both transactions only need shared read access.
GRANT LOCK
Lock conversion

Lock Upgrade and Lock Downgrade

Upgrade

Change a weaker lock to a stronger lock.

S(X) -> X(X)

This is needed when a transaction first reads X and later decides to update X.

Downgrade

Change a stronger lock to a weaker lock.

X(X) -> S(X)

The transaction no longer needs exclusive write access but may still need to read X.

Under Two-Phase Locking, lock upgrades belong to the growing phase, while downgrades belong to the shrinking phase.

Part 02 · two-phase locking

What Is Two-Phase Locking (2PL)?

Two-Phase Locking is a concurrency-control protocol that divides a transaction's locking activity into a growing phase and a shrinking phase. It guarantees conflict serializability when transactions follow the protocol correctly.

Growing Phase

The transaction may acquire new locks and upgrade locks.

It must not release locks yet.

LOCK POINT

Shrinking Phase

The transaction may release locks and downgrade locks.

It must not acquire any new lock.

Before first unlock: locks can grow · After first unlock: no new locks
Lock point

What Is the Lock Point in 2PL?

The lock point is the moment when a transaction obtains its final lock. After this point, it eventually enters the shrinking phase and cannot acquire any new lock once unlocking begins.

Example:

LOCK-S(A)
LOCK-X(B)
READ(A)
WRITE(B)

Lock point occurs after LOCK-X(B)

UNLOCK(A)
UNLOCK(B)

The ordering of lock points is related to an equivalent serial order in 2PL-based schedules.

2PL variants

Basic, Conservative, Strict and Rigorous 2PL

Basic 2PL

Growing phase followed by shrinking phase.

Guarantees conflict serializability, but deadlocks can occur and cascading rollback is still possible.

Conservative / Static 2PL

The transaction obtains all required locks before it starts its main execution.

This prevents deadlock caused by lock waiting, but can reduce concurrency and requires knowing required locks in advance.

Strict 2PL

Follows 2PL and keeps all exclusive (X) locks until commit or abort.

This produces strict schedules and simplifies recovery by preventing other transactions from reading or overwriting uncommitted writes.

Rigorous 2PL

Keeps both shared and exclusive locks until commit or abort.

It is stronger than strict 2PL in lock-release timing.

Exam comparison

Basic 2PL vs Strict 2PL vs Rigorous 2PL

PointBasic 2PLStrict 2PLRigorous 2PL
Growing / shrinking ruleYesYesYes
Hold X locks until commit/abortNot requiredYesYes
Hold S locks until commit/abortNot requiredNot necessarilyYes
Conflict serializableYesYesYes
Deadlock possibleYesYesYes
Recovery friendlinessLowerHigherHigher
Solved 2PL example

2PL Schedule Example

Transaction T1 needs to read A and update B.

T1:
LOCK-S(A)
READ(A)

LOCK-X(B)
READ(B)
WRITE(B)

UNLOCK(A)
UNLOCK(B)
COMMIT

T1 acquires both locks before releasing its first lock. After UNLOCK(A), it does not request any new lock. So it follows Basic 2PL.

If T1 keeps its X lock on B until commit or abort, it can satisfy Strict 2PL.

2PL and serializability

Why Does 2PL Guarantee Conflict Serializability?

2PL prevents arbitrary lock acquisition after a transaction has begun releasing locks. This creates an ordering through transaction lock points.

The resulting precedence relationships cannot form a cycle if all transactions obey 2PL in the normal theoretical model. Therefore the schedule is conflict-serializable.

2PL -> conflict serializable, but 2PL does not mean deadlock-free

For precedence-graph logic, revise Conflict & View Serializability.

2PL and deadlock

Can Two-Phase Locking Cause Deadlock?

Yes. Normal 2PL can create deadlocks because one transaction may hold a lock and wait for another lock while another transaction does the opposite.

T1 holds X, waits for Y
T2 holds Y, waits for X

This is why DBMSs need deadlock detection, prevention or timeout policies even when 2PL is used.

Revise Deadlock Detection & Prevention in DBMS for wait-for graphs, wait-die and wound-wait.

Part 03 · multiple granularity

What Is Multiple Granularity Locking?

Multiple granularity locking allows the DBMS to lock data at different levels of a hierarchy, such as database, table, page and row. It balances lock-management cost with concurrency.

DatabaseLargest level
Table AMedium level
Table BMedium level
Page 1Smaller level
Page 2Smaller level
Page 3Smaller level
Row 101Fine-grained lock
Row 102Fine-grained lock
Granularity trade-off

Coarse-Grained vs Fine-Grained Locks

Coarse-Grained Lock

Locks a large object such as a whole table.

Advantage: fewer locks and lower lock-management overhead.

Disadvantage: less concurrency.

Fine-Grained Lock

Locks a smaller object such as a row.

Advantage: more transactions can work on different rows.

Disadvantage: more locks and more lock-management overhead.

Large lock = low overhead, low concurrency · Small lock = high overhead, high concurrency
Why intention locks exist

What Are Intention Locks?

Suppose T1 wants an X lock on one row of a table. Before another transaction locks the whole table, the DBMS needs a quick way to know that some lower-level object is already going to be locked.

Intention locks place information on higher levels of the hierarchy.

IS: Intention Shared The transaction intends to acquire shared locks on lower-level descendants.
IX: Intention Exclusive The transaction intends to acquire exclusive or mixed lower-level locks.
SIX: Shared + Intention Exclusive The transaction holds a shared lock on this node and intends to acquire exclusive locks on some descendants.
Full intention-lock matrix

Multiple Granularity Lock Compatibility Matrix

Existing / RequestedISIXSSIXX
ISYESYESYESYESNO
IXYESYESNONONO
SYESNOYESNONO
SIXYESNONONONO
XNONONONONO

This matrix is one of the most important things to revise for multiple-granularity locking questions.

Protocol rules

Multiple Granularity Locking Protocol Rules

Start from the rootA transaction first locks the root of the hierarchy in an appropriate mode.
For S or IS on a nodeThe parent should already be locked by the transaction in IS or IX mode.
For X, IX or SIX on a nodeThe parent should already be locked by the transaction in IX or SIX mode.
Follow 2PLMultiple-granularity locking is normally combined with the two-phase locking rule.
Unlock bottom-upA node should be unlocked only after the transaction has unlocked all of its locked children.
Solved hierarchy example

Example: Updating One Row Using Multiple Granularity

Suppose T1 wants to update Row 101 inside Table STUDENT.

Hierarchy:
Database
  -> STUDENT table
      -> Page 1
          -> Row 101

A simplified lock path can be:

Database: IX
STUDENT table: IX
Page 1: IX
Row 101: X

The IX locks on higher levels tell other transactions that T1 intends to obtain an exclusive lock somewhere below them.

To X-lock a small item, place IX intention locks on the path above it.
Read example

Example: Reading One Row

If T2 wants only a shared lock on Row 102:

Database: IS
STUDENT table: IS
Page 1: IS
Row 102: S

The IS locks announce that T2 intends to take shared locks lower in the hierarchy.

SIX example

When Is SIX Lock Useful?

Suppose a transaction needs to read an entire table but update only a few rows inside that table.

Instead of separately placing S on the table and IX on the same table, the DBMS can use:

SIX on the table

This means:

S partThe transaction can read the table as a shared-lock holder.
IX partIt may acquire X locks on selected lower-level descendants.
Lock escalation

What Is Lock Escalation?

Lock escalation replaces many fine-grained locks with one coarser lock when the DBMS decides that managing a large number of small locks is too expensive.

Example:

Before:
X locks on 5,000 individual rows

After escalation:
one X lock on the table

Benefit

Lower lock-table memory and lock-management overhead.

Cost

Lower concurrency because other transactions lose access to unrelated rows in the same table.

Phantom problem

Can Row Locks Prevent Every Concurrency Problem?

No. Row locks alone may not prevent a phantom problem.

Suppose T1 runs:

SELECT *
FROM students
WHERE marks > 90;

Another transaction may insert a new row with marks 95. If T1 repeats the query, a new matching row appears.

DBMSs can use techniques such as predicate locking, index-range locking or serializable isolation mechanisms to control this kind of problem.

Locks vs MVCC

Is Locking the Only Concurrency-Control Method?

No. Locking is one major method, but modern DBMSs can also use timestamp ordering, optimistic methods and Multi-Version Concurrency Control (MVCC).

LockingTransactions may wait when incompatible locks exist.
Timestamp OrderingTransactions follow timestamp-based ordering rules.
Optimistic ControlTransactions proceed with fewer waits and validate before commit.
MVCCMultiple versions can let readers and writers interfere less.
Concurrency control vs deadlock

Why Locking Can Create Deadlock

Locks protect correctness, but waiting for locks creates a new risk.

T1:
X-lock(A)
wait for B

T2:
X-lock(B)
wait for A

The two transactions are now in a deadlock cycle.

Locks improve correctness, but incompatible waiting can create deadlock.
Concurrency control vs recovery

Why Strict 2PL Helps Database Recovery

Strict 2PL keeps exclusive locks until commit or abort. Therefore another transaction cannot read or overwrite the uncommitted value written by the current transaction.

This reduces cascading rollback and gives the DBMS a simpler recovery situation.

For logs, checkpoints, UNDO and REDO, revise Recoverability & Database Recovery in DBMS.

Solved compatibility example

Solved Lock Compatibility Example

Suppose Table STUDENT already has an IX lock held by T1.

Can T2 request IS on STUDENT?

Yes. IX and IS are compatible because T1 may update some descendants while T2 intends only to read some descendants.

Can T2 request S on STUDENT?

No. A full shared table lock would conflict with T1's intention to acquire exclusive descendant locks.

Can T2 request IX on STUDENT?

Yes. Both transactions can intend to update different lower-level descendants, although they may later conflict on the same child item.

Common mistakes

Concurrency Control Mistakes to Avoid

Thinking S means only one readerMultiple S locks can coexist on the same item.
Thinking X is compatible with SX conflicts with both S and X from other transactions.
Acquiring a new lock after unlocking in 2PLThat breaks the two-phase rule.
Thinking 2PL is deadlock-freeBasic, strict and rigorous 2PL can still deadlock.
Confusing strict and rigorous 2PLStrict holds X locks; rigorous holds both S and X locks until commit/abort.
Ignoring intention locksThey are required to coordinate different hierarchy levels efficiently.
Thinking IX means the node itself is X-lockedIX means intention to take exclusive locks lower in the hierarchy.
Confusing 2PL with 2PC2PL is locking for concurrency; 2PC is atomic commit across distributed sites.
Write according to marks

How to Write Concurrency Control in Semester Exams

2 marks

Definition

Define concurrency control, S/X lock or Two-Phase Locking in two clear lines.

5 marks

Protocol answer

Explain S/X compatibility and growing/shrinking phases, or explain IS, IX and SIX.

8-10 marks

Full answer

Cover locking, compatibility matrix, 2PL variants, deadlocks, multiple granularity, hierarchy rules and one solved example.

For answer presentation, use How to Write High-Scoring Answers in University Semester Exams. For revision priority, use the previous-year-paper method.

Practice questions

Practice Questions With Answers

1. What is concurrency control in DBMS?

Concurrency control coordinates simultaneous transactions so that interleaved execution does not produce incorrect database results.

2. What is a shared lock?

A shared lock is mainly used for reading. Multiple transactions can hold shared locks on the same item at the same time.

3. What is an exclusive lock?

An exclusive lock is used for updating data. It conflicts with shared and exclusive locks held by other transactions on the same item.

4. What is Two-Phase Locking?

2PL divides locking into a growing phase, where locks are acquired, and a shrinking phase, where locks are released and no new locks may be acquired.

5. Does 2PL guarantee serializability?

Yes. Proper Two-Phase Locking guarantees conflict serializability.

6. Does 2PL prevent deadlocks?

No. Basic, strict and rigorous 2PL can still produce deadlocks. Conservative 2PL avoids deadlock by acquiring all required locks before execution.

7. What is strict 2PL?

Strict 2PL follows the two-phase rule and keeps all exclusive locks until the transaction commits or aborts.

8. What is multiple granularity locking?

It is a locking approach that allows data to be locked at different hierarchy levels such as database, table, page and row.

9. What are intention locks?

Intention locks are higher-level locks that announce plans to acquire locks on lower-level descendants. Common modes are IS, IX and SIX.

10. What should I study after locking and 2PL?

Study timestamp ordering, optimistic concurrency control, MVCC, isolation levels and advanced deadlock handling.

60-second revision

Concurrency Control One-Minute Revision Sheet

Concurrency ControlKeeps simultaneous transactions correct.
S LockShared read lock.
X LockExclusive update lock.
2PLGrowing phase then shrinking phase.
Lock PointMoment transaction obtains its final lock.
Strict 2PLHold X locks until commit/abort.
Rigorous 2PLHold S and X locks until commit/abort.
Multiple GranularityLock database, table, page or row.
ISIntend shared locks below.
IXIntend exclusive locks below.
SIXS on node + IX below.
Lock EscalationReplace many fine locks with a coarser lock.

Ultimate memory line

Locks control access · 2PL controls timing · intention locks control hierarchy
Frequently asked questions

Frequently Asked Questions

What is concurrency control in DBMS in simple words?

Concurrency control is the set of rules a DBMS uses to let multiple transactions run together without corrupting or incorrectly mixing their results.

What is the difference between shared and exclusive locks?

A shared lock allows multiple readers, while an exclusive lock is used for updates and conflicts with other shared or exclusive locks on the same item.

What is 2PL in DBMS?

Two-Phase Locking is a protocol with a growing phase for acquiring locks and a shrinking phase for releasing locks.

What is strict 2PL?

Strict 2PL keeps all exclusive locks until commit or abort, helping produce strict schedules and simplifying recovery.

What is multiple granularity locking?

Multiple granularity locking lets the DBMS lock data at hierarchy levels such as database, table, page and row while coordinating those levels with intention locks.

What are IS, IX and SIX locks?

IS means intention shared, IX means intention exclusive, and SIX means shared on the current node plus intention exclusive on lower-level descendants.

Next chapter

What Should You Learn Next?

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Join Telegram Exam updates and free resources