MySQL 9.1.0
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:
[legend]

Public Member Functions

bool finalize_load (THD *thd)
 Finalize load of triggers for the table by creating Trigger objects to be associated with TABLE/Table_trigger_dispatcher (rather than with TABLE_SHARE), parsing trigger bodies, creating trigger chains, preparing sp_head objects and row accessors. More...
 
 ~Table_trigger_dispatcher () override
 
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, bool if_not_exists, bool &already_exists)
 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_ref *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...
 
bool has_load_been_finalized ()
 Check whether we have finalized loading of triggers for the table by parsing their bodies, creating sp_head objects and preparing row-accessors. More...
 
- Public Member Functions inherited from Table_trigger_field_support
virtual ~Table_trigger_field_support ()=default
 

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<a href="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...
 
TABLEget_subject_table () override
 
Fieldget_trigger_variable_field (enum_trigger_variable_type v, int field_index) override
 

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
 
const char * m_parse_error_message
 Error which occurred while parsing one of the triggers for the table; nullptr if there was no error for any of its triggers. More...
 
bool m_load_finalized
 Indicates whether we have finalized loading of triggers for the table. More...
 

Friends

class table_cache_unittest::Mock_share
 

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 ( )
override

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_ref 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.

◆ 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,
bool  if_not_exists,
bool &  already_exists 
)

Create trigger for table.

Parameters
thdThread context
[out]binlog_create_trigger_stmtWell-formed CREATE TRIGGER statement for putting into binlog (after successful execution)
if_not_existsTrue if 'IF NOT EXISTS' clause was specified
[out]already_existsSet to true if trigger already exists on the same table
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.

◆ finalize_load()

bool Table_trigger_dispatcher::finalize_load ( THD thd)

Finalize load of triggers for the table by creating Trigger objects to be associated with TABLE/Table_trigger_dispatcher (rather than with TABLE_SHARE), parsing trigger bodies, creating trigger chains, preparing sp_head objects and row accessors.

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

◆ 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()

TABLE * Table_trigger_dispatcher::get_subject_table ( )
inlineoverrideprivatevirtual

◆ get_trigger_variable_field()

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

◆ 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_load_been_finalized()

bool Table_trigger_dispatcher::has_load_been_finalized ( )
inline

Check whether we have finalized loading of triggers for the table by parsing their bodies, creating sp_head objects and preparing row-accessors.

◆ 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<a href="they will represent OLD.

  • row values in ON UPDATE trigger and in ON DELETE trigger which will be called during REPLACE execution" >0.
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

◆ set_parse_error_message()

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

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_parse_error_message != nullptr . 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.

Friends And Related Function Documentation

◆ table_cache_unittest::Mock_share

friend class table_cache_unittest::Mock_share
friend

Member Data Documentation

◆ m_load_finalized

bool Table_trigger_dispatcher::m_load_finalized
private

Indicates whether we have finalized loading of triggers for the table.

◆ 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

const char* Table_trigger_dispatcher::m_parse_error_message
private

Error which occurred while parsing one of the triggers for the table; nullptr if there was no error for any of its triggers.

Non-nullptr value indicates that as a precaution the object has entered the state where all trigger operations result in errors (referencing this error message saved) 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().

See also
Table_trigger_dispatcher::set_parse_error()

◆ 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: