MySQL 9.1.0
Source Code Documentation
|
To expose DATA_LOCKS to the performance schema, a storage engine needs to:
While the storage engine is in use (between init and deinit), the performance schema keeps a reference to the data lock inspector given, and use it to inspect the storage engine data locks.
When the server performs a SELECT * from performance_schema.data_locks, the performance schema creates a PSI_server_data_lock_container for the duration of the table scan.
Then, the scan loops for each storage engine capable of exposing data locks (that is, engines that registered a data lock inspector).
For each engine, the inspector is called to create an iterator, dedicated for this SELECT scan.
When table_data_locks::rnd_next() is first called, the performance schema calls the storage engine iterator, which adds N rows in the data container.
Upon subsequent calls to table_data_locks::rnd_next(), data present in the container is returned. This process loops until the storage engine iterator finally reports that it reached the end of the scan.
Note that the storage engine iterator has freedom to implement:
The major benefit of this interface is that the engine iterator can stop and restart a scan at natural boundaries within the storage engine (say, return all the locks for one transaction per call), which simplifies a lot the storage engine implementation.