~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
-- source include/have_innodb.inc
2
-- source include/have_binlog_format_mixed_or_statement.inc
3
-- source include/not_embedded.inc
4
5
###
6
### bug#22725 : incorrect killed error in binlogged query
7
###
8
9
connect (con1, localhost, root,,);
10
connect (con2, localhost, root,,);
11
12
create table t1 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
13
create table t2 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=MyISAM;
14
create table t3 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
15
16
#
17
# effective test for bug#22725
18
#
19
20
connection con1;
21
select get_lock("a", 20);
22
23
connection con2;
24
let $ID= `select connection_id()`;
25
reset master;
26
send insert into t2 values (null, null), (null, get_lock("a", 10));
27
28
29
connection con1;
30
31
disable_abort_on_error;
32
disable_query_log;
33
disable_result_log;
34
35
eval kill query $ID;
36
37
connection con2;
38
--error 0,ER_QUERY_INTERRUPTED
39
reap;
40
let $rows= `select count(*) from t2  /* must be 2 or 0 */`;
41
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
42
--exec $DRIZZLE_BINLOG --force-if-open --start-position=135 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
1 by brian
clean slate
43
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
44
eval select
45
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
46
is not null;
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
47
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
1 by brian
clean slate
48
let $error_code= `select @a like "%#%error_code=0%" /* must return 1 or 0*/`;
49
let $insert_binlogged= `select @a like "%insert into%" /* must return 1 or 0 */`;
50
eval set @result= $rows- $error_code - $insert_binlogged;
51
52
enable_abort_on_error;
53
enable_query_log;
54
enable_result_log;
55
56
select @result /* must be zero either way */;
57
58
59
--remove_file $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
60
connection con1;
61
select RELEASE_LOCK("a");
62
63
#
64
# bug#27571 asynchronous setting mysql_`query`::error and Query_log_e::error_code
65
#
66
67
# checking that killing inside of select loops is safe as before
68
# killing after the loop can be only simulated - another test
69
70
delete from t1;
71
delete from t2;
72
insert into t1 values (1,1),(2,2);
73
74
#
75
# simple update
76
#
77
connection con1;
78
begin; update t1 set b=11 where a=2;
79
80
connection con2;
81
let $ID= `select connection_id()`;
82
begin;
83
send update t1 set b=b+10;
84
85
connection con1;
86
--replace_result $ID ID
87
eval kill query $ID;
88
rollback;
89
90
# Bug #32148  	killi query may be ineffective 
91
# forced to comment out the test's outcome 
92
# and mask out ineffective ER_QUERY_INTERRUPTED
93
# todo1: revert back upon fixing bug#32148
94
# todo2: the tests need refining in that
95
#        killing should wait till the victim requested
96
#        its lock (wait_condition available in 5.1 tests)
97
98
connection con2;
99
--error 0,ER_QUERY_INTERRUPTED
100
reap;
101
rollback;
102
select * from t1  order by a /* must be the same as before (1,1),(2,2) */;
103
104
#
105
# multi update
106
# commented out as Bug #31807 multi-update,delete killing does not report with ER_QUERY_INTERRUPTED
107
# in the way
108
#
109
# connection con1;
110
# begin; update t1 set b=b+10;
111
112
# connection con2;
113
# send update t1 as t_1,t1 as t_2 set t_1.b=11 where t_2.a=2;
114
115
# connection con1;
116
# --replace_result $ID ID
117
# eval kill query $ID;
118
# rollback;
119
120
# disable_abort_on_error;
121
122
# connection con2;
123
# --error HY000,ER_QUERY_INTERRUPTED
124
# reap;
125
# select * from t1 /* must be the same as before (1,1),(2,2) */;
126
127
# enable_abort_on_error;
128
#
129
# simple delete
130
#
131
connection con1;
132
begin; delete from t1 where a=2;
133
134
connection con2;
135
let $ID= `select connection_id()`;
136
begin;
137
send delete from t1 where a=2;
138
139
connection con1;
140
--replace_result $ID ID
141
eval kill query $ID;
142
rollback;
143
144
connection con2;
145
--error 0,ER_QUERY_INTERRUPTED
146
reap;
147
rollback;
148
# todo1,2 above
149
select * from t1 order by a /* must be the same as before (1,1),(2,2) */;
150
151
152
#
153
# multi delete
154
# the same as for multi-update
155
#
156
# connection con1;
157
# begin; delete from t1 where a=2;
158
159
# connection con2;
160
# send delete t1 from t1 where t1.a=2;
161
162
# connection con1;
163
# --replace_result $ID ID
164
# eval kill query $ID;
165
# rollback;
166
167
# connection con2;
168
# --error 0,ER_QUERY_INTERRUPTED
169
# reap;
170
# select * from t1 /* must be the same as before (1,1),(2,2) */;
171
#
172
# insert select
173
#
174
connection con1;
175
--disable_warnings
176
drop table if exists t4;
177
--enable_warnings
178
create table t4 (a int, b int) engine=innodb;
179
insert into t4 values (3, 3);
180
begin; insert into t1 values (3, 3);
181
182
connection con2;
183
let $ID= `select connection_id()`;
184
begin;
185
send insert into t1 select * from t4 for update;
186
187
connection con1;
188
--replace_result $ID ID
189
eval kill query $ID;
190
rollback;
191
192
connection con2;
193
--error 0,ER_QUERY_INTERRUPTED
194
reap;
195
# todo 1,2 above
196
rollback;
197
select * from t1 /* must be the same as before (1,1),(2,2) */;
198
199
drop table t4; # cleanup for the sub-case
200
201
###
202
## non-ta table case: killing must be recorded in binlog
203
###
204
create table t4 (a int, b int) ENGINE=MyISAM /* for killing update and delete */;
205
206
delimiter |;
207
create function bug27563(n int) 
208
RETURNS int(11)
209
DETERMINISTIC
210
begin
211
  if @b > 0 then
212
     select get_lock("a", 20)  into @a;
213
  else 
214
     set @b= 1;
215
  end if;
216
  return n;
217
end|
218
delimiter ;|
219
220
#
221
# update
222
#
223
224
delete from t4;
225
insert into t4 values (1,1), (1,1);
226
reset master;
227
connection con1;
228
select get_lock("a", 20);
229
230
connection con2;
231
let $ID= `select connection_id()`;
232
set @b= 0;
233
send update t4 set b=b + bug27563(b);
234
235
connection con1;
236
let $wait_condition= select count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
237
source include/wait_condition.inc;
238
select count(*) FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
239
240
--replace_result $ID ID
241
eval kill query $ID;
242
243
connection con2;
244
--error ER_QUERY_INTERRUPTED
245
reap;
246
select * from t4 order by b /* must be (1,1), (1,2) */;
247
select @b  /* must be 1 at the end of a stmt calling bug27563() */;
248
--echo must have the update query event more to FD
249
source include/show_binlog_events.inc;
250
251
# a proof the query is binlogged with an error
252
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
253
--exec $DRIZZLE_BINLOG --force-if-open --start-position=106 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
1 by brian
clean slate
254
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
255
eval select
256
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
257
is not null;
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
258
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
1 by brian
clean slate
259
let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
260
eval select $error_code /* must return 0 to mean the killed query is in */;
261
262
# cleanup for the sub-case
263
connection con1;
264
select RELEASE_LOCK("a");
265
--remove_file $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
266
267
#
268
# delete
269
#
270
271
delete from t4;
272
insert into t4 values (1,1), (2,2);
273
reset master;
274
connection con1;
275
select get_lock("a", 20);
276
277
connection con2;
278
let $ID= `select connection_id()`;
279
set @b= 0;
280
send delete from t4 where b=bug27563(1) or b=bug27563(2);
281
282
connection con1;
283
let $wait_condition= select count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
284
source include/wait_condition.inc;
285
select count(*) FROM INFORMATION_SCHEMA.PROCESSLIST where state='User lock';
286
--replace_result $ID ID
287
eval kill query $ID;
288
289
connection con2;
290
--error ER_QUERY_INTERRUPTED
291
reap;
292
select count(*) from t4 /* must be 1 */;
293
select @b  /* must be 1 at the end of a stmt calling bug27563() */;
294
--echo must have the delete query event more to FD
295
source include/show_binlog_events.inc;
296
297
# a proof the query is binlogged with an error
298
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
299
--exec $DRIZZLE_BINLOG --force-if-open --start-position=106 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
1 by brian
clean slate
300
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
301
eval select
302
(@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
303
is not null;
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
304
--replace_result $DRIZZLE_TEST_DIR DRIZZLE_TEST_DIR
1 by brian
clean slate
305
let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
306
eval select $error_code /* must return 0 to mean the killed query is in */;
307
308
# cleanup for the sub-case
309
connection con1;
310
select RELEASE_LOCK("a");
311
--remove_file $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
312
313
drop table t4;
314
315
#
316
# load data - see simulation tests
317
#
318
319
320
# bug#27571 cleanup
321
322
drop function bug27563;
323
324
325
#
326
# common cleanup 
327
#
328
329
drop table t1,t2,t3;
330
331
--echo end of the tests