## 27.12.13.3 The metadata_locks Table 

•Index on ( BLOCKING_THREAD_ID , BLOCKING_EVENT_ID ) 

TRUNCATE TABLE  is not permitted for the data_lock_waits  table. 

MySQL uses metadata locking to manage concurrent access to database objects and to ensure data consistency; see Section 8.11.4, “Metadata Locking” . Metadata locking applies not just to tables, but also to schemas, stored programs (procedures, functions, triggers, scheduled events), tablespaces, user locks acquired with the GET_LOCK()  function (see Section 12.15, “Locking Functions” ), and locks acquired with the locking service described in Section 5.6.9.1, “The Locking Service” . 

The Performance Schema exposes metadata lock information through the metadata_locks  table: 

•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. 

•Lock requests that have 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. 

The metadata_locks  table is read only and cannot be updated. It is autosized by default; to configure the table size, set the performance_schema_max_metadata_locks  system variable at server startup. 

Metadata lock instrumentation uses the wait/lock/metadata/sql/mdl  instrument, which is enabled by default. 

To control metadata lock instrumentation state at server startup, use lines like these in your my.cnf  file: 

•Enable: 

[mysqld] performance-schema-instrument=’wait/lock/metadata/sql/mdl=ON’ 

•Disable: 

[mysqld] performance-schema-instrument=’wait/lock/metadata/sql/mdl=OFF’ 

To control metadata lock instrumentation state at runtime, update the setup_instruments  table: 

•Enable: 

UPDATE performance_schema.setup_instruments SET ENABLED = ’YES’, TIMED = ’YES’ WHERE NAME = ’wait/lock/metadata/sql/mdl’; 

•Disable: 

UPDATE performance_schema.setup_instruments SET ENABLED = ’NO’, TIMED = ’NO’ WHERE NAME = ’wait/lock/metadata/sql/mdl’; 

