Bug #89127 Optimize trx_rw_is_active() by tracking the lowest active transaction id
Submitted: 7 Jan 2018 14:12 Modified: 29 Jan 2018 17:53
Reporter: zhai weixiang (OCA) Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[7 Jan 2018 14:12] zhai weixiang
While converting implicit lock to explicit lock,  the trx_rw_is_active is invoked to see if the transaction id stored in primary record is still active, and trx_sys->mutex is always acquired before searching via trx_id. But sometimes, we can avoid acquiring the mutex if the lowest active transaction id is smaller than the id on primary record.

If we always track the smallest transaction id in trx_sys->rw_trx_ids array, we can do a fast checking before acquiring mutex in function trx_rw_is_active

How to repeat:
Read the code 

Suggested fix:
Will upload a simple fix
[7 Jan 2018 14:13] zhai weixiang
a simple patch based on 8.0.3

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: low-active.diff (application/octet-stream, text), 2.08 KiB.

[8 Jan 2018 4:16] MySQL Verification Team
Hello Zhai Weixiang,

Thank you for the report and contribution.

[29 Jan 2018 17:53] Daniel Price
Posted by developer:
Fixed as of the upcoming 8.0.5, 9.0.0 release, and here's the changelog entry:

Converting an implicit lock to an explicit lock was optimized by the
introduction of a member variable that tracks the smallest active
transaction ID. 

Thanks to Zhai Weixiang for the patch.