Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
af3180ab
Commit
af3180ab
authored
Mar 19, 2014
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-9095: Executing triggers on slave in row-based replication
parent
f1ca1f37
Changes
20
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
956 additions
and
130 deletions
+956
-130
mysql-test/include/have_rbr_triggers.inc
mysql-test/include/have_rbr_triggers.inc
+5
-0
mysql-test/r/mysqld--help.result
mysql-test/r/mysqld--help.result
+1
-0
mysql-test/suite/rpl/r/rpl_row_triggers.result
mysql-test/suite/rpl/r/rpl_row_triggers.result
+240
-0
mysql-test/suite/rpl/r/rpl_row_triggers_sbr.result
mysql-test/suite/rpl/r/rpl_row_triggers_sbr.result
+14
-0
mysql-test/suite/rpl/t/rpl_row_triggers.test
mysql-test/suite/rpl/t/rpl_row_triggers.test
+280
-0
mysql-test/suite/rpl/t/rpl_row_triggers_sbr.test
mysql-test/suite/rpl/t/rpl_row_triggers_sbr.test
+43
-0
sql/log_event.cc
sql/log_event.cc
+228
-41
sql/log_event.h
sql/log_event.h
+25
-2
sql/mysqld.cc
sql/mysqld.cc
+1
-0
sql/mysqld.h
sql/mysqld.h
+1
-0
sql/rpl_utility.h
sql/rpl_utility.h
+1
-0
sql/sql_class.h
sql/sql_class.h
+3
-0
sql/sql_delete.cc
sql/sql_delete.cc
+2
-20
sql/sql_insert.cc
sql/sql_insert.cc
+6
-44
sql/sql_insert.h
sql/sql_insert.h
+0
-1
sql/sql_load.cc
sql/sql_load.cc
+2
-2
sql/sql_update.cc
sql/sql_update.cc
+2
-20
sql/sys_vars.cc
sql/sys_vars.cc
+15
-0
sql/table.cc
sql/table.cc
+79
-0
sql/table.h
sql/table.h
+8
-0
No files found.
mysql-test/include/have_rbr_triggers.inc
0 → 100644
View file @
af3180ab
if
(
`select count(*) = 0 from information_schema.session_variables where variable_name = 'slave_run_triggers_for_rbr'`
)
{
skip
RBR
triggers
are
not
available
;
}
mysql-test/r/mysqld--help.result
View file @
af3180ab
...
...
@@ -1301,6 +1301,7 @@ slave-max-allowed-packet 1073741824
slave-net-timeout 3600
slave-parallel-max-queued 131072
slave-parallel-threads 0
slave-run-triggers-for-rbr NO
slave-skip-errors (No default value)
slave-sql-verify-checksum TRUE
slave-transaction-retries 10
...
...
mysql-test/suite/rpl/r/rpl_row_triggers.result
0 → 100644
View file @
af3180ab
include/master-slave.inc
[connection master]
# Test of row replication with triggers on the slave side
CREATE TABLE t1 (C1 CHAR(1) primary key, C2 CHAR(1)) engine=innodb;
SELECT * FROM t1;
C1 C2
SET @old_slave_exec_mode= @@global.slave_exec_mode;
SET @old_slave_run_triggers_for_rbr= @@global.slave_run_triggers_for_rbr;
SET @@global.slave_exec_mode= IDEMPOTENT;
SET @@global.slave_run_triggers_for_rbr= YES;
SELECT * FROM t1;
C1 C2
create table t2 (id char(2) primary key, cnt int, o char(1), n char(1));
insert into t2 values
('u0', 0, ' ', ' '),('u1', 0, ' ', ' '),
('d0', 0, ' ', ' '),('d1', 0, ' ', ' '),
('i0', 0, ' ', ' '),('i1', 0, ' ', ' ');
create trigger t1_cnt_b before update on t1 for each row
update t2 set cnt=cnt+1, o=old.C1, n=new.C1 where id = 'u0';
create trigger t1_cnt_db before delete on t1 for each row
update t2 set cnt=cnt+1, o=old.C1, n=' ' where id = 'd0';
create trigger t1_cnt_ib before insert on t1 for each row
update t2 set cnt=cnt+1, n=new.C1, o=' ' where id = 'i0';
create trigger t1_cnt_a after update on t1 for each row
update t2 set cnt=cnt+1, o=old.C1, n=new.C1 where id = 'u1';
create trigger t1_cnt_da after delete on t1 for each row
update t2 set cnt=cnt+1, o=old.C1, n=' ' where id = 'd1';
create trigger t1_cnt_ia after insert on t1 for each row
update t2 set cnt=cnt+1, n=new.C1, o=' ' where id = 'i1';
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 0
i1 0
u0 0
u1 0
# INSERT triggers test
insert into t1 values ('a','b');
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 1 a
i1 1 a
u0 0
u1 0
# UPDATE triggers test
update t1 set C1= 'd';
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 1 a
i1 1 a
u0 1 a d
u1 1 a d
# DELETE triggers test
delete from t1 where C1='d';
SELECT * FROM t2 order by id;
id cnt o n
d0 1 d
d1 1 d
i0 1 a
i1 1 a
u0 1 a d
u1 1 a d
# INSERT triggers which cause also UPDATE test (insert duplicate row)
insert into t1 values ('0','1');
SELECT * FROM t2 order by id;
id cnt o n
d0 1 d
d1 1 d
i0 2 0
i1 2 0
u0 1 a d
u1 1 a d
insert into t1 values ('0','1');
SELECT * FROM t2 order by id;
id cnt o n
d0 1 d
d1 1 d
i0 3 0
i1 3 0
u0 2 0 0
u1 2 0 0
# INSERT triggers which cause also DELETE test
# (insert duplicate row in table referenced by foreign key)
insert into t1 values ('1','1');
CREATE TABLE t3 (C1 CHAR(1) primary key, FOREIGN KEY (C1) REFERENCES t1(C1) ) engine=innodb;
insert into t1 values ('1','1');
SELECT * FROM t2 order by id;
id cnt o n
d0 2 1
d1 2 1
i0 5 1
i1 5 1
u0 2 0 0
u1 2 0 0
drop table t3,t1;
SET @@global.slave_exec_mode= @old_slave_exec_mode;
SET @@global.slave_run_triggers_for_rbr= @old_slave_run_triggers_for_rbr;
drop table t2;
CREATE TABLE t1 (i INT) ENGINE=InnoDB;
CREATE TABLE t2 (i INT) ENGINE=InnoDB;
SET @old_slave_run_triggers_for_rbr= @@global.slave_run_triggers_for_rbr;
SET GLOBAL slave_run_triggers_for_rbr=YES;
CREATE TRIGGER tr AFTER INSERT ON t1 FOR EACH ROW
INSERT INTO t2 VALUES (new.i);
BEGIN;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
COMMIT;
select * from t2;
i
1
2
SET @@global.slave_run_triggers_for_rbr= @old_slave_run_triggers_for_rbr;
drop tables t2,t1;
# Triggers on slave do not work if master has some
CREATE TABLE t1 (C1 CHAR(1) primary key, C2 CHAR(1)) engine=innodb;
SELECT * FROM t1;
C1 C2
create trigger t1_dummy before delete on t1 for each row
set @dummy= 1;
SET @old_slave_exec_mode= @@global.slave_exec_mode;
SET @old_slave_run_triggers_for_rbr= @@global.slave_run_triggers_for_rbr;
SET @@global.slave_exec_mode= IDEMPOTENT;
SET @@global.slave_run_triggers_for_rbr= YES;
SELECT * FROM t1;
C1 C2
create table t2 (id char(2) primary key, cnt int, o char(1), n char(1));
insert into t2 values
('u0', 0, ' ', ' '),('u1', 0, ' ', ' '),
('d0', 0, ' ', ' '),('d1', 0, ' ', ' '),
('i0', 0, ' ', ' '),('i1', 0, ' ', ' ');
create trigger t1_cnt_b before update on t1 for each row
update t2 set cnt=cnt+1, o=old.C1, n=new.C1 where id = 'u0';
create trigger t1_cnt_ib before insert on t1 for each row
update t2 set cnt=cnt+1, n=new.C1, o=' ' where id = 'i0';
create trigger t1_cnt_a after update on t1 for each row
update t2 set cnt=cnt+1, o=old.C1, n=new.C1 where id = 'u1';
create trigger t1_cnt_da after delete on t1 for each row
update t2 set cnt=cnt+1, o=old.C1, n=' ' where id = 'd1';
create trigger t1_cnt_ia after insert on t1 for each row
update t2 set cnt=cnt+1, n=new.C1, o=' ' where id = 'i1';
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 0
i1 0
u0 0
u1 0
# INSERT triggers test
insert into t1 values ('a','b');
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 0
i1 0
u0 0
u1 0
# UPDATE triggers test
update t1 set C1= 'd';
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 0
i1 0
u0 0
u1 0
# DELETE triggers test
delete from t1 where C1='d';
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 0
i1 0
u0 0
u1 0
# INSERT triggers which cause also UPDATE test (insert duplicate row)
insert into t1 values ('0','1');
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 1 0
i1 1 0
u0 0
u1 0
insert into t1 values ('0','1');
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 1 0
i1 1 0
u0 0
u1 0
# INSERT triggers which cause also DELETE test
# (insert duplicate row in table referenced by foreign key)
insert into t1 values ('1','1');
CREATE TABLE t3 (C1 CHAR(1) primary key, FOREIGN KEY (C1) REFERENCES t1(C1) ) engine=innodb;
insert into t1 values ('1','1');
SELECT * FROM t2 order by id;
id cnt o n
d0 0
d1 0
i0 2 1
i1 2 1
u0 0
u1 0
drop table t3,t1;
SET @@global.slave_exec_mode= @old_slave_exec_mode;
SET @@global.slave_run_triggers_for_rbr= @old_slave_run_triggers_for_rbr;
drop table t2;
#
# MDEV-5513: Trigger is applied to the rows after first one
#
create table t1 (a int, b int);
create table tlog (a int);
set sql_log_bin=0;
create trigger tr1 after insert on t1 for each row insert into tlog values (1);
set sql_log_bin=1;
set @slave_run_triggers_for_rbr.saved = @@slave_run_triggers_for_rbr;
set global slave_run_triggers_for_rbr=1;
create trigger tr2 before insert on t1 for each row set new.b = new.a;
insert into t1 values (1,10),(2,20),(3,30);
select * from t1;
a b
1 10
2 20
3 30
set global slave_run_triggers_for_rbr = @slave_run_triggers_for_rbr.saved;
drop table t1, tlog;
include/rpl_end.inc
mysql-test/suite/rpl/r/rpl_row_triggers_sbr.result
0 → 100644
View file @
af3180ab
include/master-slave.inc
[connection master]
set binlog_format = row;
create table t1 (i int);
create table t2 (i int);
SET @old_slave_run_triggers_for_rbr= @@global.slave_run_triggers_for_rbr;
set global slave_run_triggers_for_rbr=YES;
create trigger tr_before before insert on t1 for each row
insert into t2 values (1);
insert into t1 values (1);
include/wait_for_slave_sql_error_and_skip.inc [errno=1666]
drop tables t1,t2;
SET @@global.slave_run_triggers_for_rbr= @old_slave_run_triggers_for_rbr;
include/rpl_end.inc
mysql-test/suite/rpl/t/rpl_row_triggers.test
0 → 100644
View file @
af3180ab
--
source
include
/
have_binlog_format_row
.
inc
--
source
include
/
have_rbr_triggers
.
inc
--
source
include
/
have_innodb
.
inc
--
source
include
/
master
-
slave
.
inc
--
echo
# Test of row replication with triggers on the slave side
connection
master
;
CREATE
TABLE
t1
(
C1
CHAR
(
1
)
primary
key
,
C2
CHAR
(
1
))
engine
=
innodb
;
SELECT
*
FROM
t1
;
sync_slave_with_master
;
connection
slave
;
SET
@
old_slave_exec_mode
=
@@
global
.
slave_exec_mode
;
SET
@
old_slave_run_triggers_for_rbr
=
@@
global
.
slave_run_triggers_for_rbr
;
SET
@@
global
.
slave_exec_mode
=
IDEMPOTENT
;
SET
@@
global
.
slave_run_triggers_for_rbr
=
YES
;
SELECT
*
FROM
t1
;
create
table
t2
(
id
char
(
2
)
primary
key
,
cnt
int
,
o
char
(
1
),
n
char
(
1
));
insert
into
t2
values
(
'u0'
,
0
,
' '
,
' '
),(
'u1'
,
0
,
' '
,
' '
),
(
'd0'
,
0
,
' '
,
' '
),(
'd1'
,
0
,
' '
,
' '
),
(
'i0'
,
0
,
' '
,
' '
),(
'i1'
,
0
,
' '
,
' '
);
create
trigger
t1_cnt_b
before
update
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
o
=
old
.
C1
,
n
=
new
.
C1
where
id
=
'u0'
;
create
trigger
t1_cnt_db
before
delete
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
o
=
old
.
C1
,
n
=
' '
where
id
=
'd0'
;
create
trigger
t1_cnt_ib
before
insert
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
n
=
new
.
C1
,
o
=
' '
where
id
=
'i0'
;
create
trigger
t1_cnt_a
after
update
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
o
=
old
.
C1
,
n
=
new
.
C1
where
id
=
'u1'
;
create
trigger
t1_cnt_da
after
delete
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
o
=
old
.
C1
,
n
=
' '
where
id
=
'd1'
;
create
trigger
t1_cnt_ia
after
insert
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
n
=
new
.
C1
,
o
=
' '
where
id
=
'i1'
;
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
--
echo
# INSERT triggers test
insert
into
t1
values
(
'a'
,
'b'
);
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
--
echo
# UPDATE triggers test
update
t1
set
C1
=
'd'
;
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
--
echo
# DELETE triggers test
delete
from
t1
where
C1
=
'd'
;
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
--
echo
# INSERT triggers which cause also UPDATE test (insert duplicate row)
insert
into
t1
values
(
'0'
,
'1'
);
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
insert
into
t1
values
(
'0'
,
'1'
);
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
--
echo
# INSERT triggers which cause also DELETE test
--
echo
# (insert duplicate row in table referenced by foreign key)
insert
into
t1
values
(
'1'
,
'1'
);
connection
master
;
CREATE
TABLE
t3
(
C1
CHAR
(
1
)
primary
key
,
FOREIGN
KEY
(
C1
)
REFERENCES
t1
(
C1
)
)
engine
=
innodb
;
insert
into
t1
values
(
'1'
,
'1'
);
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
drop
table
t3
,
t1
;
sync_slave_with_master
;
connection
slave
;
SET
@@
global
.
slave_exec_mode
=
@
old_slave_exec_mode
;
SET
@@
global
.
slave_run_triggers_for_rbr
=
@
old_slave_run_triggers_for_rbr
;
drop
table
t2
;
--
connection
master
CREATE
TABLE
t1
(
i
INT
)
ENGINE
=
InnoDB
;
CREATE
TABLE
t2
(
i
INT
)
ENGINE
=
InnoDB
;
--
sync_slave_with_master
SET
@
old_slave_run_triggers_for_rbr
=
@@
global
.
slave_run_triggers_for_rbr
;
SET
GLOBAL
slave_run_triggers_for_rbr
=
YES
;
CREATE
TRIGGER
tr
AFTER
INSERT
ON
t1
FOR
EACH
ROW
INSERT
INTO
t2
VALUES
(
new
.
i
);
--
connection
master
BEGIN
;
INSERT
INTO
t1
VALUES
(
1
);
INSERT
INTO
t1
VALUES
(
2
);
COMMIT
;
--
sync_slave_with_master
select
*
from
t2
;
SET
@@
global
.
slave_run_triggers_for_rbr
=
@
old_slave_run_triggers_for_rbr
;
--
connection
master
drop
tables
t2
,
t1
;
--
sync_slave_with_master
--
echo
# Triggers on slave do not work if master has some
connection
master
;
CREATE
TABLE
t1
(
C1
CHAR
(
1
)
primary
key
,
C2
CHAR
(
1
))
engine
=
innodb
;
SELECT
*
FROM
t1
;
create
trigger
t1_dummy
before
delete
on
t1
for
each
row
set
@
dummy
=
1
;
sync_slave_with_master
;
connection
slave
;
SET
@
old_slave_exec_mode
=
@@
global
.
slave_exec_mode
;
SET
@
old_slave_run_triggers_for_rbr
=
@@
global
.
slave_run_triggers_for_rbr
;
SET
@@
global
.
slave_exec_mode
=
IDEMPOTENT
;
SET
@@
global
.
slave_run_triggers_for_rbr
=
YES
;
SELECT
*
FROM
t1
;
create
table
t2
(
id
char
(
2
)
primary
key
,
cnt
int
,
o
char
(
1
),
n
char
(
1
));
insert
into
t2
values
(
'u0'
,
0
,
' '
,
' '
),(
'u1'
,
0
,
' '
,
' '
),
(
'd0'
,
0
,
' '
,
' '
),(
'd1'
,
0
,
' '
,
' '
),
(
'i0'
,
0
,
' '
,
' '
),(
'i1'
,
0
,
' '
,
' '
);
create
trigger
t1_cnt_b
before
update
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
o
=
old
.
C1
,
n
=
new
.
C1
where
id
=
'u0'
;
create
trigger
t1_cnt_ib
before
insert
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
n
=
new
.
C1
,
o
=
' '
where
id
=
'i0'
;
create
trigger
t1_cnt_a
after
update
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
o
=
old
.
C1
,
n
=
new
.
C1
where
id
=
'u1'
;
create
trigger
t1_cnt_da
after
delete
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
o
=
old
.
C1
,
n
=
' '
where
id
=
'd1'
;
create
trigger
t1_cnt_ia
after
insert
on
t1
for
each
row
update
t2
set
cnt
=
cnt
+
1
,
n
=
new
.
C1
,
o
=
' '
where
id
=
'i1'
;
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
--
echo
# INSERT triggers test
insert
into
t1
values
(
'a'
,
'b'
);
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
--
echo
# UPDATE triggers test
update
t1
set
C1
=
'd'
;
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
--
echo
# DELETE triggers test
delete
from
t1
where
C1
=
'd'
;
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
--
echo
# INSERT triggers which cause also UPDATE test (insert duplicate row)
insert
into
t1
values
(
'0'
,
'1'
);
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
insert
into
t1
values
(
'0'
,
'1'
);
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
--
echo
# INSERT triggers which cause also DELETE test
--
echo
# (insert duplicate row in table referenced by foreign key)
insert
into
t1
values
(
'1'
,
'1'
);
connection
master
;
CREATE
TABLE
t3
(
C1
CHAR
(
1
)
primary
key
,
FOREIGN
KEY
(
C1
)
REFERENCES
t1
(
C1
)
)
engine
=
innodb
;
insert
into
t1
values
(
'1'
,
'1'
);
sync_slave_with_master
;
connection
slave
;
SELECT
*
FROM
t2
order
by
id
;
connection
master
;
drop
table
t3
,
t1
;
sync_slave_with_master
;
connection
slave
;
SET
@@
global
.
slave_exec_mode
=
@
old_slave_exec_mode
;
SET
@@
global
.
slave_run_triggers_for_rbr
=
@
old_slave_run_triggers_for_rbr
;
drop
table
t2
;
--
echo
#
--
echo
# MDEV-5513: Trigger is applied to the rows after first one
--
echo
#
--
connection
master
create
table
t1
(
a
int
,
b
int
);
create
table
tlog
(
a
int
);
set
sql_log_bin
=
0
;
create
trigger
tr1
after
insert
on
t1
for
each
row
insert
into
tlog
values
(
1
);
set
sql_log_bin
=
1
;
sync_slave_with_master
;
--
connection
slave
set
@
slave_run_triggers_for_rbr
.
saved
=
@@
slave_run_triggers_for_rbr
;
set
global
slave_run_triggers_for_rbr
=
1
;
create
trigger
tr2
before
insert
on
t1
for
each
row
set
new
.
b
=
new
.
a
;
--
connection
master
insert
into
t1
values
(
1
,
10
),(
2
,
20
),(
3
,
30
);
--
sync_slave_with_master
select
*
from
t1
;
# Cleanup
set
global
slave_run_triggers_for_rbr
=
@
slave_run_triggers_for_rbr
.
saved
;
--
connection
master
drop
table
t1
,
tlog
;
sync_slave_with_master
;
--
source
include
/
rpl_end
.
inc
mysql-test/suite/rpl/t/rpl_row_triggers_sbr.test
0 → 100644
View file @
af3180ab
--
source
include
/
have_binlog_format_statement
.
inc
--
source
include
/
have_rbr_triggers
.
inc
--
source
include
/
master
-
slave
.
inc
--
disable_query_log
CALL
mtr
.
add_suppression
(
"Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT"
);
--
enable_query_log
set
binlog_format
=
row
;
create
table
t1
(
i
int
);
create
table
t2
(
i
int
);
--
sync_slave_with_master
--
disable_query_log
CALL
mtr
.
add_suppression
(
"impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT"
);
--
enable_query_log
SET
@
old_slave_run_triggers_for_rbr
=
@@
global
.
slave_run_triggers_for_rbr
;
set
global
slave_run_triggers_for_rbr
=
YES
;
create
trigger
tr_before
before
insert
on
t1
for
each
row
insert
into
t2
values
(
1
);
--
connection
master
insert
into
t1
values
(
1
);
--
connection
slave
--
let
$slave_sql_errno
=
1666
--
source
include
/
wait_for_slave_sql_error_and_skip
.
inc
--
connection
master
drop
tables
t1
,
t2
;
--
sync_slave_with_master
SET
@@
global
.
slave_run_triggers_for_rbr
=
@
old_slave_run_triggers_for_rbr
;
--
connection
master
--
source
include
/
rpl_end
.
inc
sql/log_event.cc
View file @
af3180ab
This diff is collapsed.
Click to expand it.
sql/log_event.h
View file @
af3180ab
...
...
@@ -4049,7 +4049,9 @@ public:
enum
{
TM_NO_FLAGS
=
0U
,
TM_BIT_LEN_EXACT_F
=
(
1U
<<
0
)
TM_BIT_LEN_EXACT_F
=
(
1U
<<
0
),
// MariaDB flags (we starts from the other end)
TM_BIT_HAS_TRIGGERS_F
=
(
1U
<<
14
)
};
flag_set
get_flags
(
flag_set
flag
)
const
{
return
m_flags
&
flag
;
}
...
...
@@ -4254,6 +4256,10 @@ public:
const
uchar
*
get_extra_row_data
()
const
{
return
m_extra_row_data
;
}
#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
virtual
uint8
get_trg_event_map
()
=
0
;
#endif
protected:
/*
The constructors are protected since you're supposed to inherit
...
...
@@ -4307,6 +4313,7 @@ protected:
uchar
*
m_extra_row_data
;
/* Pointer to extra row data if any */
/* If non null, first byte is length */
/* helper functions */
#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
...
...
@@ -4315,6 +4322,7 @@ protected:
uchar
*
m_key
;
/* Buffer to keep key value during searches */
KEY
*
m_key_info
;
/* Pointer to KEY info for m_key_nr */
uint
m_key_nr
;
/* Key number */
bool
master_had_triggers
;
/* set after tables opening */
int
find_key
();
// Find a best key to use in find_row()
int
find_row
(
rpl_group_info
*
);
...
...
@@ -4329,6 +4337,9 @@ protected:
return
::
unpack_row
(
rgi
,
m_table
,
m_width
,
m_curr_row
,
&
m_cols
,
&
m_curr_row_end
,
&
m_master_reclength
,
m_rows_end
);
}
bool
process_triggers
(
trg_event_type
event
,
trg_action_time_type
time_type
,
bool
old_row_is_record1
);
#endif
private:
...
...
@@ -4433,6 +4444,10 @@ public:
}
#endif
#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
uint8
get_trg_event_map
();
#endif
private:
virtual
Log_event_type
get_general_type_code
()
{
return
(
Log_event_type
)
TYPE_CODE
;
}
...
...
@@ -4507,6 +4522,10 @@ public:
return
Rows_log_event
::
is_valid
()
&&
m_cols_ai
.
bitmap
;
}
#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
uint8
get_trg_event_map
();
#endif
protected:
virtual
Log_event_type
get_general_type_code
()
{
return
(
Log_event_type
)
TYPE_CODE
;
}
...
...
@@ -4572,6 +4591,10 @@ public:
}
#endif
#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
uint8
get_trg_event_map
();
#endif
protected:
virtual
Log_event_type
get_general_type_code
()
{
return
(
Log_event_type
)
TYPE_CODE
;
}
...
...
sql/mysqld.cc
View file @
af3180ab
...
...
@@ -479,6 +479,7 @@ ulong open_files_limit, max_binlog_size;
ulong
slave_trans_retries
;
uint
slave_net_timeout
;
ulong
slave_exec_mode_options
;
ulong
slave_run_triggers_for_rbr
=
0
;
ulong
slave_ddl_exec_mode_options
=
SLAVE_EXEC_MODE_IDEMPOTENT
;
ulonglong
slave_type_conversions_options
;
ulong
thread_cache_size
=
0
;
...
...
sql/mysqld.h
View file @
af3180ab
...
...
@@ -98,6 +98,7 @@ extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
extern
my_bool
opt_slave_compressed_protocol
,
use_temp_pool
;
extern
ulong
slave_exec_mode_options
,
slave_ddl_exec_mode_options
;
extern
ulong
slave_retried_transactions
;
extern
ulong
slave_run_triggers_for_rbr
;
extern
ulonglong
slave_type_conversions_options
;
extern
my_bool
read_only
,
opt_readonly
;
extern
my_bool
lower_case_file_system
;
...
...
sql/rpl_utility.h
View file @
af3180ab
...
...
@@ -238,6 +238,7 @@ struct RPL_TABLE_LIST
bool
m_tabledef_valid
;
table_def
m_tabledef
;
TABLE
*
m_conv_table
;
bool
master_had_triggers
;
};
...
...
sql/sql_class.h
View file @
af3180ab
...
...
@@ -80,6 +80,9 @@ enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON,
enum
enum_slave_exec_mode
{
SLAVE_EXEC_MODE_STRICT
,
SLAVE_EXEC_MODE_IDEMPOTENT
,
SLAVE_EXEC_MODE_LAST_BIT
};
enum
enum_slave_run_triggers_for_rbr
{
SLAVE_RUN_TRIGGERS_FOR_RBR_NO
,
SLAVE_RUN_TRIGGERS_FOR_RBR_YES
,
SLAVE_RUN_TRIGGERS_FOR_RBR_LOGGING
};
enum
enum_slave_type_conversions
{
SLAVE_TYPE_CONVERSIONS_ALL_LOSSY
,
SLAVE_TYPE_CONVERSIONS_ALL_NON_LOSSY
};
enum
enum_mark_columns
...
...
sql/sql_delete.cc
View file @
af3180ab
...
...
@@ -521,16 +521,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
init_ftfuncs
(
thd
,
select_lex
,
1
);
THD_STAGE_INFO
(
thd
,
stage_updating
);
if
(
table
->
triggers
&&
table
->
triggers
->
has_triggers
(
TRG_EVENT_DELETE
,
TRG_ACTION_AFTER
))
if
(
table
->
prepare_triggers_for_delete_stmt_or_event
())
{
/*
The table has AFTER DELETE triggers that might access to subject table
and therefore might need delete to be done immediately. So we turn-off
the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_DELETE_CANNOT_BATCH
);
will_batch
=
FALSE
;
}
else
...
...
@@ -938,17 +930,7 @@ multi_delete::initialize_tables(JOIN *join)
transactional_tables
=
1
;
else
normal_tables
=
1
;
if
(
tbl
->
triggers
&&
tbl
->
triggers
->
has_triggers
(
TRG_EVENT_DELETE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER DELETE triggers that might access to subject
table and therefore might need delete to be done immediately.
So we turn-off the batching.
*/
(
void
)
tbl
->
file
->
extra
(
HA_EXTRA_DELETE_CANNOT_BATCH
);
}
tbl
->
prepare_triggers_for_delete_stmt_or_event
();
tbl
->
prepare_for_position
();
tbl
->
mark_columns_needed_for_delete
();
}
...
...
sql/sql_insert.cc
View file @
af3180ab
...
...
@@ -373,48 +373,6 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
return
0
;
}
/*
Prepare triggers for INSERT-like statement.
SYNOPSIS
prepare_triggers_for_insert_stmt()
table Table to which insert will happen
NOTE
Prepare triggers for INSERT-like statement by marking fields
used by triggers and inform handlers that batching of UPDATE/DELETE
cannot be done if there are BEFORE UPDATE/DELETE triggers.
*/
void
prepare_triggers_for_insert_stmt
(
TABLE
*
table
)
{
if
(
table
->
triggers
)
{
if
(
table
->
triggers
->
has_triggers
(
TRG_EVENT_DELETE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER DELETE triggers that might access to
subject table and therefore might need delete to be done
immediately. So we turn-off the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_DELETE_CANNOT_BATCH
);
}
if
(
table
->
triggers
->
has_triggers
(
TRG_EVENT_UPDATE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER UPDATE triggers that might access to subject
table and therefore might need update to be done immediately.
So we turn-off the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_UPDATE_CANNOT_BATCH
);
}
}
table
->
mark_columns_needed_for_insert
();
}
/**
Upgrade table-level lock of INSERT statement to TL_WRITE if
a more concurrent lock is infeasible for some reason. This is
...
...
@@ -902,7 +860,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
thd
->
abort_on_warning
=
!
ignore
&&
thd
->
is_strict_mode
();
prepare_triggers_for_insert_stmt
(
table
);
table
->
prepare_triggers_for_insert_stmt_or_event
();
table
->
mark_columns_needed_for_insert
();
if
(
table_list
->
prepare_where
(
thd
,
0
,
TRUE
)
||
...
...
@@ -3537,7 +3496,10 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
table_list
->
prepare_check_option
(
thd
));
if
(
!
res
)
prepare_triggers_for_insert_stmt
(
table
);
{
table
->
prepare_triggers_for_insert_stmt_or_event
();
table
->
mark_columns_needed_for_insert
();
}
DBUG_RETURN
(
res
);
}
...
...
sql/sql_insert.h
View file @
af3180ab
...
...
@@ -38,7 +38,6 @@ void upgrade_lock_type_for_insert(THD *thd, thr_lock_type *lock_type,
bool
is_multi_insert
);
int
check_that_all_fields_are_given_values
(
THD
*
thd
,
TABLE
*
entry
,
TABLE_LIST
*
table_list
);
void
prepare_triggers_for_insert_stmt
(
TABLE
*
table
);
int
write_record
(
THD
*
thd
,
TABLE
*
table
,
COPY_INFO
*
info
);
void
kill_delayed_threads
(
void
);
...
...
sql/sql_load.cc
View file @
af3180ab
...
...
@@ -28,7 +28,6 @@
#include <my_dir.h>
#include "sql_view.h" // check_key_in_view
#include "sql_insert.h" // check_that_all_fields_are_given_values,
// prepare_triggers_for_insert_stmt,
// write_record
#include "sql_acl.h" // INSERT_ACL, UPDATE_ACL
#include "log_event.h" // Delete_file_log_event,
...
...
@@ -298,7 +297,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
DBUG_RETURN
(
TRUE
);
}
prepare_triggers_for_insert_stmt
(
table
);
table
->
prepare_triggers_for_insert_stmt_or_event
();
table
->
mark_columns_needed_for_insert
();
uint
tot_length
=
0
;
bool
use_blobs
=
0
,
use_vars
=
0
;
...
...
sql/sql_update.cc
View file @
af3180ab
...
...
@@ -703,16 +703,8 @@ int mysql_update(THD *thd,
transactional_table
=
table
->
file
->
has_transactions
();
thd
->
abort_on_warning
=
!
ignore
&&
thd
->
is_strict_mode
();
if
(
table
->
triggers
&&
table
->
triggers
->
has_triggers
(
TRG_EVENT_UPDATE
,
TRG_ACTION_AFTER
))
if
(
table
->
prepare_triggers_for_update_stmt_or_event
())
{
/*
The table has AFTER UPDATE triggers that might access to subject
table and therefore might need update to be done immediately.
So we turn-off the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_UPDATE_CANNOT_BATCH
);
will_batch
=
FALSE
;
}
else
...
...
@@ -1610,17 +1602,7 @@ int multi_update::prepare(List<Item> ¬_used_values,
table
->
no_keyread
=
1
;
table
->
covering_keys
.
clear_all
();
table
->
pos_in_table_list
=
tl
;
if
(
table
->
triggers
&&
table
->
triggers
->
has_triggers
(
TRG_EVENT_UPDATE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER UPDATE triggers that might access to subject
table and therefore might need update to be done immediately.
So we turn-off the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_UPDATE_CANNOT_BATCH
);
}
table
->
prepare_triggers_for_update_stmt_or_event
();
}
}
...
...
sql/sys_vars.cc
View file @
af3180ab
...
...
@@ -2737,6 +2737,21 @@ static Sys_var_enum Slave_ddl_exec_mode(
GLOBAL_VAR
(
slave_ddl_exec_mode_options
),
CMD_LINE
(
REQUIRED_ARG
),
slave_exec_mode_names
,
DEFAULT
(
SLAVE_EXEC_MODE_IDEMPOTENT
));
static
const
char
*
slave_run_triggers_for_rbr_names
[]
=
{
"NO"
,
"YES"
,
"LOGGING"
,
0
};
static
Sys_var_enum
Slave_run_triggers_for_rbr
(
"slave_run_triggers_for_rbr"
,
"Modes for how triggers in row-base replication on slave side will be "
"executed. Legal values are NO (default), YES and LOGGING. NO means "
"that trigger for RBR will not be running on slave. YES and LOGGING "
"means that triggers will be running on slave, if there was not "
"triggers running on the master for the statement. LOGGING also means "
"results of that the executed triggers work will be written to "
"the binlog."
,
GLOBAL_VAR
(
slave_run_triggers_for_rbr
),
CMD_LINE
(
REQUIRED_ARG
),
slave_run_triggers_for_rbr_names
,
DEFAULT
(
SLAVE_RUN_TRIGGERS_FOR_RBR_NO
));
static
const
char
*
slave_type_conversions_name
[]
=
{
"ALL_LOSSY"
,
"ALL_NON_LOSSY"
,
0
};
static
Sys_var_set
Slave_type_conversions
(
"slave_type_conversions"
,
...
...
sql/table.cc
View file @
af3180ab
...
...
@@ -3994,6 +3994,10 @@ void TABLE::init(THD *thd, TABLE_LIST *tl)
created
=
TRUE
;
cond_selectivity
=
1.0
;
cond_selectivity_sampling_explain
=
NULL
;
#ifdef HAVE_REPLICATION
/* used in RBR Triggers */
master_had_triggers
=
0
;
#endif
/* Catch wrong handling of the auto_increment_field_not_null. */
DBUG_ASSERT
(
!
auto_increment_field_not_null
);
...
...
@@ -6656,6 +6660,81 @@ int TABLE::update_default_fields()
}
/*
Prepare triggers for INSERT-like statement.
SYNOPSIS
prepare_triggers_for_insert_stmt_or_event()
NOTE
Prepare triggers for INSERT-like statement by marking fields
used by triggers and inform handlers that batching of UPDATE/DELETE
cannot be done if there are BEFORE UPDATE/DELETE triggers.
*/
void
TABLE
::
prepare_triggers_for_insert_stmt_or_event
()
{
if
(
triggers
)
{
if
(
triggers
->
has_triggers
(
TRG_EVENT_DELETE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER DELETE triggers that might access to
subject table and therefore might need delete to be done
immediately. So we turn-off the batching.
*/
(
void
)
file
->
extra
(
HA_EXTRA_DELETE_CANNOT_BATCH
);
}
if
(
triggers
->
has_triggers
(
TRG_EVENT_UPDATE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER UPDATE triggers that might access to subject
table and therefore might need update to be done immediately.
So we turn-off the batching.
*/
(
void
)
file
->
extra
(
HA_EXTRA_UPDATE_CANNOT_BATCH
);
}
}
}
bool
TABLE
::
prepare_triggers_for_delete_stmt_or_event
()
{
if
(
triggers
&&
triggers
->
has_triggers
(
TRG_EVENT_DELETE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER DELETE triggers that might access to subject table
and therefore might need delete to be done immediately. So we turn-off
the batching.
*/
(
void
)
file
->
extra
(
HA_EXTRA_DELETE_CANNOT_BATCH
);
return
TRUE
;
}
return
FALSE
;
}
bool
TABLE
::
prepare_triggers_for_update_stmt_or_event
()
{
if
(
triggers
&&
triggers
->
has_triggers
(
TRG_EVENT_UPDATE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER UPDATE triggers that might access to subject
table and therefore might need update to be done immediately.
So we turn-off the batching.
*/
(
void
)
file
->
extra
(
HA_EXTRA_UPDATE_CANNOT_BATCH
);
return
TRUE
;
}
return
FALSE
;
}
/*
@brief Reset const_table flag
...
...
sql/table.h
View file @
af3180ab
...
...
@@ -1234,6 +1234,10 @@ public:
bool
get_fields_in_item_tree
;
/* Signal to fix_field */
bool
m_needs_reopen
;
bool
created
;
/* For tmp tables. TRUE <=> tmp table was actually created.*/
#ifdef HAVE_REPLICATION
/* used in RBR Triggers */
bool
master_had_triggers
;
#endif
REGINFO
reginfo
;
/* field connections */
MEM_ROOT
mem_root
;
...
...
@@ -1362,6 +1366,10 @@ public:
ulong
actual_key_flags
(
KEY
*
keyinfo
);
int
update_default_fields
();
inline
ha_rows
stat_records
()
{
return
used_stat_records
;
}
void
prepare_triggers_for_insert_stmt_or_event
();
bool
prepare_triggers_for_delete_stmt_or_event
();
bool
prepare_triggers_for_update_stmt_or_event
();
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment