1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-34724: Skipping a row operation from a trigger

Implementation of this task adds ability to raise the signal with
SQLSTATE '02TRG' from a BEFORE INSERT/UPDATE/DELETE trigger and handles
this signal as an indicator meaning 'to throw away the current row'
on processing the INSERT/UPDATE/DELETE statement. The signal with
SQLSTATE '02TRG' has special meaning only in case it is raised inside
BEFORE triggers, for AFTER trigger's this value of SQLSTATE isn't treated
in any special way. In according with SQL standard, the SQLSTATE class '02'
means NO DATA and sql_errno for this class is set to value
ER_SIGNAL_NOT_FOUND by current implementation of MariaDB server.
Implementation of this task assigns the value ER_SIGNAL_SKIP_ROW_FROM_TRIGGER
to sql_errno in Diagnostics_area in case the signal is raised from a trigger
and SQLSTATE has value '02TRG'.

To catch signal with SQLTSATE '02TRG' and handle it in special way, the methods
 Table_triggers_list::process_triggers
 select_insert::store_values
 select_create::store_values
 Rows_log_event::process_triggers
and the overloaded function
 fill_record_n_invoke_before_triggers
were extended with extra out parameter for returning the flag whether
to skip the current values being processed by INSERT/UPDATE/DELETE
statement. This extra parameter is passed as nullptr in case of AFTER trigger
and BEFORE trigger this parameter points to a variable to store a marker
whether to skip the current record or store it by calling write_record().
This commit is contained in:
Dmitry Shulga
2025-01-27 16:29:25 +07:00
parent fcf7211136
commit 4c956fa15b
17 changed files with 1097 additions and 64 deletions

View File

@ -2130,7 +2130,7 @@ public:
#define SUB_STMT_TRIGGER 1
#define SUB_STMT_FUNCTION 2
#define SUB_STMT_STAT_TABLES 4
#define SUB_STMT_BEFORE_TRIGGER 8
class Sub_statement_state
{
@ -6666,7 +6666,7 @@ class select_insert :public select_result_interceptor {
int prepare(List<Item> &list, SELECT_LEX_UNIT *u) override;
int prepare2(JOIN *join) override;
int send_data(List<Item> &items) override;
virtual bool store_values(List<Item> &values);
virtual bool store_values(List<Item> &values, bool *trg_skip_row);
virtual bool can_rollback_data() { return 0; }
bool prepare_eof();
bool send_ok_packet();
@ -6711,7 +6711,7 @@ public:
int prepare(List<Item> &list, SELECT_LEX_UNIT *u) override;
int binlog_show_create_table(TABLE **tables, uint count);
bool store_values(List<Item> &values) override;
bool store_values(List<Item> &values, bool *trg_skip_row) override;
bool send_eof() override;
void abort_result_set() override;
bool can_rollback_data() override { return 1; }