mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / suite / binlog / t / binlog_killed.test
blobe2db326129d1c6de2a508e96f816442e692cebdc
1 -- source include/have_innodb.inc
2 -- source include/have_binlog_format_statement.inc
4 # You cannot use `KILL' with the Embedded MySQL Server library,
5 # because the embedded server merely runs inside the threads of the host
6 # application. -- the docs
8 -- source include/not_embedded.inc
10 ###
11 ### bug#22725 : incorrect killed error in binlogged query
12 ###
14 connect (con1, localhost, root,,);
15 connect (con2, localhost, root,,);
17 create table t1 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
18 create table t2 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=MyISAM;
19 create table t3 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
22 # effective test for bug#22725
25 connection con1;
26 select get_lock("a", 20);
28 connection con2;
29 let $ID= `select connection_id()`;
32 # reset master does not reset binlogging on the embedded server.
33 # the test is not run on the embedded for reason of using KILL query.
34 # `reset master' problem is to be addressed by bug#15580 fixes.
36 reset master;
37 send insert into t2 values (null, null), (null, get_lock("a", 10));
40 connection con1;
42 disable_abort_on_error;
43 disable_query_log;
44 disable_result_log;
46 eval kill query $ID;
48 connection con2;
49 --error 0,ER_QUERY_INTERRUPTED
50 reap;
51 let $rows= `select count(*) from t2  /* must be 2 or 0 */`;
53 let $MYSQLD_DATADIR= `select @@datadir`;
54 --exec $MYSQL_BINLOG --force-if-open --start-position=134 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
55 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
56 eval select
57 (@a:=load_file("$MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
58 is not null;
59 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
60 let $error_code= `select @a like "%#%error_code=0%" /* must return 1 or 0*/`;
61 let $insert_binlogged= `select @a like "%insert into%" /* must return 1 or 0 */`;
62 eval set @result= $rows- $error_code - $insert_binlogged;
64 enable_abort_on_error;
65 enable_query_log;
66 enable_result_log;
68 select @result /* must be zero either way */;
71 --remove_file $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
72 connection con1;
73 select RELEASE_LOCK("a");
76 # bug#27571 asynchronous setting mysql_`query`::error and Query_log_e::error_code
79 # checking that killing inside of select loops is safe as before
80 # killing after the loop can be only simulated - another test
82 delete from t1;
83 delete from t2;
84 insert into t1 values (1,1),(2,2);
87 # simple update
89 connection con1;
90 begin; update t1 set b=11 where a=2;
92 connection con2;
93 let $ID= `select connection_id()`;
94 begin;
95 send update t1 set b=b+10;
97 connection con1;
98 --replace_result $ID ID
99 eval kill query $ID;
100 rollback;
102 # Bug #32148    killi query may be ineffective 
103 # forced to comment out the test's outcome 
104 # and mask out ineffective ER_QUERY_INTERRUPTED
105 # todo1: revert back upon fixing bug#32148
106 # todo2: the tests need refining in that
107 #        killing should wait till the victim requested
108 #        its lock (wait_condition available in 5.1 tests)
110 connection con2;
111 --error 0,ER_QUERY_INTERRUPTED
112 reap;
113 rollback;
114 select * from t1  order by a /* must be the same as before (1,1),(2,2) */;
117 # multi update
118 # commented out as Bug #31807 multi-update,delete killing does not report with ER_QUERY_INTERRUPTED
119 # in the way
121 # connection con1;
122 # begin; update t1 set b=b+10;
124 # connection con2;
125 # send update t1 as t_1,t1 as t_2 set t_1.b=11 where t_2.a=2;
127 # connection con1;
128 # --replace_result $ID ID
129 # eval kill query $ID;
130 # rollback;
132 # disable_abort_on_error;
134 # connection con2;
135 # --error HY000,ER_QUERY_INTERRUPTED
136 # reap;
137 # select * from t1 /* must be the same as before (1,1),(2,2) */;
139 # enable_abort_on_error;
141 # simple delete
143 connection con1;
144 begin; delete from t1 where a=2;
146 connection con2;
147 let $ID= `select connection_id()`;
148 begin;
149 send delete from t1 where a=2;
151 connection con1;
152 --replace_result $ID ID
153 eval kill query $ID;
154 rollback;
156 connection con2;
157 --error 0,ER_QUERY_INTERRUPTED
158 reap;
159 rollback;
160 # todo1,2 above
161 select * from t1 order by a /* must be the same as before (1,1),(2,2) */;
165 # multi delete
166 # the same as for multi-update
168 # connection con1;
169 # begin; delete from t1 where a=2;
171 # connection con2;
172 # send delete t1 from t1 where t1.a=2;
174 # connection con1;
175 # --replace_result $ID ID
176 # eval kill query $ID;
177 # rollback;
179 # connection con2;
180 # --error 0,ER_QUERY_INTERRUPTED
181 # reap;
182 # select * from t1 /* must be the same as before (1,1),(2,2) */;
184 # insert select
186 connection con1;
187 --disable_warnings
188 drop table if exists t4;
189 --enable_warnings
190 create table t4 (a int, b int) engine=innodb;
191 insert into t4 values (3, 3);
192 begin; insert into t1 values (3, 3);
194 connection con2;
195 let $ID= `select connection_id()`;
196 begin;
197 send insert into t1 select * from t4 for update;
199 connection con1;
200 --replace_result $ID ID
201 eval kill query $ID;
202 rollback;
204 connection con2;
205 --error 0,ER_QUERY_INTERRUPTED
206 reap;
207 # todo 1,2 above
208 rollback;
209 select * from t1 /* must be the same as before (1,1),(2,2) */;
211 drop table t4; # cleanup for the sub-case
214 ## non-ta table case: killing must be recorded in binlog
216 create table t4 (a int, b int) ENGINE=MyISAM /* for killing update and delete */;
218 delimiter |;
219 create function bug27563(n int) 
220 RETURNS int(11)
221 DETERMINISTIC
222 begin
223   if @b > 0 then
224      select get_lock("a", 20)  into @a;
225   else 
226      set @b= 1;
227   end if;
228   return n;
229 end|
230 delimiter ;|
233 # update
236 delete from t4;
237 insert into t4 values (1,1), (1,1);
238 reset master;
239 connection con1;
240 select get_lock("a", 20);
242 connection con2;
243 let $ID= `select connection_id()`;
244 set @b= 0;
245 send update t4 set b=b + bug27563(b);
247 connection con1;
248 let $wait_condition= select count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
249 source include/wait_condition.inc;
250 select count(*) FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
252 --replace_result $ID ID
253 eval kill query $ID;
255 connection con2;
256 --error ER_QUERY_INTERRUPTED
257 reap;
258 select * from t4 order by b /* must be (1,1), (1,2) */;
259 select @b  /* must be 1 at the end of a stmt calling bug27563() */;
260 --echo must have the update query event more to FD
261 source include/show_binlog_events.inc;
263 # a proof the query is binlogged with an error
265 --exec $MYSQL_BINLOG --force-if-open --start-position=106 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
266 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
267 eval select
268 (@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
269 is not null;
270 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
271 let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
272 eval select $error_code /* must return 0 to mean the killed query is in */;
274 # cleanup for the sub-case
275 connection con1;
276 select RELEASE_LOCK("a");
277 --remove_file $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
280 # delete
283 delete from t4;
284 insert into t4 values (1,1), (2,2);
285 reset master;
286 connection con1;
287 select get_lock("a", 20);
289 connection con2;
290 let $ID= `select connection_id()`;
291 set @b= 0;
292 send delete from t4 where b=bug27563(1) or b=bug27563(2);
294 connection con1;
295 let $wait_condition= select count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
296 source include/wait_condition.inc;
297 select count(*) FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
298 --replace_result $ID ID
299 eval kill query $ID;
301 connection con2;
302 --error ER_QUERY_INTERRUPTED
303 reap;
304 select count(*) from t4 /* must be 1 */;
305 select @b  /* must be 1 at the end of a stmt calling bug27563() */;
306 --echo must have the delete query event more to FD
307 source include/show_binlog_events.inc;
309 # a proof the query is binlogged with an error
311 --exec $MYSQL_BINLOG --force-if-open --start-position=106 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
312 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
313 eval select
314 (@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
315 is not null;
316 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
317 let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
318 eval select $error_code /* must return 0 to mean the killed query is in */;
320 # cleanup for the sub-case
321 connection con1;
322 select RELEASE_LOCK("a");
323 --remove_file $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
325 drop table t4;
328 # load data - see simulation tests
332 # bug#27571 cleanup
334 drop function bug27563;
338 # common cleanup 
341 drop table t1,t2,t3;
343 --echo end of the tests