Pre-General Availability Draft: 2017-09-22
The Performance Schema exposes metadata lock information
Locks that have been granted (shows which sessions own which current metadata locks)
Locks that have been requested but not yet granted (shows which sessions are waiting for which metadata locks).
Lock requests that have been killed by the deadlock detector or timed out and are waiting for the requesting session's lock request to be discarded
This information enables you to understand metadata lock dependencies between sessions. You can see not only which lock a session is waiting for, but which session currently holds that lock.
Metadata lock instrumentation uses the
which is enabled by default.
To control metadata lock instrumention state at server
startup, use lines like these in your
To control metadata lock instrumention state at runtime,
UPDATE setup_instruments SET ENABLED = 'YES', TIMED = 'YES' WHERE NAME = 'wait/lock/metadata/sql/mdl';
UPDATE setup_instruments SET ENABLED = 'NO', TIMED = 'NO' WHERE NAME = 'wait/lock/metadata/sql/mdl';
The Performance Schema maintains
metadata_locks table content as
follows, using the
LOCK_STATUS column to
indicate the status of each lock:
When a metadata lock is requested and obtained immediately, a row with a status of
When a metadata lock is requested and not obtained immediately, a row with a status of
When a metadata lock previously requested is granted, its row status is updated to
When a metadata lock is released, its row is deleted.
When a pending lock request is canceled by the deadlock detector to break a deadlock (
ER_LOCK_DEADLOCK), its row status is updated from
When a pending lock request times out (
ER_LOCK_WAIT_TIMEOUT), its row status is updated from
When granted lock or pending lock request is killed, its row status is updated from
KILLEDstatus values are brief and signify that the lock row is about to be deleted.
POST_RELEASE_NOTIFYstatus values are brief and signify that the metadata locking subsubsystem is notifying interested storage engines while entering lock acquisition or leaving lock release operations.
metadata_locks table has
The type of lock used in the metadata lock subsystem: The value is one of
USER LEVEL LOCK,
A value of
USER LEVEL LOCKindicates a lock acquired with
GET_LOCK(). A value of
LOCKING SERVICEindicates a lock acquired using the locking service described in Section 28.3.1, “The Locking Service”.
The schema that contains the object.
The name of the instrumented object.
The address in memory of the instrumented object.
The lock type from the metadata lock subsystem. The value is one of
The lock duration from the metadata lock subsystem. The value is one of
TRANSACTIONvalues signify locks that are released at statement or transaction end, respectively. The
EXPLICITvalue signifies locks that survive statement or transaction end and are released explicitly, such as global locks acquired with
FLUSH TABLES WITH READ LOCK.
The lock status from the metadata lock subsystem. The value is one of
POST_RELEASE_NOTIFY. The Performance Schema assigns these values as described previously.
The name of the source file containing the instrumented code that produced the event and the line number in the file at which the instrumentation occurs. This enables you to check the source to determine exactly what code is involved.
The thread requesting a metadata lock.
The event requesting a metadata lock.
metadata_locks table has
Primary key on (
Index on (
Index on (