Since read operations cannot conflict, it is permissible for more than one transaction to
hold shared locks simultaneously on the same item. On the other hand, an exclusive lock
gives a transaction exclusive access to that item. Thus, as long as a transaction holds the
exclusive lock on the item, no other transactions can read or update that data item. Locks
are used in the following way:
n Any transaction that needs to access a data item must first lock the item, requesting a
shared lock for read only access or an exclusive lock for both read and write access.
n If the item is not already locked by another transaction, the lock will be granted.
n If the item is currently locked, the DBMS determines whether the request is compatible
with the existing lock. If a shared lock is requested on an item that already has a shared
lock on it, the request will be granted; otherwise, the transaction must wait until the
existing lock is released.
n A transaction continues to hold a lock until it explicitly releases it either during execution
or when it terminates (aborts or commits). It is only when the exclusive lock has been
released that the effects of the write operation will be made visible to other transactions.
In addition to these rules, some systems permit a transaction to issue a shared lock on
an item and then later to upgrade the lock to an exclusive lock. This in effect allows a
transaction to examine the data first and then decide whether it wishes to update it. If
upgrading is not supported, a transaction must hold exclusive locks on all data items that
it may update at some time during the execution of the transaction, thereby potentially
reducing the level of concurrency in the system. For the same reason, some systems also
permit a transaction to issue an exclusive lock and then later to downgrade the lock to a
shared lock.
Using locks in transactions, as described above, does not guarantee serializability of
schedules by themselves, as Example 20.5 shows.