1
-- source include/have_innodb.inc
2
-- source include/have_binlog_format_statement.inc
3
-- source include/binlog_start_pos.inc
5
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
7
# You cannot use `KILL' with the Embedded MySQL Server library,
8
# because the embedded server merely runs inside the threads of the host
9
# application. -- the docs
11
-- source include/not_embedded.inc
14
### bug#22725 : incorrect killed error in binlogged query
17
connect (con1, localhost, root,,);
18
connect (con2, localhost, root,,);
20
create table t1 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
21
create table t2 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=MyISAM;
22
create table t3 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
25
# effective test for bug#22725
29
select get_lock("a", 20);
32
let $ID= `select connection_id()`;
35
# reset master does not reset binlogging on the embedded server.
36
# the test is not run on the embedded for reason of using KILL query.
37
# `reset master' problem is to be addressed by bug#15580 fixes.
40
send insert into t2 values (null, null), (null, get_lock("a", 10));
45
--disable_abort_on_error
49
select count(*) = 1 from information_schema.processlist
50
where info like "%insert into t2 values%" and state like 'User lock';
51
--source include/wait_condition.inc
53
--replace_regex /[0-9]+/ID/
57
--error 0,ER_QUERY_INTERRUPTED
59
let $rows= `select count(*) from t2 /* must be 2 or 0 */`;
61
let $MYSQLD_DATADIR= `select @@datadir`;
62
--let $binlog_killed_pos=query_get_value(SHOW BINLOG EVENTS, Pos, 4)
63
--let $binlog_killed_end_log_pos=query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
64
--exec $MYSQL_BINLOG --force-if-open --start-position=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
65
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
68
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
71
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
72
let $error_code= `select @a like "%#%error_code=0%" /* must return 1 or 0*/`;
73
let $insert_binlogged= `select @a like "%insert into%" /* must return 1 or 0 */`;
74
eval set @result= $rows - $error_code - $insert_binlogged;
77
--enable_abort_on_error
79
select @result /* must be zero either way */;
82
--remove_file $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
84
select RELEASE_LOCK("a");
87
# bug#27571 asynchronous setting mysql_`query`::error and Query_log_e::error_code
90
# checking that killing inside of select loops is safe as before
91
# killing after the loop can be only simulated - another test
95
insert into t1 values (1,1),(2,2);
101
begin; update t1 set b=11 where a=2;
104
let $ID= `select connection_id()`;
106
send update t1 set b=b+10;
109
--replace_result $ID ID
113
# Bug #32148 killi query may be ineffective
114
# forced to comment out the test's outcome
115
# and mask out ineffective ER_QUERY_INTERRUPTED
116
# todo1: revert back upon fixing bug#32148
117
# todo2: the tests need refining in that
118
# killing should wait till the victim requested
119
# its lock (wait_condition available in 5.1 tests)
122
--error 0,ER_QUERY_INTERRUPTED
125
select * from t1 order by a /* must be the same as before (1,1),(2,2) */;
129
# commented out as Bug #31807 multi-update,delete killing does not report with ER_QUERY_INTERRUPTED
133
# begin; update t1 set b=b+10;
136
# send update t1 as t_1,t1 as t_2 set t_1.b=11 where t_2.a=2;
139
# --replace_result $ID ID
140
# eval kill query $ID;
143
# disable_abort_on_error;
146
# --error HY000,ER_QUERY_INTERRUPTED
148
# select * from t1 /* must be the same as before (1,1),(2,2) */;
150
# enable_abort_on_error;
155
begin; delete from t1 where a=2;
158
let $ID= `select connection_id()`;
160
send delete from t1 where a=2;
163
--replace_result $ID ID
168
--error 0,ER_QUERY_INTERRUPTED
172
select * from t1 order by a /* must be the same as before (1,1),(2,2) */;
177
# the same as for multi-update
180
# begin; delete from t1 where a=2;
183
# send delete t1 from t1 where t1.a=2;
186
# --replace_result $ID ID
187
# eval kill query $ID;
191
# --error 0,ER_QUERY_INTERRUPTED
193
# select * from t1 /* must be the same as before (1,1),(2,2) */;
199
drop table if exists t4;
201
create table t4 (a int, b int) engine=innodb;
202
insert into t4 values (3, 3);
203
begin; insert into t1 values (3, 3);
206
let $ID= `select connection_id()`;
208
send insert into t1 select * from t4 for update;
211
--replace_result $ID ID
216
--error 0,ER_QUERY_INTERRUPTED,ER_LOCK_WAIT_TIMEOUT
220
select * from t1 /* must be the same as before (1,1),(2,2) */;
222
drop table t4; # cleanup for the sub-case
225
## non-ta table case: killing must be recorded in binlog
227
create table t4 (a int, b int) ENGINE=MyISAM /* for killing update and delete */;
230
create function bug27563(n int)
235
select get_lock("a", 20) into @a;
248
insert into t4 values (1,1), (1,1);
251
select get_lock("a", 20);
254
let $ID= `select connection_id()`;
256
send update t4 set b=b + bug27563(b);
259
let $wait_condition= select count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
260
source include/wait_condition.inc;
261
select count(*) FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
263
--replace_result $ID ID
267
--error ER_QUERY_INTERRUPTED
269
select * from t4 order by b /* must be (1,1), (1,2) */;
270
select @b /* must be 1 at the end of a stmt calling bug27563() */;
271
--echo must have the update query event on the 4th line
272
source include/show_binlog_events.inc;
273
--let $binlog_killed_pos= query_get_value(SHOW BINLOG EVENTS, Pos, 4)
274
--let $binlog_killed_end_log_pos= query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
276
--echo *** a proof the query is binlogged with an error ***
278
--exec $MYSQL_BINLOG --force-if-open --start-position=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
279
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
281
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
283
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
284
let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
285
eval select $error_code /* must return 0 to mean the killed update is in */;
287
# cleanup for the sub-case
289
select RELEASE_LOCK("a");
290
--remove_file $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
297
insert into t4 values (1,1), (2,2);
300
select get_lock("a", 20);
303
let $ID= `select connection_id()`;
305
send delete from t4 where b=bug27563(1) or b=bug27563(2);
308
let $wait_condition= select count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
309
source include/wait_condition.inc;
310
select count(*) FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
311
--replace_result $ID ID
315
--error ER_QUERY_INTERRUPTED
317
select count(*) from t4 /* must be 1 */;
318
select @b /* must be 1 at the end of a stmt calling bug27563() */;
319
--echo must have the delete query event on the 4th line
320
source include/show_binlog_events.inc;
321
--let $binlog_killed_pos= query_get_value(SHOW BINLOG EVENTS, Pos, 4)
322
--let $binlog_killed_end_log_pos= query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
324
# a proof the query is binlogged with an error
326
--exec $MYSQL_BINLOG --force-if-open --start-position=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
327
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
329
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
331
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
332
let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
333
eval select $error_code /* must return 0 to mean the killed delete is in */;
335
# cleanup for the sub-case
337
select RELEASE_LOCK("a");
338
--remove_file $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
343
# load data - see simulation tests
349
drop function bug27563;
358
--echo end of the tests