1
# Test evaluation of replication table filter rules
5
# Test if replication table filter rules are properly evaluated when
6
# some of the tables referenced by the multiple-table update do not
11
# Master creates tables t1, t2, t3, t4, t5, t6, t7, t8, t9 and the
12
# slave is started with the following replication table filter rules:
14
# --replicate-do-table=t1
15
# --replicate-do-table=t2
16
# --replicate-do-table=t3
20
# --replicate-ignore-table=t4
21
# --replicate-ignore-table=t5
22
# --replicate-ignore-table=t6
24
# So the slave only replicate changes to tables t1, t2 and t3 and only
25
# these tables exist on slave.
27
# From now on, tables t1, t2, and t3 are referenced as do tables,
28
# tables t4, t5, t6 are referenced as ignore tables, and tables t7,
29
# t8, t9 are referenced as other tables.
31
# All multi-table update tests reference tables that are not do
32
# tables, which do not exist on slave. And the following situations
33
# of multi-table update will be tested:
35
# 1. Do tables are not referenced at all
36
# 2. Do tables are not referenced for update
37
# 3. Ignore tables are referenced for update before do tables
38
# 4. Only do tables are referenced for update
39
# 5. Do tables and other tables are referenced for update
40
# 6. Do tables are referenced for update before ignore tables
42
# For 1, 2 and 3, the statement should be ignored by slave, for 4, 5
43
# and 6 the statement should be accepted by slave and cause an error
44
# because of non-exist tables.
46
# ==== Related bugs ====
48
# BUG#37051 Replication rules not evaluated correctly
51
source include/have_binlog_format_statement.inc;
52
source include/master-slave.inc;
54
# These tables are mentioned in do-table rules
55
CREATE TABLE t1 (id int, a int);
56
CREATE TABLE t2 (id int, b int);
57
CREATE TABLE t3 (id int, c int);
59
# These tables are mentioned in ignore-table rules
60
CREATE TABLE t4 (id int, d int);
61
CREATE TABLE t5 (id int, e int);
62
CREATE TABLE t6 (id int, f int);
64
# These tables are not mentioned in do-table or ignore-table rules
65
CREATE TABLE t7 (id int, g int);
66
CREATE TABLE t8 (id int, h int);
67
CREATE TABLE t9 (id int, i int);
69
INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3);
70
INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3);
71
INSERT INTO t3 VALUES (1, 1), (2, 2), (3, 3);
73
INSERT INTO t4 VALUES (1, 1), (2, 2), (3, 3);
74
INSERT INTO t5 VALUES (1, 1), (2, 2), (3, 3);
75
INSERT INTO t6 VALUES (1, 1), (2, 2), (3, 3);
77
INSERT INTO t7 VALUES (1, 1), (2, 2), (3, 3);
78
INSERT INTO t8 VALUES (1, 1), (2, 2), (3, 3);
79
INSERT INTO t9 VALUES (1, 1), (2, 2), (3, 3);
81
# Only t1, t2, t3 should be replicated to slave
82
sync_slave_with_master;
84
SHOW TABLES LIKE 't%';
90
# Do tables are not referenced, these statements should be ignored by
93
UPDATE t7 LEFT JOIN t4 ON (t4.id=t7.id) SET d=0, g=0 where t7.id=1;
94
UPDATE t7 LEFT JOIN (t4, t5, t6) ON (t7.id=t4.id and t7.id=t5.id and t7.id=t6.id) SET d=0, e=0, f=0, g=0 where t7.id=1;
95
UPDATE t4 LEFT JOIN (t7, t8, t9) ON (t4.id=t7.id and t4.id=t8.id and t4.id=t9.id) SET d=0, g=0, h=0, i=0 where t4.id=1;
96
UPDATE t7 LEFT JOIN (t8, t9) ON (t7.id=t8.id and t7.id=t9.id) SET g=0, h=0, i=0 where t7.id=1;
99
# Do tables are not referenced for update, these statements should be
102
UPDATE t1 LEFT JOIN t4 ON (t1.id=t4.id) SET d=0 where t1.id=1;
103
UPDATE t1 LEFT JOIN t7 ON (t1.id=t7.id) SET g=0 where t1.id=1;
104
UPDATE t1 LEFT JOIN (t4, t5, t6) ON (t1.id=t4.id and t1.id=t5.id and t1.id=t6.id) SET d=0, e=0, f=0 where t1.id=1;
105
UPDATE t1 LEFT JOIN (t4, t5, t8) ON (t1.id=t4.id and t1.id=t5.id and t1.id=t8.id) SET d=0, e=0, h=0 where t1.id=1;
106
UPDATE t1 LEFT JOIN (t7, t8, t5) ON (t1.id=t7.id and t1.id=t8.id and t1.id=t5.id) SET g=0, h=0, e=0 where t1.id=1;
107
UPDATE t1 LEFT JOIN (t2, t3, t5) ON (t1.id=t2.id and t1.id=t3.id and t1.id=t5.id) SET e=0 where t1.id=1;
110
# Ignore tables are referenced for update before do tables, these
111
# statements should be ignore by slave.
113
UPDATE t4 LEFT JOIN t1 ON (t1.id=t4.id) SET a=0, d=0 where t4.id=1;
114
UPDATE t4 LEFT JOIN (t1, t7) ON (t4.id=t1.id and t7.id=t4.id) SET a = 0, d=0, g=0 where t4.id=1;
115
UPDATE t4 LEFT JOIN (t1, t2, t3) ON (t1.id=t4.id and t2.id=t4.id and t3.id=t4.id) SET a=0, b=0, c=0, d=0 where t4.id=1;
116
UPDATE t4 LEFT JOIN (t1, t2, t5) ON (t1.id=t4.id and t2.id=t4.id and t5.id=t4.id) SET a=0, b=0, e=0, d=0 where t4.id=1;
117
UPDATE t4 LEFT JOIN (t1, t6, t7) ON (t4.id=t1.id and t4.id=t6.id and t4.id=t7.id) SET a=0, d=0, f=0, g=0 where t4.id=1;
118
UPDATE t7 LEFT JOIN (t4, t1, t2) ON (t7.id=t4.id and t7.id=t1.id and t7.id=t2.id) SET a=0, b=0, d=0, g=0 where t7.id=1;
119
UPDATE t7 LEFT JOIN (t8, t4, t1) ON (t7.id=t8.id and t7.id=t4.id and t7.id=t1.id) SET a=0, d=0, g=0, h=0 where t7.id=1;
121
# Sync slave to make sure all above statements are correctly ignored,
122
# if any of the above statement are not ignored, it would cause error
123
# and stop slave sql thread.
124
sync_slave_with_master;
127
# Parameters for include/wait_for_slave_sql_error_and_skip.inc:
128
# Ask it to show SQL error message.
129
let $show_sql_error= 1;
130
# The expected error will always be 1146 (ER_NO_SUCH_TABLE).
131
let $slave_sql_errno= 1146;
134
# Only do tables are referenced for update, these statements should
135
# cause error on slave
137
UPDATE t1 LEFT JOIN t4 ON (t1.id=t4.id) SET a=0 where t1.id=1;
138
source include/wait_for_slave_sql_error_and_skip.inc;
140
UPDATE t1 LEFT JOIN (t4, t7) ON (t1.id=t4.id and t1.id=t7.id) SET a=0 where t1.id=1;
141
source include/wait_for_slave_sql_error_and_skip.inc;
143
UPDATE t1 LEFT JOIN (t2, t4, t7) ON (t1.id=t2.id and t1.id=t4.id and t1.id=t7.id) SET a=0, b=0 where t1.id=1;
144
source include/wait_for_slave_sql_error_and_skip.inc;
146
UPDATE t1 LEFT JOIN (t2, t3, t7) ON (t1.id=t2.id and t1.id=t3.id and t1.id=t7.id) SET a=0, b=0, c=0 where t1.id=1;
147
source include/wait_for_slave_sql_error_and_skip.inc;
150
# Do tables and other tables are referenced for update, these
151
# statements should cause error on slave
153
UPDATE t1 LEFT JOIN t7 ON (t1.id=t7.id) SET a=0, g=0 where t1.id=1;
154
source include/wait_for_slave_sql_error_and_skip.inc;
156
UPDATE t7 LEFT JOIN t1 ON (t1.id=t7.id) SET a=0, g=0 where t7.id=1;
157
source include/wait_for_slave_sql_error_and_skip.inc;
159
UPDATE t1 LEFT JOIN (t4, t5, t7) ON (t1.id=t4.id and t1.id=t5.id and t1.id=t7.id) SET a=0, g=0 where t1.id=1;
160
source include/wait_for_slave_sql_error_and_skip.inc;
162
UPDATE t1 LEFT JOIN (t4, t7, t8) ON (t1.id=t4.id and t1.id=t7.id and t1.id=t8.id) SET a=0, g=0 where t1.id=1;
163
source include/wait_for_slave_sql_error_and_skip.inc;
165
UPDATE t1 LEFT JOIN (t7, t8, t9) ON (t1.id=t7.id and t1.id=t8.id and t1.id=t9.id) SET a=0, g=0, h=0, i=0 where t1.id=1;
166
source include/wait_for_slave_sql_error_and_skip.inc;
168
UPDATE t7 LEFT JOIN (t1, t2, t3) ON (t7.id=t1.id and t7.id=t2.id and t7.id=t3.id) SET g=0, a=0, b=0, c=0 where t7.id=1;
169
source include/wait_for_slave_sql_error_and_skip.inc;
171
UPDATE t7 LEFT JOIN (t4, t5, t3) ON (t7.id=t4.id and t7.id=t5.id and t7.id=t3.id) SET g=0, c=0 where t7.id=1;
172
source include/wait_for_slave_sql_error_and_skip.inc;
174
UPDATE t7 LEFT JOIN (t8, t9, t3) ON (t7.id=t8.id and t7.id=t9.id and t7.id=t3.id) SET g=0, h=0, i=0, c=0 where t7.id=1;
175
source include/wait_for_slave_sql_error_and_skip.inc;
178
# Do tables are referenced for update before ignore tables
180
UPDATE t1 LEFT JOIN t4 ON (t1.id=t4.id) SET a=0, d=0 where t1.id=1;
181
source include/wait_for_slave_sql_error_and_skip.inc;
183
UPDATE t1 LEFT JOIN (t4, t5, t6) ON (t1.id=t4.id and t1.id=t5.id and t1.id=t6.id) SET a=0, d=0, e=0, f=0 where t1.id=1;
184
source include/wait_for_slave_sql_error_and_skip.inc;
186
UPDATE t4 LEFT JOIN (t1, t5, t6) ON (t4.id=t1.id and t4.id=t5.id and t4.id=t6.id) SET a=0, e=0, f=0 where t4.id=1;
187
source include/wait_for_slave_sql_error_and_skip.inc;
189
UPDATE t7 LEFT JOIN (t1, t4, t2) ON (t7.id=t1.id and t7.id=t4.id and t7.id=t2.id) SET a=0, b=0, d=0, g=0 where t7.id=1;
190
source include/wait_for_slave_sql_error_and_skip.inc;
192
sync_slave_with_master;
195
# We should only have tables t1, t2, t3 on slave
196
show tables like 't%';
198
# The rows in these tables should remain untouched
206
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
207
source include/master-slave-end.inc;