Multiple granularity locking

In computer science, multiple granularity locking (MGL) is a locking method used in database management systems (DBMS) and relational databases.

MGL exploits the hierarchical nature of the contains relationship.

This protocol is shown in the following table: Determining what level of granularity to use for locking is done by locking the finest level possible (i.e., at the lowest leaf), and then escalating these locks to higher levels in the file hierarchy to cover more records or file elements as needed in a process known as "lock escalation".

MGL locking modes are compatible with each other as defined in the following matrix.

Following the locking protocol and the compatibility matrix, if one transaction holds a node in S mode, no other transactions can have locked any ancestor in X mode.