45 Lecture

CS403

Midterm & Final Term Short Notes

Locking Idea

Locking is a concurrency control mechanism that is used to prevent conflicting access to shared resources in a database management system. It works by acquiring a lock on a resource, which prevents other transactions from accessing or modifying


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is locking in a database management system? a. A mechanism to prevent transactions from accessing shared resources b. A mechanism to prevent transactions from accessing only exclusive resources c. A mechanism to allow transactions to access shared resources simultaneously d. A mechanism to allow transactions to access exclusive resources simultaneously Answer: a Which of the following is not a type of lock? a. Shared lock b. Exclusive lock c. Read lock d. Write lock Answer: c What is the purpose of a shared lock? a. To allow multiple transactions to read the same resource simultaneously b. To prevent multiple transactions from reading the same resource simultaneously c. To allow multiple transactions to write to the same resource simultaneously d. To prevent multiple transactions from writing to the same resource simultaneously Answer: a What is the purpose of an exclusive lock? a. To allow multiple transactions to read the same resource simultaneously b. To prevent multiple transactions from reading the same resource simultaneously c. To allow multiple transactions to write to the same resource simultaneously d. To prevent multiple transactions from writing to the same resource simultaneously Answer: d What is a deadlock? a. A situation where two or more transactions are waiting for each other to release locks b. A situation where a transaction is waiting for a lock that is held by another transaction c. A situation where a transaction is waiting for a lock that has already been released d. A situation where a transaction is waiting for a resource that is not available Answer: a What is a timeout in locking? a. A mechanism to release a lock after a specified time period b. A mechanism to acquire a lock after a specified time period c. A mechanism to prevent a transaction from acquiring a lock d. A mechanism to prevent a transaction from releasing a lock Answer: a What is the purpose of lock escalation? a. To reduce the number of locks held by a transaction b. To increase the number of locks held by a transaction c. To release all locks held by a transaction d. To prevent a transaction from acquiring any locks Answer: a What is the difference between a shared lock and an exclusive lock? a. A shared lock allows multiple transactions to read the same resource, while an exclusive lock prevents multiple transactions from writing to the same resource simultaneously b. A shared lock allows multiple transactions to write to the same resource simultaneously, while an exclusive lock prevents multiple transactions from reading the same resource simultaneously c. A shared lock allows multiple transactions to access the same resource simultaneously, while an exclusive lock prevents any other transactions from accessing the resource until the lock is released d. A shared lock allows a transaction to access a resource exclusively, while an exclusive lock allows multiple transactions to access the same resource simultaneously Answer: c What is the purpose of lock granularity? a. To determine the size of the resource that will be locked b. To determine the type of lock that will be used c. To determine the duration of the lock d. To determine the transaction that will hold the lock Answer: a What is the purpose of a lock manager in a database management system? a. To manage the acquisition and release of locks b. To manage the execution of transactions c. To manage the storage of data d. To manage the retrieval of data Answer: a


Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is locking and how does it work in a database management system? Answer: Locking is a mechanism used in a database management system to prevent concurrent access to shared resources by multiple transactions. It works by granting exclusive access to a resource to a transaction, and then releasing the lock when the transaction is complete. What is the difference between shared and exclusive locks? Answer: A shared lock allows multiple transactions to access a resource simultaneously for read-only purposes, while an exclusive lock allows only one transaction to access the resource for write purposes. How can a deadlock occur in a locking mechanism? Answer: A deadlock occurs when two or more transactions are waiting for each other to release the locks they are holding, resulting in a circular wait that cannot be resolved. What is lock granularity and why is it important? Answer: Lock granularity is the size of the resource that will be locked by a transaction. It is important to determine the appropriate level of granularity to ensure efficient use of resources and prevent excessive locking. What is lock escalation and how does it work? Answer: Lock escalation is the process of converting a large number of low-level locks into a smaller number of higher-level locks to reduce the overhead associated with managing locks. It works by releasing lower-level locks and acquiring higher-level locks when the number of locks held by a transaction exceeds a threshold. What is a timeout in locking and how is it used? Answer: A timeout is a mechanism used to release a lock after a specified time period to prevent a transaction from waiting indefinitely for a resource. It is used to ensure that transactions do not get stuck waiting for a resource that may never become available. What is a lock manager and what is its role in a database management system? Answer: A lock manager is a component of a database management system that manages the acquisition and release of locks. Its role is to ensure that transactions have access to the resources they need while preventing conflicts between transactions. How does locking impact database performance? Answer: Locking can impact database performance by introducing overhead associated with managing locks and waiting for resources. It is important to optimize locking to minimize the impact on performance. What are some common locking strategies used in database management systems? Answer: Some common locking strategies include optimistic locking, pessimistic locking, two-phase locking, and multi-version concurrency control. What are some best practices for implementing locking in a database management system? Answer: Some best practices include minimizing the size and duration of locks, optimizing lock granularity, implementing lock escalation, using timeouts, and minimizing the number of conflicts between transactions.

Locking is a technique used in database management systems to control concurrent access to shared resources by multiple transactions. It ensures that transactions access resources in a mutually exclusive manner to prevent conflicts and data inconsistency. There are two types of locks: shared locks and exclusive locks. Shared locks allow multiple transactions to access a resource simultaneously for read-only purposes, while exclusive locks allow only one transaction to access the resource for write purposes. Locks can be granted at various levels of granularity, from row-level locks to table-level locks. One of the challenges with locking is the potential for deadlocks, where two or more transactions are waiting for each other to release the locks they are holding. To avoid deadlocks, lock managers implement timeout mechanisms, which release locks after a specified time period. Lock escalation is another technique used to minimize the number of locks held by a transaction. It involves releasing lower-level locks and acquiring higher-level locks when the number of locks held by a transaction exceeds a threshold. This reduces the overhead associated with managing locks and improves performance. Optimistic locking is another approach to minimizing conflicts between transactions. It assumes that conflicts are rare and allows transactions to proceed without acquiring locks. When a transaction wants to update a resource, it checks if the resource has been modified by another transaction since it last accessed it. If there is a conflict, the transaction is rolled back and restarted. Pessimistic locking, on the other hand, assumes that conflicts are common and acquires locks before a transaction accesses a resource. This approach can result in higher lock overhead but reduces the potential for conflicts. In summary, locking is a critical technique used to ensure data consistency and prevent conflicts in a database management system. The appropriate locking strategy depends on the specific requirements of the application and the level of contention for shared resources.