MySQL 8.4.0
Source Code Documentation
sql_truncate.cc File Reference
#include "sql/sql_truncate.h"
#include <stddef.h>
#include <sys/types.h>
#include "lex_string.h"
#include "my_base.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_sys.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include "mysqld.h"
#include "mysqld_error.h"
#include "scope_guard.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd_schema.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/debug_sync.h"
#include "sql/handler.h"
#include "sql/lock.h"
#include "sql/mdl.h"
#include "sql/query_options.h"
#include "sql/sql_audit.h"
#include "sql/sql_backup_lock.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_show.h"
#include "sql/sql_table.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/transaction.h"
#include "sql/transaction_info.h"
#include "sql_string.h"
#include "thr_lock.h"

Namespaces

namespace  dd
 The version of the current data dictionary table definitions.
 

Enumerations

enum class  Truncate_result { OK = 0 , FAILED_BUT_BINLOG , FAILED_SKIP_BINLOG , FAILED_OPEN }
 

Functions

static const char * fk_info_str (const THD *thd, const dd::Foreign_key_parent *fk_p)
 Generate a foreign key description suitable for a error message. More...
 
static bool fk_truncate_illegal_if_parent (THD *thd, Table_ref *table_list, dd::Table *table_def)
 Check and emit a fatal error if the table which is going to be affected by TRUNCATE TABLE is a parent table in some non-self- referencing foreign key. More...
 
static Truncate_result handler_truncate_base (THD *thd, Table_ref *table_ref, dd::Table *table_def)
 Open and truncate a locked base table. More...
 
static Truncate_result handler_truncate_temporary (THD *thd, Table_ref *table_ref)
 Open and truncate a locked temporary table. More...
 

Enumeration Type Documentation

◆ Truncate_result

enum class Truncate_result
strong
Enumerator
OK 
FAILED_BUT_BINLOG 
FAILED_SKIP_BINLOG 
FAILED_OPEN 

Function Documentation

◆ fk_info_str()

static const char * fk_info_str ( const THD thd,
const dd::Foreign_key_parent fk_p 
)
static

Generate a foreign key description suitable for a error message.

Parameters
thdThread context.
fk_pObject describing foreign key in parent table.
Returns
A human-readable string describing the foreign key.

◆ fk_truncate_illegal_if_parent()

static bool fk_truncate_illegal_if_parent ( THD thd,
Table_ref table_list,
dd::Table table_def 
)
static

Check and emit a fatal error if the table which is going to be affected by TRUNCATE TABLE is a parent table in some non-self- referencing foreign key.

Remarks
The intention is to allow truncate only for tables that are not dependent on other tables.
Parameters
thdThread context.
table_listTable list element for the table.
table_defdd::Table describing the table.
Return values
falseThis table is not parent in a non-self-referencing foreign key. Statement can proceed.
trueThis table is parent in a non-self-referencing foreign key, error was emitted.

◆ handler_truncate_base()

static Truncate_result handler_truncate_base ( THD thd,
Table_ref table_ref,
dd::Table table_def 
)
static

Open and truncate a locked base table.

Parameters
thdThread context.
table_refTable list element for the table to be truncated.
table_defDictionary table object.
Return values
Truncate_result::OKTruncate was successful and statement can be safely binlogged.
Truncate_result::FAILED_BUT_BINLOGTruncate failed but still go ahead with binlogging as in case of non transactional tables partial truncation is possible.
Truncate_result::FAILED_SKIP_BINLOGTruncate was not successful hence do not binlog the statement.
Truncate_result::FAILED_OPENTruncate failed to open table, do not binlog the statement.

◆ handler_truncate_temporary()

static Truncate_result handler_truncate_temporary ( THD thd,
Table_ref table_ref 
)
static

Open and truncate a locked temporary table.

Parameters
thdThread context.
table_refTable list element for the table to be truncated.
Return values
Truncate_result::OKTruncate was successful and statement can be safely binlogged.
Truncate_result::FAILED_BUT_BINLOGTruncate failed but still go ahead with binlogging as in case of non transactional tables partial truncation is possible.
Truncate_result::FAILED_SKIP_BINLOGTruncate was not successful hence do not binlog the statement.
Truncate_result::FAILED_OPENTruncate failed to open table, do not binlog the statement.