|
Please see my questions/challenges below ---
A key value lock is a lock on a unique index key value that we get when deleting/updating a unique key when the DB2_RR_TO_RS registry variable is set. This registry variable disables next key locking, which is the standard technique DB2 uses to ensure that deleted keys are waited upon for both scans and inserts. Next key locking traditionally causes lock wait and deadlock scenarios. The registry variable was created back in V2 for SAP to disable next key locking on non-catalog tables and instead implemented key value locking to guarantee uniqueness for unique indexes.
--- so key value lock is actually a real key lock in DB2! but if it's a derivation from ARIES/KVL algorithm, key value lock should apply to unique/non-unique indexes, not just unique one! Besides, as what you said, even I set the DB2_RR_TO_RS to YES, I still can not see any key value lock(KVL), except row lock in key row.
--- 'Next key locking' is a must use method in ARIES/IM/KVL if RR is required, I think DB2_RR_TO_RS registry variable is only for lowering down the isolation level from serializable(RR) to less restricted level (RS) but in the cost of lossing the semantic transaction isolation. (it will allow the phantom inserts)
For a unique index, say we delete the key with value 1 but do not commit. Another transaction comes in and wants to insert key value 1. With next key locking the delete would have locked the next key above 1 (say 2), and the insert would have to lock the next key above 1 (thus waiting for the lock on 2 to see if there is or isn't a value of 1 already as the first transaction can either commit or rollback the delete.
--- I agree with this, it is how the next key locking works behind the sence. But is this happen only for unique index?
With next key locking disabled, the insert of 1 cannot occur until we know the status of the delete of 1. The key value lock is a hash of the unique key value. The delete acquires this lock in X mode. An insert will wait for lock (similar to how it would have with next key locking) in order to see the uncommitted status of the possible delete.
--- can next key locking(NKL) really be disabled in DB2? I knew the SQL server make use of Key Range Locking(KRL), which let them overcome some of weakness of next key locking and enable them to get better transaction concurrency. but without any improvement in ARIES algorithm. can db2 simply bypass next key locking?
--- what you said here is looked like the benefit of type-2 index in v8 gave out, but have nothing to do with key value locking. can you give out an example? |
|