 |
» |
|
|
 |
 |
 |

5.29 Describe lock strengths
Key points
- The strength of a lock refers to the number of other lock mode types
with which it is compatible. Stronger locks are less compatible with other
locks, and weaker locks are more compatible with other locks.
- The figure above shows the relative strength of all lock mode types. The
following chart summarizes the compatiblity of each type of lock:
Lock Mode | Compatible Locks | Total
-----------|------------------|-------
IS | IS, IX, S, SIX | 4
IX | IS, IX | 2
S | IS, S | 2
SIX | IS | 1
X | | 0
- IS locks are the weakest locks, and X locks are the strongest.
- A lock can be converted from a weaker lock into a stronger lock, but never the
reverse.
- S locks cannot be converted into IX locks, and IX locks cannot be converted
into S locks. Instead, the S or IX lock is converted into an SIX lock.
- Stronger locks do not take precedence over weaker locks that already exist on
a data object. A request for a new lock will not be granted until every
existing, incompatible lock held by other transactions is released. It makes
no difference whether the existing locks are stronger or weaker than the
requested lock.
- Lock mode strength is used in the following ways by ALLBASE/SQL:
- When several transactions are concurrently accessing the same data object,
each has been granted a lock on the object. ALLBASE/SQL has computed which
lock is the strongest, and has stored this information. When a new
transaction requests a lock on the data object, or when one of the existing
transactions tries to convert its existing lock to one that is stronger, the
requested lock mode type is compared to the strongest existing lock on the
data object. If the requested lock is compatible with the strongest lock, the
request is granted; otherwise, the requesting transaction must wait.
- A transaction does not need to acquire a new lock on a data object in either
of the following situations:
- The transaction already owns a lock on the data object, and the existing
lock is the same or stronger than the lock that is needed.
For example, if a transaction needs to read a row from a PUBLIC table, and it
has already been granted an X lock on the page when it previously updated a
different row on the page, the transaction does not need to obtain an S lock
on the page. The existing X lock is stronger than the S lock that is needed.
- The transaction already owns a lock at a higher granularity, and the
existing lock is the same or stronger than the lock that is needed.
For example, if a transaction has already been granted an SIX lock on a
PUBLICROW or PUBLIC table, it does not need to acquire an S row or page lock
when it reads a row. The SIX lock at the table level is stronger than the S
lock that is needed at the lower level. But if the transaction writes a row,
it does need to acquire an X row or page lock because the SIX lock at the
table level is not strong enough.

Page last updated on November 29, 1995
|
|
|