Internal logic has been improved in an internal cleanup routine related to key-level locks. When it is recognized that all the key-level locks in the node belong to the calling thread for the current transaction, cleanup overhead is avoided for these key-level locks. This improves the performance of large transactions that repeatedly add/visit key values during the transaction because unnecessary attempts to cleanup pending key-level locks for the same transaction are no longer attempted.