Back to course home
0% completed
Vote For New Content
📚 Use Case: Why Do We Need Intention Locks?
Parth Sorathiya
May 5, 2025
Without intention locks, if one transaction acquires a row-level exclusive lock, and another transaction wants to acquire a table-level shared lock, the DBMS wouldn’t know whether that table-level lock would conflict — unless it scanned every row. This is inefficient.
🔧 Intention Locks Solve This:
They allow hierarchical locking while preserving compatibility and efficiency.
🧠 Example: How Intention Locks Work
Let’s say we have a table Employees, and a transaction wants to:
🔹 Transaction T1:
- Acquire exclusive lock on a row (e.g., row 5).
It will first:
- Place an IX lock on the table
Employees. - Then place an X lock on row 5.
🔹 Transaction T2:
- Wants a shared lock on the entire table (to read all rows safely).
It requests:
- An S lock on the table.
❌ Conflict Detected:
- T2’s S lock is not compatible with T1’s existing IX lock, so T2 must wait.
This avoids:
- T2 thinking it's safe to read the table while T1 is modifying a row.
- Dirty reads or inconsistent views of the data.
0
0
Comments
Comments
On this page