Lock-based protocols in DBMS Theory - Time & Space Complexity
Lock-based protocols control access to data in databases to avoid conflicts.
We want to understand how the time to manage locks grows as more transactions run.
Analyze the time complexity of the following lock management process.
BEGIN TRANSACTION;
FOR each data item needed {
ACQUIRE lock on data item;
READ or WRITE data item;
RELEASE lock on data item;
}
COMMIT TRANSACTION;
This code shows a transaction acquiring and releasing locks on multiple data items sequentially.
Look for repeated actions that affect time.
- Primary operation: Acquiring and releasing locks for each data item.
- How many times: Once per data item accessed in the transaction.
As the number of data items accessed grows, the number of lock operations grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 lock acquire and 10 release operations |
| 100 | About 100 lock acquire and 100 release operations |
| 1000 | About 1000 lock acquire and 1000 release operations |
Pattern observation: The total lock operations increase directly with the number of data items accessed.
Time Complexity: O(n)
This means the time to manage locks grows linearly with the number of data items accessed in a transaction.
[X] Wrong: "Lock management time stays the same no matter how many data items are accessed."
[OK] Correct: Each data item needs its own lock operations, so more items mean more time spent managing locks.
Understanding how lock operations scale helps you explain database concurrency control clearly and confidently.
What if multiple transactions try to lock the same data items at the same time? How would that affect the time complexity?