Multiple Granularity Locking in DBMS (original) (raw)

Last Updated : 2 Aug, 2025

Granularity refers to the size of the data item on which a lock is applied. Multiple GranularityLocking 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

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

**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):

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:

**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.