Skip to content

Commit 6a2fbdf

Browse files
committed
MDEV-6979 simplify trigger rules for RBR triggers
Rows_log_event::write_row - don't optimize DELETE+INSERT into UPDATE if RBR triggers are used
1 parent 1bd1c29 commit 6a2fbdf

File tree

3 files changed

+26
-33
lines changed

3 files changed

+26
-33
lines changed

mysql-test/suite/rpl/r/rpl_row_triggers.result

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ i0 1 a
6565
i1 1 a
6666
u0 1 a d
6767
u1 1 a d
68-
# INSERT triggers which cause also UPDATE test (insert duplicate row)
68+
# INSERT triggers causing DELETE + INSERT (on unique key conflict)
6969
insert into t1 values ('0','1');
7070
SELECT * FROM t2 order by id;
7171
id cnt o n
@@ -78,25 +78,25 @@ u1 1 a d
7878
insert into t1 values ('0','1');
7979
SELECT * FROM t2 order by id;
8080
id cnt o n
81-
d0 1 d
82-
d1 1 d
81+
d0 2 0
82+
d1 2 0
8383
i0 3 0
8484
i1 3 0
85-
u0 2 0 0
86-
u1 2 0 0
85+
u0 1 a d
86+
u1 1 a d
8787
# INSERT triggers which cause also DELETE test
8888
# (insert duplicate row in table referenced by foreign key)
8989
insert into t1 values ('1','1');
9090
CREATE TABLE t3 (C1 CHAR(1) primary key, FOREIGN KEY (C1) REFERENCES t1(C1) ) engine=innodb;
9191
insert into t1 values ('1','1');
9292
SELECT * FROM t2 order by id;
9393
id cnt o n
94-
d0 2 1
95-
d1 2 1
94+
d0 3 1
95+
d1 3 1
9696
i0 5 1
9797
i1 5 1
98-
u0 2 0 0
99-
u1 2 0 0
98+
u0 1 a d
99+
u1 1 a d
100100
drop table t3,t1;
101101
SET @@global.slave_exec_mode= @old_slave_exec_mode;
102102
SET @@global.slave_run_triggers_for_rbr= @old_slave_run_triggers_for_rbr;

mysql-test/suite/rpl/t/rpl_row_triggers.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ sync_slave_with_master;
6464
connection slave;
6565
SELECT * FROM t2 order by id;
6666

67-
--echo # INSERT triggers which cause also UPDATE test (insert duplicate row)
67+
--echo # INSERT triggers causing DELETE + INSERT (on unique key conflict)
6868
insert into t1 values ('0','1');
6969

7070
SELECT * FROM t2 order by id;

sql/log_event.cc

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11471,36 +11471,29 @@ Rows_log_event::write_row(rpl_group_info *rgi,
1147111471
then there might be another key for which the unique check will
1147211472
fail, so we're better off just deleting the row and inserting
1147311473
the correct row.
11474+
11475+
Additionally we don't use UPDATE if rbr triggers should be invoked -
11476+
when triggers are used we want a simple and predictable execution path.
1147411477
*/
11475-
if (last_uniq_key(table, keynum) &&
11478+
if (last_uniq_key(table, keynum) && !invoke_triggers &&
1147611479
!table->file->referenced_by_foreign_key())
1147711480
{
1147811481
DBUG_PRINT("info",("Updating row using ha_update_row()"));
11479-
if (invoke_triggers &&
11480-
process_triggers(TRG_EVENT_UPDATE, TRG_ACTION_BEFORE, FALSE))
11481-
error= HA_ERR_GENERIC; // in case if error is not set yet
11482-
else
11483-
{
11484-
error= table->file->ha_update_row(table->record[1],
11485-
table->record[0]);
11486-
switch (error) {
11482+
error= table->file->ha_update_row(table->record[1],
11483+
table->record[0]);
11484+
switch (error) {
1148711485

11488-
case HA_ERR_RECORD_IS_THE_SAME:
11489-
DBUG_PRINT("info",("ignoring HA_ERR_RECORD_IS_THE_SAME error from"
11490-
" ha_update_row()"));
11491-
error= 0;
11486+
case HA_ERR_RECORD_IS_THE_SAME:
11487+
DBUG_PRINT("info",("ignoring HA_ERR_RECORD_IS_THE_SAME error from"
11488+
" ha_update_row()"));
11489+
error= 0;
1149211490

11493-
case 0:
11494-
break;
11491+
case 0:
11492+
break;
1149511493

11496-
default:
11497-
DBUG_PRINT("info",("ha_update_row() returns error %d",error));
11498-
table->file->print_error(error, MYF(0));
11499-
}
11500-
if (invoke_triggers && !error &&
11501-
(process_triggers(TRG_EVENT_UPDATE, TRG_ACTION_AFTER, TRUE) ||
11502-
process_triggers(TRG_EVENT_INSERT, TRG_ACTION_AFTER, TRUE)))
11503-
error= HA_ERR_GENERIC; // in case if error is not set yet
11494+
default:
11495+
DBUG_PRINT("info",("ha_update_row() returns error %d",error));
11496+
table->file->print_error(error, MYF(0));
1150411497
}
1150511498

1150611499
DBUG_RETURN(error);

0 commit comments

Comments
 (0)