When an InnoDB transaction is about to update a record, two steps will be performed before the modification of the clustered index tree can start:
- the transaction must be able to acquire an exclusive lock on the record
- writing an undo log record for rolling back the operation must succeed
This bug is about the undo log processing. We can get to that phase only if the record was last modified by a committed transaction.
In the scenario of this bug, that committed transaction would still exist in the system in the purge queue, and the record would still carry a nonzero DB_TRX_ID.
If the old transaction is purgeable, then we should write DB_TRX_ID=0 to the undo log record, so that in case our transaction is rolled back, the history will be reset at rollback.
TODO: Write a test case for this scenario.
If the old transaction is accessible in some transaction’s read view, then we must write the old DB_TRX_ID,DB_ROLL_PTR to the undo log record, so that the other read views can still correctly reach the correct old version of the record.
The following test patch demonstrates that currently, the DB_TRX_ID will never be reset:
With this change to the test, the DB_TRX_ID,DB_ROLL_PTR will not be reset by purge.