MySQL 9.0.0
Source Code Documentation
MDL_key Struct Reference

Metadata lock object key. More...

#include <mdl.h>

Public Types

enum  enum_mdl_namespace {
  GLOBAL = 0 , BACKUP_LOCK , TABLESPACE , SCHEMA ,
  TABLE , FUNCTION , PROCEDURE , TRIGGER ,
  EVENT , COMMIT , USER_LEVEL_LOCK , LOCKING_SERVICE ,
  SRID , ACL_CACHE , COLUMN_STATISTICS , RESOURCE_GROUPS ,
  FOREIGN_KEY , CHECK_CONSTRAINT , NAMESPACE_END
}
 Object namespaces. More...
 

Public Member Functions

const ucharptr () const
 
uint length () const
 
const char * db_name () const
 
uint db_name_length () const
 
const char * name () const
 
uint name_length () const
 
const char * col_name () const
 
uint col_name_length () const
 
enum_mdl_namespace mdl_namespace () const
 
void mdl_key_init (enum_mdl_namespace mdl_namespace, const char *db, const char *name)
 Construct a metadata lock key from a triplet (mdl_namespace, database and name). More...
 
void mdl_key_init (enum_mdl_namespace mdl_namespace, const char *db, const char *name, const char *column_name)
 Construct a metadata lock key from a quadruplet (mdl_namespace, database, table and column name). More...
 
void mdl_key_init (enum_mdl_namespace mdl_namespace, const char *db, const char *normalized_name, size_t normalized_name_len, const char *name)
 Construct a metadata lock key from a quadruplet (mdl_namespace, database, normalized object name buffer and the object name). More...
 
void mdl_key_init (enum_mdl_namespace mdl_namespace, const char *part_key, size_t part_key_length, size_t db_length)
 Construct a metadata lock key from namespace and partial key, which contains info about object database and name. More...
 
void mdl_key_init (const MDL_key *rhs)
 
void reset ()
 
bool is_equal (const MDL_key *rhs) const
 
int cmp (const MDL_key *rhs) const
 Compare two MDL keys lexicographically. More...
 
 MDL_key (const MDL_key &rhs)
 
MDL_keyoperator= (const MDL_key &rhs)
 
 MDL_key (enum_mdl_namespace namespace_arg, const char *db_arg, const char *name_arg)
 
 MDL_key ()=default
 
const PSI_stage_infoget_wait_state_name () const
 Get thread state name to be used in case when we have to wait on resource identified by key. More...
 

Static Public Member Functions

static void init_psi_keys ()
 

Private Member Functions

bool use_normalized_object_name () const
 Check if normalized object name should be used. More...
 

Private Attributes

uint16 m_length {0}
 
uint16 m_db_name_length {0}
 
uint16 m_object_name_length {0}
 
char m_ptr [MAX_MDLKEY_LENGTH] {0}
 

Static Private Attributes

static PSI_stage_info m_namespace_to_wait_state_name [NAMESPACE_END]
 Thread state names to be used in case when we have to wait on resource belonging to certain namespace. More...
 

Detailed Description

Metadata lock object key.

A lock is requested or granted based on a fully qualified name and type. E.g. They key for a table consists of <0 (=table)>+<database>+<table name>. Elsewhere in the comments this triple will be referred to simply as "key" or "name".

Member Enumeration Documentation

◆ enum_mdl_namespace

Object namespaces.

Sic: when adding a new member to this enum make sure to update m_namespace_to_wait_state_name array in mdl.cc!

Different types of objects exist in different namespaces

  • GLOBAL is used for the global read lock.
  • BACKUP_LOCK is to block any operations that could cause inconsistent backup. Such operations are most DDL statements, and some administrative statements.
  • TABLESPACE is for tablespaces.
  • SCHEMA is for schemas (aka databases).
  • TABLE is for tables and views.
  • FUNCTION is for stored functions.
  • PROCEDURE is for stored procedures.
  • TRIGGER is for triggers.
  • EVENT is for event scheduler events.
  • COMMIT is for enabling the global read lock to block commits.
  • USER_LEVEL_LOCK is for user-level locks.
  • LOCKING_SERVICE is for the name plugin RW-lock service
  • SRID is for spatial reference systems
  • ACL_CACHE is for ACL caches
  • COLUMN_STATISTICS is for column statistics, such as histograms
  • RESOURCE_GROUPS is for resource groups.
  • FOREIGN_KEY is for foreign key names.
  • CHECK_CONSTRAINT is for check constraint names. Note that requests waiting for user-level locks get special treatment - waiting is aborted if connection to client is lost.
Enumerator
GLOBAL 
BACKUP_LOCK 
TABLESPACE 
SCHEMA 
TABLE 
FUNCTION 
PROCEDURE 
TRIGGER 
EVENT 
COMMIT 
USER_LEVEL_LOCK 
LOCKING_SERVICE 
SRID 
ACL_CACHE 
COLUMN_STATISTICS 
RESOURCE_GROUPS 
FOREIGN_KEY 
CHECK_CONSTRAINT 
NAMESPACE_END 

Constructor & Destructor Documentation

◆ MDL_key() [1/3]

MDL_key::MDL_key ( const MDL_key rhs)
inline

◆ MDL_key() [2/3]

MDL_key::MDL_key ( enum_mdl_namespace  namespace_arg,
const char *  db_arg,
const char *  name_arg 
)
inline

◆ MDL_key() [3/3]

MDL_key::MDL_key ( )
default

Member Function Documentation

◆ cmp()

int MDL_key::cmp ( const MDL_key rhs) const
inline

Compare two MDL keys lexicographically.

◆ col_name()

const char * MDL_key::col_name ( ) const
inline

◆ col_name_length()

uint MDL_key::col_name_length ( ) const
inline

◆ db_name()

const char * MDL_key::db_name ( ) const
inline

◆ db_name_length()

uint MDL_key::db_name_length ( ) const
inline

◆ get_wait_state_name()

const PSI_stage_info * MDL_key::get_wait_state_name ( ) const
inline

Get thread state name to be used in case when we have to wait on resource identified by key.

◆ init_psi_keys()

void MDL_key::init_psi_keys ( )
static

◆ is_equal()

bool MDL_key::is_equal ( const MDL_key rhs) const
inline

◆ length()

uint MDL_key::length ( ) const
inline

◆ mdl_key_init() [1/5]

void MDL_key::mdl_key_init ( const MDL_key rhs)
inline

◆ mdl_key_init() [2/5]

void MDL_key::mdl_key_init ( enum_mdl_namespace  mdl_namespace,
const char *  db,
const char *  name 
)
inline

Construct a metadata lock key from a triplet (mdl_namespace, database and name).

Remarks
The key for a table is <mdl_namespace>+<database name>+<table name>
Parameters
mdl_namespaceId of namespace of object to be locked
dbName of database to which the object belongs
nameName of of the object

◆ mdl_key_init() [3/5]

void MDL_key::mdl_key_init ( enum_mdl_namespace  mdl_namespace,
const char *  db,
const char *  name,
const char *  column_name 
)
inline

Construct a metadata lock key from a quadruplet (mdl_namespace, database, table and column name).

Remarks
The key for a column is <mdl_namespace>+<database name>+<table name>+<column name>
Parameters
mdl_namespaceId of namespace of object to be locked
dbName of database to which the object belongs
nameName of of the object
column_nameName of of the column

◆ mdl_key_init() [4/5]

void MDL_key::mdl_key_init ( enum_mdl_namespace  mdl_namespace,
const char *  db,
const char *  normalized_name,
size_t  normalized_name_len,
const char *  name 
)
inline

Construct a metadata lock key from a quadruplet (mdl_namespace, database, normalized object name buffer and the object name).

Remarks
The key for a routine/event/resource group/trigger is <mdl_namespace>+<database name>+<normalized object name> additionally <object name> is stored in the same buffer for information purpose if buffer has sufficient space.

Routine, Event and Resource group names are case sensitive and accent sensitive. So normalized object name is used to form a MDL_key.

With the UTF8MB3 charset space reserved for the db name/object name is 64 * 3 bytes. utf8mb3_general_ci collation is used for the Routine, Event and Resource group names. With this collation, the normalized object name uses just 2 bytes for each character (max length = 64 * 2 bytes). MDL_key has still some space to store the object names. If there is a sufficient space for the object name in the MDL_key then it is stored in the MDL_key (similar to the column names in the MDL_key). Actual object name is used by the PFS. Not listing actual object name from the PFS should be OK when there is no space to store it (instead of increasing the MDL_key size). Object name is not used in the key comparisons. So only (mdl_namespace + strlen(db) + 1 + normalized_name_len + 1) value is stored in the m_length member.

Parameters
mdl_namespaceId of namespace of object to be locked.
dbName of database to which the object belongs.
normalized_nameNormalized name of the object.
normalized_name_lenLength of the normalized object name.
nameName of the object.

◆ mdl_key_init() [5/5]

void MDL_key::mdl_key_init ( enum_mdl_namespace  mdl_namespace,
const char *  part_key,
size_t  part_key_length,
size_t  db_length 
)
inline

Construct a metadata lock key from namespace and partial key, which contains info about object database and name.

Remarks
The partial key must be "<database>\0<name>\0".
Parameters
mdl_namespaceId of namespace of object to be locked
part_keyPartial key.
part_key_lengthPartial key length
db_lengthDatabase name length.

◆ mdl_namespace()

enum_mdl_namespace MDL_key::mdl_namespace ( ) const
inline

◆ name()

const char * MDL_key::name ( ) const
inline

◆ name_length()

uint MDL_key::name_length ( ) const
inline

◆ operator=()

MDL_key & MDL_key::operator= ( const MDL_key rhs)
inline

◆ ptr()

const uchar * MDL_key::ptr ( ) const
inline

◆ reset()

void MDL_key::reset ( void  )
inline

◆ use_normalized_object_name()

bool MDL_key::use_normalized_object_name ( ) const
inlineprivate

Check if normalized object name should be used.

Returns
true if normlized object name should be used, false otherwise.

Member Data Documentation

◆ m_db_name_length

uint16 MDL_key::m_db_name_length {0}
private

◆ m_length

uint16 MDL_key::m_length {0}
private

◆ m_namespace_to_wait_state_name

PSI_stage_info MDL_key::m_namespace_to_wait_state_name
staticprivate
Initial value:
= {
{0, "Waiting for global read lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for backup lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for tablespace metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for schema metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for table metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for stored function metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for stored procedure metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for trigger metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for event metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for commit lock", 0, PSI_DOCUMENT_ME},
{0, "User lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for locking service lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for spatial reference system lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for acl cache lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for column statistics lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for resource groups metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for foreign key metadata lock", 0, PSI_DOCUMENT_ME},
{0, "Waiting for check constraint metadata lock", 0, PSI_DOCUMENT_ME}}
#define PSI_DOCUMENT_ME
Definition: component_common.h:29

Thread state names to be used in case when we have to wait on resource belonging to certain namespace.

◆ m_object_name_length

uint16 MDL_key::m_object_name_length {0}
private

◆ m_ptr

char MDL_key::m_ptr[MAX_MDLKEY_LENGTH] {0}
private

The documentation for this struct was generated from the following files: