MySQL  8.0.21
Source Code Documentation
Table_trigger_dispatcher Class Reference

This class holds all information about triggers of a table. More...

#include <table_trigger_dispatcher.h>

Inheritance diagram for Table_trigger_dispatcher:
Table_trigger_field_support

Public Member Functions

bool check_n_load (THD *thd, const dd::Table &table)
 Load triggers for the table. More...
 
bool reorder_57_list (MEM_ROOT *mem_root, List< Trigger > *triggers)
 
 ~Table_trigger_dispatcher ()
 
bool check_for_broken_triggers ()
 Checks if there is a broken trigger for this table. More...
 
bool create_trigger (THD *thd, String *binlog_create_trigger_stmt)
 Create trigger for table. More...
 
bool process_triggers (THD *thd, enum_trigger_event_type event, enum_trigger_action_time_type action_time, bool old_row_is_record1)
 Execute trigger for given (event, time) pair. More...
 
Trigger_chainget_triggers (int event, int action_time)
 
const Trigger_chainget_triggers (int event, int action_time) const
 
Triggerfind_trigger (const LEX_STRING &trigger_name)
 Get trigger object by trigger name. More...
 
bool has_triggers (enum_trigger_event_type event, enum_trigger_action_time_type action_time) const
 
bool has_update_triggers () const
 
bool has_delete_triggers () const
 
bool mark_fields (enum_trigger_event_type event)
 Mark fields of subject table which we read/set in its triggers as such. More...
 
bool add_tables_and_routines_for_triggers (THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list)
 Add triggers for table to the set of routines used by statement. More...
 
void enable_fields_temporary_nullability (THD *thd)
 Mark all trigger fields as "temporary nullable" and remember the current THD::check_for_truncated_fields value. More...
 
void disable_fields_temporary_nullability ()
 Reset "temporary nullable" flag from trigger fields. More...
 
void print_upgrade_warnings (THD *thd)
 Iterate along triggers and print necessary upgrade warnings. More...
 
void parse_triggers (THD *thd, List< Trigger > *triggers, bool is_upgrade)
 Parse trigger definition statements (CREATE TRIGGER). More...
 
- Public Member Functions inherited from Table_trigger_field_support
virtual ~Table_trigger_field_support ()
 

Static Public Member Functions

static Table_trigger_dispatchercreate (TABLE *subject_table)
 Create an instance of Table_trigger_dispatcher for the given subject table. More...
 

Private Member Functions

 Table_trigger_dispatcher (TABLE *subject_table)
 Private form of Table_trigger_dispatcher constructor. More...
 
Trigger_chaincreate_trigger_chain (MEM_ROOT *mem_root, enum_trigger_event_type event, enum_trigger_action_time_type action_time)
 Make sure there is a chain for the specified event and action time. More...
 
bool prepare_record1_accessors ()
 Prepare array of Field objects referencing to TABLE::record[1] instead of record[0] (they will represent OLD. More...
 
void set_parse_error_message (const char *error_message)
 Remember a parse error that occurred while parsing trigger definitions loaded from the Data Dictionary. More...
 
virtual TABLEget_subject_table ()
 
virtual Fieldget_trigger_variable_field (enum_trigger_variable_type v, int field_index)
 

Private Attributes

TABLEm_subject_table
 TABLE instance for which this triggers list object was created. More...
 
Trigger_chainm_trigger_map [TRG_EVENT_MAX][TRG_ACTION_MAX]
 Triggers grouped by event, action_time. More...
 
Field ** m_record1_field
 Copy of TABLE::Field array with field pointers set to TABLE::record[1] buffer instead of TABLE::record[0] (used for OLD values in on UPDATE trigger and DELETE trigger when it is called for REPLACE). More...
 
Field ** m_new_field
 During execution of trigger m_new_field and m_old_field should point to the array of fields representing new or old version of row correspondingly (so it can point to TABLE::field or to Table_trigger_dispatcher::m_record1_field). More...
 
Field ** m_old_field
 
bool m_has_unparseable_trigger
 This flag indicates that one of the triggers was not parsed successfully, and as a precaution the object has entered the state where all trigger operations result in errors until all the table triggers are dropped. More...
 
char m_parse_error_message [MYSQL_ERRMSG_SIZE]
 This error will be displayed when the user tries to manipulate or invoke triggers on a table that has broken triggers. More...
 

Detailed Description

This class holds all information about triggers of a table.

Constructor & Destructor Documentation

◆ Table_trigger_dispatcher()

Table_trigger_dispatcher::Table_trigger_dispatcher ( TABLE subject_table)
private

Private form of Table_trigger_dispatcher constructor.

In order to construct an instance of Table_trigger_dispatcher with a valid pointer to the subject table, use Table_trigger_dispatcher::create().

◆ ~Table_trigger_dispatcher()

Table_trigger_dispatcher::~Table_trigger_dispatcher ( )

Member Function Documentation

◆ add_tables_and_routines_for_triggers()

bool Table_trigger_dispatcher::add_tables_and_routines_for_triggers ( THD thd,
Query_tables_list prelocking_ctx,
TABLE_LIST table_list 
)

Add triggers for table to the set of routines used by statement.

Add tables used by them to statement table list. Do the same for routines used by triggers.

Parameters
thdThread context.
prelocking_ctxPrelocking context of the statement.
table_listTable list element for table with trigger.
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ check_for_broken_triggers()

bool Table_trigger_dispatcher::check_for_broken_triggers ( )
inline

Checks if there is a broken trigger for this table.

Return values
falseif all triggers are Ok.
truein case there is at least one broken trigger (a trigger which SQL-definition can not be parsed) for this table.

◆ check_n_load()

bool Table_trigger_dispatcher::check_n_load ( THD thd,
const dd::Table table 
)

Load triggers for the table.

Parameters
thdcurrent thread context
tabletable object.
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ create()

Table_trigger_dispatcher * Table_trigger_dispatcher::create ( TABLE subject_table)
static

Create an instance of Table_trigger_dispatcher for the given subject table.

Parameters
subject_tablevalid (not fake!) TABLE-object representing the subject table
Returns
a pointer to a new Table_trigger_dispatcher instance.

◆ create_trigger()

bool Table_trigger_dispatcher::create_trigger ( THD thd,
String binlog_create_trigger_stmt 
)

Create trigger for table.

Parameters
thdthread context
[out]binlog_create_trigger_stmtwell-formed CREATE TRIGGER statement for putting into binlog (after successful execution)
Note
  • Assumes that trigger name is fully qualified.
  • NULL-string means the following LEX_STRING instance: { str = 0; length = 0 }.
  • In other words, definer_user and definer_host should contain simultaneously NULL-strings (non-SUID/old trigger) or valid strings (SUID/new trigger).
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ create_trigger_chain()

Trigger_chain * Table_trigger_dispatcher::create_trigger_chain ( MEM_ROOT mem_root,
enum_trigger_event_type  event,
enum_trigger_action_time_type  action_time 
)
private

Make sure there is a chain for the specified event and action time.

Returns
A pointer to newly created Trigger_chain object, NULL in case of OOM error.

◆ disable_fields_temporary_nullability()

void Table_trigger_dispatcher::disable_fields_temporary_nullability ( )

Reset "temporary nullable" flag from trigger fields.

◆ enable_fields_temporary_nullability()

void Table_trigger_dispatcher::enable_fields_temporary_nullability ( THD thd)

Mark all trigger fields as "temporary nullable" and remember the current THD::check_for_truncated_fields value.

Parameters
thdThread context.

◆ find_trigger()

Trigger * Table_trigger_dispatcher::find_trigger ( const LEX_STRING trigger_name)

Get trigger object by trigger name.

Parameters
[in]trigger_nametrigger name
Returns
a pointer to Trigger object, NULL if the trigger not found.

◆ get_subject_table()

virtual TABLE* Table_trigger_dispatcher::get_subject_table ( )
inlineprivatevirtual

◆ get_trigger_variable_field()

virtual Field* Table_trigger_dispatcher::get_trigger_variable_field ( enum_trigger_variable_type  v,
int  field_index 
)
inlineprivatevirtual

◆ get_triggers() [1/2]

Trigger_chain* Table_trigger_dispatcher::get_triggers ( int  event,
int  action_time 
)
inline

◆ get_triggers() [2/2]

const Trigger_chain* Table_trigger_dispatcher::get_triggers ( int  event,
int  action_time 
) const
inline

◆ has_delete_triggers()

bool Table_trigger_dispatcher::has_delete_triggers ( ) const
inline

◆ has_triggers()

bool Table_trigger_dispatcher::has_triggers ( enum_trigger_event_type  event,
enum_trigger_action_time_type  action_time 
) const
inline

◆ has_update_triggers()

bool Table_trigger_dispatcher::has_update_triggers ( ) const
inline

◆ mark_fields()

bool Table_trigger_dispatcher::mark_fields ( enum_trigger_event_type  event)

Mark fields of subject table which we read/set in its triggers as such.

This method marks fields of subject table which are read/set in its triggers as such (by properly updating TABLE::read_set/write_set) and thus informs handler that values for these fields should be retrieved/stored during execution of statement.

Parameters
eventType of event triggers for which we are going to inspect
Returns
false if success, true if error

◆ parse_triggers()

void Table_trigger_dispatcher::parse_triggers ( THD thd,
List< Trigger > *  triggers,
bool  is_upgrade 
)

Parse trigger definition statements (CREATE TRIGGER).

Parameters
[in]thdThread context
[in]is_upgradeFlag to indicate that trigger being parsed is read from .TRG file in case of upgrade.
[in]triggersList of triggers to parse

◆ prepare_record1_accessors()

bool Table_trigger_dispatcher::prepare_record1_accessors ( )
private

Prepare array of Field objects referencing to TABLE::record[1] instead of record[0] (they will represent OLD.

  • row values in ON UPDATE trigger and in ON DELETE trigger which will be called during REPLACE execution).
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ print_upgrade_warnings()

void Table_trigger_dispatcher::print_upgrade_warnings ( THD thd)

Iterate along triggers and print necessary upgrade warnings.

Now it prints the warning about missing 'CREATED' attribute.

Parameters
thdThread context.

◆ process_triggers()

bool Table_trigger_dispatcher::process_triggers ( THD thd,
enum_trigger_event_type  event,
enum_trigger_action_time_type  action_time,
bool  old_row_is_record1 
)

Execute trigger for given (event, time) pair.

The operation executes trigger for the specified event (insert, update, delete) and time (after, before) if it is set.

Parameters
thdThread handle
eventInsert, update or delete
action_timeBefore or after
old_row_is_record1If record1 contains old or new field.
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ reorder_57_list()

bool Table_trigger_dispatcher::reorder_57_list ( MEM_ROOT mem_root,
List< Trigger > *  triggers 
)

◆ set_parse_error_message()

void Table_trigger_dispatcher::set_parse_error_message ( const char *  error_message)
inlineprivate

Remember a parse error that occurred while parsing trigger definitions loaded from the Data Dictionary.

This makes the Table_trigger_dispatcher enter the error state flagged by m_has_unparseable_trigger == true. The error message will be used whenever a statement invoking or manipulating triggers is issued against the Table_trigger_dispatcher's table.

Parameters
error_messageThe error message thrown by the parser.

Member Data Documentation

◆ m_has_unparseable_trigger

bool Table_trigger_dispatcher::m_has_unparseable_trigger
private

This flag indicates that one of the triggers was not parsed successfully, and as a precaution the object has entered the state where all trigger operations result in errors until all the table triggers are dropped.

It is not safe to add triggers since it is unknown if the broken trigger has the same name or event type. Nor is it safe to invoke any trigger. The only safe operations are drop_trigger() and drop_all_triggers().

We can't use the value of m_parse_error_message as a flag to inform that a trigger has a parse error since for multi-byte locale the first byte of message can be 0 but the message still be meaningful. It means that just a comparison against m_parse_error_message[0] can not be done safely.

See also
Table_trigger_dispatcher::set_parse_error()

◆ m_new_field

Field** Table_trigger_dispatcher::m_new_field
private

During execution of trigger m_new_field and m_old_field should point to the array of fields representing new or old version of row correspondingly (so it can point to TABLE::field or to Table_trigger_dispatcher::m_record1_field).

◆ m_old_field

Field** Table_trigger_dispatcher::m_old_field
private

◆ m_parse_error_message

char Table_trigger_dispatcher::m_parse_error_message[MYSQL_ERRMSG_SIZE]
private

This error will be displayed when the user tries to manipulate or invoke triggers on a table that has broken triggers.

It is set once per statement and thus will contain the first parse error encountered in the trigger file.

◆ m_record1_field

Field** Table_trigger_dispatcher::m_record1_field
private

Copy of TABLE::Field array with field pointers set to TABLE::record[1] buffer instead of TABLE::record[0] (used for OLD values in on UPDATE trigger and DELETE trigger when it is called for REPLACE).

◆ m_subject_table

TABLE* Table_trigger_dispatcher::m_subject_table
private

TABLE instance for which this triggers list object was created.

◆ m_trigger_map

Trigger_chain* Table_trigger_dispatcher::m_trigger_map[TRG_EVENT_MAX][TRG_ACTION_MAX]
private

Triggers grouped by event, action_time.


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