MySQL  8.0.17
Source Code Documentation
Locked_tables_list Class Reference

Tables that were locked with LOCK TABLES statement. More...

#include <locked_tables_list.h>

Classes

struct  MDL_ticket_pair
 

Public Member Functions

 Locked_tables_list ()
 
void unlock_locked_tables (THD *thd)
 Leave LTM_LOCK_TABLES mode if it's been entered. More...
 
 ~Locked_tables_list ()
 
bool init_locked_tables (THD *thd)
 Enter LTM_LOCK_TABLES mode. More...
 
TABLE_LISTlocked_tables () const
 
void unlink_from_list (const THD *thd, TABLE_LIST *table_list, bool remove_from_locked_tables)
 Unlink a locked table from the locked tables list, either temporarily or permanently. More...
 
void unlink_all_closed_tables (THD *thd, MYSQL_LOCK *lock, size_t reopen_count)
 This is an attempt to recover (somewhat) in case of an error. More...
 
bool reopen_tables (THD *thd)
 Reopen the tables locked with LOCK TABLES and temporarily closed by a DDL statement or FLUSH TABLES. More...
 
void rename_locked_table (TABLE_LIST *old_table_list, const char *new_db, const char *new_table_name, MDL_ticket *target_mdl_ticket)
 Update database and table names of table locked with LOCK TABLES after table rename. More...
 
void add_rename_tablespace_mdls (MDL_ticket *src, MDL_ticket *dst)
 
void adjust_renamed_tablespace_mdls (MDL_context *mctx)
 
void discard_renamed_tablespace_mdls ()
 

Private Types

using MDL_ticket_pairs = std::vector< MDL_ticket_pair >
 

Private Attributes

MEM_ROOT m_locked_tables_root
 
TABLE_LISTm_locked_tables
 
TABLE_LIST ** m_locked_tables_last
 
TABLE ** m_reopen_array
 An auxiliary array used only in reopen_tables(). More...
 
size_t m_locked_tables_count
 Count the number of tables in m_locked_tables list. More...
 
MDL_ticket_pairs m_rename_tablespace_mdls
 

Detailed Description

Tables that were locked with LOCK TABLES statement.

Encapsulates a list of TABLE_LIST instances for tables locked by LOCK TABLES statement, memory root for metadata locks, and, generally, the context of LOCK TABLES statement.

In LOCK TABLES mode, the locked tables are kept open between statements. Therefore, we can't allocate metadata locks on execution memory root – as well as tables, the locks need to stay around till UNLOCK TABLES is called. The locks are allocated in the memory root encapsulated in this class.

Some SQL commands, like FLUSH TABLE or ALTER TABLE, demand that the tables they operate on are closed, at least temporarily. This class encapsulates a list of TABLE_LIST instances, one for each base table from LOCK TABLES list, which helps conveniently close the TABLEs when it's necessary and later reopen them.

Member Typedef Documentation

◆ MDL_ticket_pairs

Constructor & Destructor Documentation

◆ Locked_tables_list()

Locked_tables_list::Locked_tables_list ( )

◆ ~Locked_tables_list()

Locked_tables_list::~Locked_tables_list ( )
inline

Member Function Documentation

◆ add_rename_tablespace_mdls()

void Locked_tables_list::add_rename_tablespace_mdls ( MDL_ticket src,
MDL_ticket dst 
)

◆ adjust_renamed_tablespace_mdls()

void Locked_tables_list::adjust_renamed_tablespace_mdls ( MDL_context mctx)

◆ discard_renamed_tablespace_mdls()

void Locked_tables_list::discard_renamed_tablespace_mdls ( )
inline

◆ init_locked_tables()

bool Locked_tables_list::init_locked_tables ( THD thd)

Enter LTM_LOCK_TABLES mode.

Enter the LOCK TABLES mode using all the tables that are currently open and locked in this connection. Initializes a TABLE_LIST instance for every locked table.

Parameters
thdthread handle
Returns
true if out of memory.

Sic: remember the actual table level lock type taken, to acquire the exact same type in reopen_tables(). E.g. if the table was locked for write, src_table_list->lock_type is TL_WRITE_DEFAULT, whereas reginfo.lock_type has been updated from thd->update_lock_default.

Allocate an auxiliary array to pass to mysql_lock_tables() in reopen_tables(). reopen_tables() is a critical path and we don't want to complicate it with extra allocations.

◆ locked_tables()

TABLE_LIST* Locked_tables_list::locked_tables ( ) const
inline

◆ rename_locked_table()

void Locked_tables_list::rename_locked_table ( TABLE_LIST old_table_list,
const char *  new_db,
const char *  new_table_name,
MDL_ticket target_mdl_ticket 
)

Update database and table names of table locked with LOCK TABLES after table rename.

Parameters
old_table_listTable list element representing old db/table name.
new_dbTable's new database.
new_table_nameTable's new name.
target_mdl_ticketTicket representing metadata lock acquired on new table name.
Note
This function is a no-op if we're not under LOCK TABLES.

◆ reopen_tables()

bool Locked_tables_list::reopen_tables ( THD thd)

Reopen the tables locked with LOCK TABLES and temporarily closed by a DDL statement or FLUSH TABLES.

Note
This function is a no-op if we're not under LOCK TABLES.
Returns
true if an error reopening the tables. May happen in case of some fatal system error only, e.g. a disk corruption, out of memory or a serious bug in the locking.

◆ unlink_all_closed_tables()

void Locked_tables_list::unlink_all_closed_tables ( THD thd,
MYSQL_LOCK lock,
size_t  reopen_count 
)

This is an attempt to recover (somewhat) in case of an error.

If we failed to reopen a closed table, let's unlink it from the list and forget about it. From a user perspective that would look as if the server "lost" the lock on one of the locked tables.

Note
This function is a no-op if we're not under LOCK TABLES.

◆ unlink_from_list()

void Locked_tables_list::unlink_from_list ( const THD thd,
TABLE_LIST table_list,
bool  remove_from_locked_tables 
)

Unlink a locked table from the locked tables list, either temporarily or permanently.

Parameters
thdthread handle
table_listthe element of locked tables list. The implementation assumes that this argument points to a TABLE_LIST element linked into the locked tables list. Passing a TABLE_LIST instance that is not part of locked tables list will lead to a crash.
remove_from_locked_tablestrue if the table is removed from the list permanently.

This function is a no-op if we're not under LOCK TABLES.

See also
Locked_tables_list::reopen_tables()

◆ unlock_locked_tables()

void Locked_tables_list::unlock_locked_tables ( THD thd)

Leave LTM_LOCK_TABLES mode if it's been entered.

Close all locked tables, free memory, and leave the mode.

Note
This function is a no-op if we're not in LOCK TABLES.

Member Data Documentation

◆ m_locked_tables

TABLE_LIST* Locked_tables_list::m_locked_tables
private

◆ m_locked_tables_count

size_t Locked_tables_list::m_locked_tables_count
private

Count the number of tables in m_locked_tables list.

We can't rely on thd->lock->table_count because it excludes non-transactional temporary tables. We need to know an exact number of TABLE objects.

◆ m_locked_tables_last

TABLE_LIST** Locked_tables_list::m_locked_tables_last
private

◆ m_locked_tables_root

MEM_ROOT Locked_tables_list::m_locked_tables_root
private

◆ m_rename_tablespace_mdls

MDL_ticket_pairs Locked_tables_list::m_rename_tablespace_mdls
private

◆ m_reopen_array

TABLE** Locked_tables_list::m_reopen_array
private

An auxiliary array used only in reopen_tables().


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