Hi Kristian, Sorry for the late reply. On Wed, Aug 9, 2023 at 4:25 PM Kristian Nielsen <knielsen@knielsen-hq.org> wrote:
I assume this is because it's cheaper to roll back the current transaction, than to mark another transaction as the victim, go to sleep, and then wake back up once the other transaction(s) has released the lock waited for?
Yes, definitely, rolling back the current transaction is easier and should be preferred. Actually, some time ago we tried to simplify the asynchronous rollback in https://jira.mariadb.org/browse/MDEV-29860 but in the end, decided against it.
I refined my patch with bitwise operations to keep using a single comparison between weights in the cycle loop. I use the top bit for the thd_deadlock_victim_preference() and the lowest bit to prefer the current transaction over another with same weight.
This makes sense, thank you. For the non-HAVE_REPLICATION code path, I might have defined the dummy variables victim_not_pref, next_not_pref as constexpr. But, the oldest compiler that I found on godbolt.org (GCC 4.1.2) is able to optimize away the bitwise OR with a non-const variable that is 0, starting with -O1. The oldest compiler that we aim to support is GCC 4.8.5. Marko -- Marko Mäkelä, Lead Developer InnoDB MariaDB plc