MDEV-41464 INSERTING/UPDATING/DELETING, OLD, NEW in multi-event triggers #5853
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.72) × (1 − Review Confidence (0.64)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.72 · 1191 lines diff across 16 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.35 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.400
Mass File Touch
mass_file_touch
0.080
Real PR Conversation Timeline
4 items
Approved
Thank you for your contribution! This is a preliminary review.
LGTM. Please stand by for the final review.
Changes Requested
hmm, spoke too soon. main.trigger-33083 failure seems related. Please have a look
Approved
Thank for test suite stabilization!
LGTM. Please stand by for the final review.
gkodinov
arcivanov
https://jira.mariadb.org/browse/MDEV-41464
A trigger defined for several events (
CREATE TRIGGER ... BEFORE INSERT OR DELETE ...) did not see the event that fired it.INSERTING,UPDATINGandDELETINGreported the kind of the DML statement instead,OLDin a firing for an INSERT event andNEWin a firing for a DELETE event were NULL to some ways of reading them and not to others, and a value written toNEWthrough a routine argument could be stored in the wrong row.1.
MDEV-41464 INSERTING/UPDATING/DELETING, OLD, NEW in multi-event triggersINSERTING,UPDATING,DELETING. The item read a per-statement stack thatmysql_insert(),Sql_cmd_update::execute_inner()andSql_cmd_delete::execute_inner()pushed the kind of their statement on, through theTHDthat parsed the trigger body. That was wrong forINSERT ... SELECT,REPLACE ... SELECTandLOAD DATA, which push nothing; for a statement run by the trigger body, which pushed its own kind on top; in a connection other than the one that loaded the triggers into theTABLE; for a firing of another event than the statement's own (the rowREPLACEdeletes, the rowINSERT ... ON DUPLICATE KEY UPDATEupdates, the rows... FOR PORTION OFinserts); and as a value, whereItem_intreturned the constant 0. The item is now anItem_bool_functhat compares its event with the event of the innermost trigger being run, read from theTHDevaluating it. The statement stack andRunning_stmt_guardare removed. The trigger event stack becomes onetrg_event_typeonStatement, whichTrigger_event_guardsaves and restores, so recording the event can no longer fail on allocation.OLDon INSERT andNEWon DELETE. NULL was produced by overriding someval_()methods ofItem_trigger_field, andis_null(),get_date()andval_native()went around them to the record buffer.IS NULLcould return 0,DATE_FORMAT()andINET6values returned whatever the buffer held (in the firings ofREPLACE, the other of its two rows), andYEAR()failed a debug assertion. For a table that has a multi-event trigger,Table_triggers_listnow keepsnull_row_field, a copy of the fields whose null bit is always set, andprocess_triggers()binds it asOLDin an INSERT firing and asNEWin a DELETE firing. Every way of reading the field then sees NULL, and the overrides are removed.NEWas an OUT or INOUT argument.CREATE TRIGGERrefusesSET NEW.b= ...in a BEFORE trigger also defined for DELETE, but acceptedNEW.bas an OUT or INOUT argument of a procedure or a stored function, and in the DELETE firing ofREPLACEthe value was written into the row about to be inserted. The mode of a parameter is only known once the routine is called, so the check is made there:sp_head::bind_input_param()asks the newSettable_routine_parameter::check_settable(), whichItem_trigger_fieldanswers withER_TRG_NO_SUCH_ROW_IN_TRG, the errorSET NEWgets, when the trigger is running for a DELETE event. The routine does not run. INSERT and UPDATE firings writeNEWas before.2.
Replace active_dml_stmt with trg_event_typeWith the statement stack gone,
enum class active_dml_stmtonly named the three clauses a second time.enum trg_event_typemoves unchanged fromsql_trigger.htosql_basic_types.hin its place, so the item holds the event it names,val_bool()is a comparison,Item_trigger_type_of_statement::clause_name()names the clauses for bothfunc_name_cstring()andER_INCOMPATIBLE_EVENT_FLAG, andLEX::create_item_ident_trigger_specific()checks the event once instead of once per clause.Testing
The
End of 12.3 testssection ofmain.triggerholds 42 checks, each a statement and the value it must produce, and asserts at the end that every check got its value, listing those that did not. It covers each statement kind above, a trigger body's own statements, a second connection and one that has disconnected,OLDandNEWread as a value, throughIS NULL, as aDATE, anINET6and from aNOT NULLcolumn in AFTER and BEFORE triggers, andNEWas an INOUT argument of a procedure and of a function in INSERT, UPDATE,REPLACEand DELETE firings.On a debug build, each commit:
main,innodb,binlog,funcs_1,rpl,parts,sys_vars,perfschema,compat/oracle,versioning,period,spider:Completed: All 5710 tests were successful.; embeddedmain,funcs_1,compat/oracle,versioning:Completed: All 1173 tests were successful.