Open In App

Multiple Granularity Locking in DBMS

Last Updated : 02 Aug, 2025
Comments
Improve
Suggest changes
24 Likes
Like
Report

Granularity refers to the size of the data item on which a lock is applied. Multiple Granularity Locking introduces a hierarchical structure, where locks can be applied at various levels (e.g., database, file, record) to balance efficiency and concurrency.

Granularity Hierarchy

A typical hierarchy can be visualized as a tree:

Database
└── Area
└── File
└── Record

  • Database: the entire DB
  • Area: logical sections
  • File: groups of records
  • Record: individual data entries

A transaction can lock any node, and doing so implicitly locks all of its descendants.


Multi Granularity Tree
Multi Granularity tree Hiererchy


How It Works

  • If a transaction locks a file in exclusive (X) mode, it implicitly holds an exclusive lock on all its records.
  • This differs from traditional tree locking because you don’t have to lock each child explicitly.

Example: If T1 locks file Fc in exclusive mode, it doesn’t need to lock each record in Fc they're automatically locked.

Intention Mode Lock

To support hierarchical locking, new intention lock modes are introduced alongside Shared (S) and Exclusive (X):

  • Intention-Shared (IS): explicit locking at a lower level of the tree but only with shared locks.
  • Intention-Exclusive (IX): explicit locking at a lower level with exclusive or shared locks.
  • Shared & Intention-Exclusive (SIX): the subtree rooted by that node is locked explicitly in shared mode and explicit locking is being done at a lower level with exclusive mode locks.

The compatibility matrix for these lock modes are described below: 

Multi Granularity Tree hierarchy
Multi Granularity tree Hierarchy

Locking Protocol Rules

A transaction Ti must follow these rules:

  1. Lock the root first (in any mode).
  2. To acquire S or IS, parent must be locked in IS/IX.
  3. To acquire X, IX, or SIX, parent must be locked in IX or SIX.
  4. Locks must be acquired top-down (root to leaf).
  5. Locks must be released bottom-up (leaf to root).
  6. A node can be unlocked only after all its children are unlocked.
  7. Transactions must follow the 2-Phase Locking (2PL) protocol

Observe that the multiple-granularity protocol requires that locks be acquired in top-down (root-to-leaf) order, whereas locks must be released in bottom-up (leaf to-root) order. 

As an illustration of the protocol, consider the tree given above and the transactions: 

  • Say transaction T1 reads record Ra2 in file Fa. Then, T1 needs to lock the database, area A1, and Fa in IS mode (and in that order), and finally to lock Ra2 in S mode.
  • Say transaction T2 modifies record Ra9 in file Fa . Then, T2 needs to lock the database, area A1, and file Fa (and in that order) in IX mode, and at last to lock Ra9 in X mode.
  • Say transaction T3 reads all the records in file Fa. Then, T3 needs to lock the database and area A1 (and in that order) in IS mode, and at last to lock Fa in S mode.
  • Say transaction T4 reads the entire database. It can do so after locking the database in S mode.

Note: Transactions T1, T3 and T4 can access the database concurrently. Transaction T2 can execute concurrently with T1, but not with either T3 or T4

This protocol enhances concurrency and reduces lock overhead. Deadlock is still possible in the multiple-granularity protocol, as it is in the two-phase locking protocol. These can be eliminated by using certain deadlock elimination techniques.

Suggested Quiz
5 Questions

What is the purpose of introducing intention lock modes in multiple granularity locking?

  • A

    To lock leaf nodes directly

  • B

    To prevent access to certain transactions

  • C

    To avoid searching the entire tree for conflicts

  • D

    To improve query execution speed

Explanation:

Intention locks help the DBMS determine potential conflicts without scanning the entire tree , making the system more efficient.

Which of the following is not a valid intention lock mode?

  • A

    IS (Intention-Shared)

  • B

    IX (Intention-Exclusive)

  • C

    SIX (Shared & Intention-Exclusive)

  • D

    SX (Shared-Exclusive)

Explanation:

SX is not a valid lock mode. The correct intention lock modes are IS , IX , and SIX

Which of the following is true about the use of Intention Locks in Multiple Granularity Locking?

  • A

    Intention locks are used to directly access data records without locking higher levels

  • B

    Intention locks allow a transaction to bypass the lock compatibility matrix

  • C

    Intention locks indicate a transaction’s intention to acquire locks at lower levels

  • D

    Intention locks are only used in two-phase locking without hierarchies

Explanation:

Intention locks (IS, IX, SIX) signal a transaction’s intention to acquire specific types of locks on lower-level nodes in a hierarchy.

Which of the following ensures that locks are released in the correct order in MGL?

  • A

    Locks are released randomly

  • B

    Locks must be released top-down

  • C

    Locks are released in bottom-up (leaf to root) order

  • D

    Locks are released immediately after use

Explanation:

In Multiple-Granularity Locking (MGL):

  • Locks are acquired top-down (from root → leaf).
  • Locks must be released bottom-up (from leaf → root).

This ordering prevents violations of the locking protocol and ensures consistency and serializability in hierarchical locking structures.

If transaction T3 reads all records in file Fa, which of the following lock sequence is correct?

  • A

    Lock database (S), lock Fa (S)

  • B

    Lock Fa (S) only

  • C

    Lock database (IS), area A1 (IS), Fa (S)

  • D

    Lock database (IX), area A1 (IX), Fa (X)

Explanation:

The correct lock sequence is Lock database (IS), area A1 (IS), Fa (S).

In Multiple Granularity Locking (MGL), when a transaction reads an entire file (shared access), it must:

  1. Acquire Intent-Shared (IS) locks on higher levels (database, area) to signal potential shared locks below.
  2. Acquire a Shared (S) lock on the target file (Fa) for read access.

The other options fail because:

  • Lock database (S), lock Fa (S) is overly restrictive (unnecessarily locks the entire database).
  • Lock Fa (S) only violates MGL hierarchy (missing IS locks on parents).
  • Lock database (IX), area A1 (IX), Fa (X) incorrectly uses exclusive locks for a read-only operation.

Answer: Lock database (IS), area A1 (IS), Fa (S)

Quiz Completed Successfully
Your Score :   2/5
Accuracy :  0%
Login to View Explanation
1/5 1/5 < Previous Next >

Explore