mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / suite / rpl / t / rpl_filter_tables_not_exist.test
blob3572dd53ea7ac9aedc145545a2450b1e05c4fb7b
1 # Test evaluation of replication table filter rules
3 # ==== Purpose ====
5 # Test if replication table filter rules are properly evaluated when
6 # some of the tables referenced by the multiple-table update do not
7 # exist on slave.
9 # ==== Method ====
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
18 # and
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;
83 echo [on slave];
84 SHOW TABLES LIKE 't%';
86 connection master;
87 echo [on master];
90 # Do tables are not referenced, these statements should be ignored by
91 # slave.
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
100 # ignored by slave.
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;
125 connection slave;
126 call mtr.add_suppression("Slave SQL.*Error .Table .test.t[47]. doesn.t exist. on query.* Error_code: 1146");
127 connection master;
129 # Parameters for include/wait_for_slave_sql_error_and_skip.inc:
130 # Ask it to show SQL error message.
131 let $show_slave_sql_error= 1;
132 # The expected error will always be 1146 (ER_NO_SUCH_TABLE).
133 let $slave_sql_errno= 1146;
136 # Only do tables are referenced for update, these statements should
137 # cause error on slave
139 UPDATE t1 LEFT JOIN t4 ON (t1.id=t4.id) SET a=0 where t1.id=1;
140 source include/wait_for_slave_sql_error_and_skip.inc;
142 UPDATE t1 LEFT JOIN (t4, t7) ON (t1.id=t4.id and t1.id=t7.id) SET a=0 where t1.id=1;
143 source include/wait_for_slave_sql_error_and_skip.inc;
145 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;
146 source include/wait_for_slave_sql_error_and_skip.inc;
148 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;
149 source include/wait_for_slave_sql_error_and_skip.inc;
152 # Do tables and other tables are referenced for update, these
153 # statements should cause error on slave
155 UPDATE t1 LEFT JOIN t7 ON (t1.id=t7.id) SET a=0, g=0 where t1.id=1;
156 source include/wait_for_slave_sql_error_and_skip.inc;
158 UPDATE t7 LEFT JOIN t1 ON (t1.id=t7.id) SET a=0, g=0 where t7.id=1;
159 source include/wait_for_slave_sql_error_and_skip.inc;
161 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;
162 source include/wait_for_slave_sql_error_and_skip.inc;
164 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;
165 source include/wait_for_slave_sql_error_and_skip.inc;
167 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;
168 source include/wait_for_slave_sql_error_and_skip.inc;
170 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;
171 source include/wait_for_slave_sql_error_and_skip.inc;
173 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;
174 source include/wait_for_slave_sql_error_and_skip.inc;
176 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;
177 source include/wait_for_slave_sql_error_and_skip.inc;
180 # Do tables are referenced for update before ignore tables
182 UPDATE t1 LEFT JOIN t4 ON (t1.id=t4.id) SET a=0, d=0 where t1.id=1;
183 source include/wait_for_slave_sql_error_and_skip.inc;
185 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;
186 source include/wait_for_slave_sql_error_and_skip.inc;
188 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;
189 source include/wait_for_slave_sql_error_and_skip.inc;
191 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;
192 source include/wait_for_slave_sql_error_and_skip.inc;
194 sync_slave_with_master;
195 echo [on slave];
197 # We should only have tables t1, t2, t3 on slave
198 show tables like 't%';
200 # The rows in these tables should remain untouched
201 SELECT * FROM t1;
202 SELECT * FROM t2;
203 SELECT * FROM t3;
205 # Clean up
206 connection master;
207 echo [on master];
208 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
210 --sync_slave_with_master
213 # BUG#11754117 - 45670: INTVAR_EVENTS FOR FILTERED-OUT QUERY_LOG_EVENTS ARE EXECUTED
214 # Int-, Rand- and User- var events accompaning a filtered out Query-log-event should
215 # be filtered as well.
217 connection master;
218 # Although RAND() is from 0 to 1.0, DECIMAL(M,D), requires that M must be >= D.
219 CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b DECIMAL(20,20), c INT); # ignored on slave
220 CREATE TABLE test.t1 (a INT); # accepted on slave
221 INSERT INTO test.t1 VALUES(1);
223 --sync_slave_with_master
224 call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
225 # Although RAND() is from 0 to 1.0, DECIMAL(M,D), requires that M must be >= D.
226 CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b DECIMAL(20,20), c INT);
227 CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW
228                                INSERT INTO test.t_slave VALUES(NULL, RAND(), @c);
230 connection master;
231 SET INSERT_ID=2;
232 SET @c=2;
233 SET @@rand_seed1=10000000, @@rand_seed2=1000000;
234 INSERT INTO t5 VALUES (NULL, RAND(), @c); # to be ignored
235 SELECT b into @b FROM test.t5;
236 --let $b_master=`select @b`
237 UPDATE test.t1 SET a=2; # to run trigger on slave
239 --sync_slave_with_master
241 # The proof:
242 SELECT a AS 'ONE' into @a FROM test.t_slave;
243 SELECT c AS 'NULL' into @c FROM test.t_slave;
245 let $count= 1;
246 let $table= test.t_slave;
247 source include/wait_until_rows_count.inc;
249 if (`SELECT @a != 2 and @c != NULL`)
251     SELECT * FROM test.t_slave;
252     --die Intvar or user var from replication events unexpetedly escaped out to screw a following query applying context.
255 SELECT b into @b FROM test.t_slave;
256 --let $b_slave=`select @b`
258 --let $assert_text= Random values from master and slave must be different
259 --let $assert_cond= $b_master != $b_slave
260 --source include/assert.inc
262 # cleanup BUG#11754117
263 connection master;
264 drop table test.t5;
265 drop table test.t1;
267 --sync_slave_with_master
268 drop table test.t_slave;
270 --source include/rpl_end.inc