MySQL 8.4.3
Source Code Documentation
sql_rename.cc File Reference

Atomic rename of table; RENAME TABLE t1 to t2, tmp to t1 [,...]. More...

#include "sql/sql_rename.h"
#include <string.h>
#include <set>
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_murmur3.h"
#include "my_sys.h"
#include "mysql/components/services/log_shared.h"
#include "mysqld_error.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd_table.h"
#include "sql/dd/properties.h"
#include "sql/dd/types/abstract_table.h"
#include "sql/dd/types/table.h"
#include "sql/dd_sql_view.h"
#include "sql/derror.h"
#include "sql/handler.h"
#include "sql/log.h"
#include "sql/mysqld.h"
#include "sql/sp_cache.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_handler.h"
#include "sql/sql_table.h"
#include "sql/sql_trigger.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/transaction.h"

Classes

struct  anonymous_namespace{sql_rename.cc}::table_list_hash
 
struct  anonymous_namespace{sql_rename.cc}::table_list_equal
 

Namespaces

namespace  dd
 The version of the current data dictionary table definitions.
 
namespace  anonymous_namespace{sql_rename.cc}
 

Typedefs

typedef std::set< handlerton * > post_ddl_htons_t
 

Functions

static Table_refrename_tables (THD *thd, Table_ref *table_list, bool *int_commit_done, post_ddl_htons_t *post_ddl_htons, Foreign_key_parents_invalidator *fk_invalidator)
 Rename all tables/views in the list. More...
 
static Table_refreverse_table_list (Table_ref *table_list)
 
static bool check_if_owns_upgradable_mdl (THD *thd, const char *db, const char *table_name)
 Check if connection owns SNRW metadata lock on table or view. More...
 
static void find_and_set_explicit_duration_for_schema_mdl (THD *thd, Table_ref *table, Prealloced_array< MDL_request *, 1 > *schema_reqs)
 Find metadata lock request for table's schema in the set of schema requests and set duration of corresponding lock to explicit. More...
 
bool mysql_rename_tables (THD *thd, Table_ref *table_list)
 Rename tables from the list. More...
 
static bool do_rename (THD *thd, Table_ref *ren_table, const char *new_db, const char *new_table_name, const char *new_table_alias, bool *int_commit_done, std::set< handlerton * > *post_ddl_htons, Foreign_key_parents_invalidator *fk_invalidator)
 Rename a single table or a view. More...
 

Detailed Description

Atomic rename of table; RENAME TABLE t1 to t2, tmp to t1 [,...].

Typedef Documentation

◆ post_ddl_htons_t

typedef std::set<handlerton *> post_ddl_htons_t

Function Documentation

◆ check_if_owns_upgradable_mdl()

static bool check_if_owns_upgradable_mdl ( THD thd,
const char *  db,
const char *  table_name 
)
static

Check if connection owns SNRW metadata lock on table or view.

Report appropriate error if not.

Note
Unlike find_table_for_mdl_upgrade() this call can handle views.

◆ do_rename()

static bool do_rename ( THD thd,
Table_ref ren_table,
const char *  new_db,
const char *  new_table_name,
const char *  new_table_alias,
bool *  int_commit_done,
std::set< handlerton * > *  post_ddl_htons,
Foreign_key_parents_invalidator fk_invalidator 
)
static

Rename a single table or a view.

Parameters
[in]thdThread handle.
[in]ren_tableA table/view to be renamed.
[in]new_dbThe database to which the table to be moved to.
[in]new_table_nameThe new table/view name.
[in]new_table_aliasThe new table/view alias.
[in,out]int_commit_doneWhether intermediate commits were done.
[in,out]post_ddl_htonsSet of SEs supporting atomic DDL for which post-DDL hooks needs to be called.
[in,out]fk_invalidatorObject keeping track of which dd::Table objects to invalidate.
Note
Unless int_commit_done is true failure of this call requires rollback of transaction before doing anything else.
Returns
False on success, True if rename failed.

◆ find_and_set_explicit_duration_for_schema_mdl()

static void find_and_set_explicit_duration_for_schema_mdl ( THD thd,
Table_ref table,
Prealloced_array< MDL_request *, 1 > *  schema_reqs 
)
static

Find metadata lock request for table's schema in the set of schema requests and set duration of corresponding lock to explicit.

Note
We assume that there are no duplicate schemata in schema_reqs array.

◆ mysql_rename_tables()

bool mysql_rename_tables ( THD thd,
Table_ref table_list 
)

Rename tables from the list.

Parameters
thdThread context.
table_listEvery two entries in the table_list form a pair of original name and the new name.
Returns
True - on failure, false - on success.

◆ rename_tables()

static Table_ref * rename_tables ( THD thd,
Table_ref table_list,
bool *  int_commit_done,
post_ddl_htons_t post_ddl_htons,
Foreign_key_parents_invalidator fk_invalidator 
)
static

Rename all tables/views in the list.

Parameters
[in]thdThread handle.
[in]table_listList of tables to rename.
[in,out]int_commit_doneWhether intermediate commits were done.
[in,out]post_ddl_htonsSet of SEs supporting atomic DDL for which post-DDL hooks needs to be called.
[in,out]fk_invalidatorObject keeping track of which dd::Table objects to invalidate.
Note
Take a table/view name from and odd list element and rename it to a the name taken from list element+1. Note that the table_list may be empty.
Unless int_commit_done is true failure of this call requires rollback of transaction before doing anything else.
Returns
0 - on success, pointer to problematic entry if something goes wrong.

◆ reverse_table_list()

static Table_ref * reverse_table_list ( Table_ref table_list)
static