MySQL 8.0.37
Source Code Documentation
|
Innodb Performance Schema data lock instrumentation
To provide content to the performance_schema.data_locks table, innodb implements Innodb_data_lock_iterator.
Likewise, table performance_schema.data_wait_locks is populated with Innodb_data_lock_wait_iterator.
Both these iterators need to return the data present in the innodb engine memory, which imply to take the proper mutex locks when inspecting it. The structure to inspect here is the transaction list (trx_sys)
How to implement this scan is critical for performances.
Consider this implementation:
This implementation materializes the entire table.
The benefits with this approach are:
The problems with this approach are:
For example with N = 10,000 transactions, a single scan reports all 10,000 transaction locks.
This alternative is rejected.
Consider this implementation:
This implementation returns a row for a single transaction, or even a single lock, at a time.
The benefits with this approach are:
The problems with this approach are:
For example with N = 10,000 transactions, the trx_list would be scanned 10,000 times to return 1 record each time. The total number of operations on the list is 100 Millions.
This alternative is rejected.
What is implemented is:
This is a compromise, with the following properties:
For example with N = 10,000 transactions and RANGE = 256, there are 40 batches at the trx list, where each batch reports (up to) 256 trx, with the trx locks. The total number of operations on the list is 400 thousands.