As noted in MDEV-21423, InnoDB is unnecessarily performing full traversal of the lock-free trx_sys.rw_trx_hash when enforcing locks on secondary indexes.
Apart from some recovery code, there are two sources of trx_sys.rw_trx_hash traversal, which will be affected by MDEV-20630:
- cloning a read view
- in trx_sys.snapshot_ids() executed via ReadViewBase::snapshot() and ReadView::open()
- in trx_sys.clone_oldest_view() executed via purge_sys.clone_oldest_view()
- determining the minimum transaction identifier in any read view
I created something similar, replacing trx_sys.get_min_trx_id() with trx_sys.find_same_or_older(). I expect it to improve performance of operations that involve secondary indexes. The new hash table traversal trx_sys.find_same_or_older() employs short circuit evaluation, in a strictly read-only operation (not even acquiring any mutex).
This change did not affect performance (for the better or worse) in axel's benchmark test battery, so I do not think that we can claim that this cleanup fixes MDEV-21423. Nevertheless, I think that the cleanup is useful and it could benefit some other types workloads, possibly with more conflicts between secondary index record locks.