MySQL 9.0.0
Source Code Documentation
sql_trigger.cc File Reference
#include "sql/sql_trigger.h"
#include <stddef.h>
#include <string.h>
#include <string>
#include <utility>
#include "m_string.h"
#include "my_base.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_psi_config.h"
#include "my_sys.h"
#include "mysql/psi/mysql_sp.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/binlog.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd_schema.h"
#include "sql/dd/string_type.h"
#include "sql/dd/types/abstract_table.h"
#include "sql/dd/types/table.h"
#include "sql/dd/types/trigger.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/mysqld.h"
#include "sql/sp_cache.h"
#include "sql/sp_head.h"
#include "sql/sql_backup_lock.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_db.h"
#include "sql/sql_error.h"
#include "sql/sql_handler.h"
#include "sql/sql_lex.h"
#include "sql/sql_table.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/table_trigger_dispatcher.h"
#include "sql/transaction.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "thr_lock.h"

Namespaces

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

Functions

bool get_table_for_trigger (THD *thd, const LEX_CSTRING &db_name, const LEX_STRING &trigger_name, bool continue_if_not_exist, Table_ref **table)
 Find trigger's table from trigger identifier. More...
 
void remove_all_triggers_from_perfschema (const char *schema_name, const dd::Table &table)
 Drop statistics from performance schema for every trigger associated with a table. More...
 
bool check_table_triggers_are_not_in_the_same_schema (const char *db_name, const dd::Table &table, const char *new_db_name)
 Check for table with triggers that old database name and new database name are the same. More...
 
bool acquire_exclusive_mdl_for_trigger (THD *thd, const char *db, const char *trg_name)
 Acquire exclusive MDL lock for a trigger in specified schema. More...
 
bool acquire_mdl_for_trigger (THD *thd, const char *db, const char *trg_name, enum_mdl_type trigger_name_mdl_type)
 Acquire either exclusive or shared MDL lock for a trigger in specified schema. More...
 
static bool finalize_trigger_ddl (THD *thd, const char *db_name, TABLE *table, const String &stmt_query, bool binlog_stmt, bool trg_created_or_dropped)
 Close all open instances of a trigger's table, reopen it if needed, invalidate SP-cache and possibly write a statement to binlog. More...
 

Function Documentation

◆ acquire_exclusive_mdl_for_trigger()

bool acquire_exclusive_mdl_for_trigger ( THD thd,
const char *  db,
const char *  trg_name 
)

Acquire exclusive MDL lock for a trigger in specified schema.

Parameters
[in]thdCurrent thread context
[in]dbSchema name
[in]trg_nameTrigger name
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ acquire_mdl_for_trigger()

bool acquire_mdl_for_trigger ( THD thd,
const char *  db,
const char *  trg_name,
enum_mdl_type  trigger_name_mdl_type 
)

Acquire either exclusive or shared MDL lock for a trigger in specified schema.

Parameters
[in]thdCurrent thread context
[in]dbSchema name
[in]trg_nameTrigger name
[in]trigger_name_mdl_typeType of MDL to acquire for trigger name
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ check_table_triggers_are_not_in_the_same_schema()

bool check_table_triggers_are_not_in_the_same_schema ( const char *  db_name,
const dd::Table table,
const char *  new_db_name 
)

Check for table with triggers that old database name and new database name are the same.

This functions is called while handling the statement RENAME TABLE to ensure that table moved within the same database.

Parameters
[in]db_nameSchema name.
[in]tableTable.
[in]new_db_nameNew schema name
Note
Set error ER_TRG_IN_WRONG_SCHEMA in Diagnostics_area in case function returns true.
Returns
Operation status
Return values
falseEither there is no triggers assigned to a table or old and new schema name are the same.
trueOld and new schema name aren't the same.

◆ finalize_trigger_ddl()

static bool finalize_trigger_ddl ( THD thd,
const char *  db_name,
TABLE table,
const String stmt_query,
bool  binlog_stmt,
bool  trg_created_or_dropped 
)
static

Close all open instances of a trigger's table, reopen it if needed, invalidate SP-cache and possibly write a statement to binlog.

Parameters
[in]thdCurrent thread context
[in]db_nameDatabase name where trigger's table defined
[in]tableTable associated with a trigger
[in]stmt_queryQuery string to write to binlog
[in]binlog_stmtShould the statement be binlogged?
[in]trg_created_or_droppedSet to true if trigger is created or dropped. Set to false if the statement failed or the trigger already existed in case of CREATE TRIGGER IF NOT EXISTS.
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ get_table_for_trigger()

bool get_table_for_trigger ( THD thd,
const LEX_CSTRING db_name,
const LEX_STRING trigger_name,
bool  continue_if_not_exist,
Table_ref **  table 
)

Find trigger's table from trigger identifier.

Parameters
[in]thdThread context.
[in]db_nameSchema name.
[in]trigger_nameTrigger name.
[in]continue_if_not_existtrue if SQL statement contains "IF EXISTS" clause. That means a warning instead of error should be thrown if trigger with given name does not exist.
[out]tablePointer to Table_ref object for the table trigger.
Returns
Operation status
Return values
falseOn success.
trueOtherwise.

◆ remove_all_triggers_from_perfschema()

void remove_all_triggers_from_perfschema ( const char *  schema_name,
const dd::Table table 
)

Drop statistics from performance schema for every trigger associated with a table.

Parameters
schema_nameName of schema containing the table.
tableTable reference, for that associated triggers statistics has to be deleted.