mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / kill.test
blob02b033df2e5c90dc3f124b69a23bcb3110642c1c
1 # This test doesn't work with the embedded version as this code
2 # assumes that one query is running while we are doing queries on
3 # a second connection.
4 # This would work if mysqltest run would be threaded and handle each
5 # connection in a separate thread.
7 -- source include/not_embedded.inc
9 # Disable concurrent inserts to avoid test failures when reading the
10 # connection id which was inserted into a table by another thread.
11 set @old_concurrent_insert= @@global.concurrent_insert;
12 set @@global.concurrent_insert= 0;
14 connect (con1, localhost, root,,);
15 connect (con2, localhost, root,,);
17 #remember id of con1
18 connection con1;
19 --disable_warnings
20 drop table if exists t1, t2, t3;
21 --enable_warnings
23 --disable_reconnect
24 create table t1 (kill_id int);
25 insert into t1 values(connection_id());
27 #kill con1
28 connection con2;
29 select ((@id := kill_id) - kill_id) from t1; 
30 kill @id;
32 connection con1;
33 --sleep 2
35 --disable_query_log
36 --disable_result_log
37 # One of the following statements should fail
38 --error 0,2006,2013
39 select 1;
40 --error 0,2006,2013
41 select 1;
42 --enable_query_log
43 --enable_result_log
45 --enable_reconnect
46 # this should work, and we should have a new connection_id()
47 select ((@id := kill_id) - kill_id) from t1;
48 select @id != connection_id();
50 #make sure the server is still alive
51 connection con2;
52 select 4;
53 drop table t1;
54 connection default;
56 --error ER_NOT_SUPPORTED_YET
57 kill (select count(*) from mysql.user);
60 # BUG#14851: killing long running subquery processed via a temporary table.
62 create table t1 (id int primary key);
63 create table t2 (id int unsigned not null);
65 connect (conn1, localhost, root,,);
66 connection conn1;
68 -- disable_result_log
69 -- disable_query_log
70 let $1 = 4096;
71 while ($1)
73   eval insert into t1 values ($1);
74   dec $1;
76 -- enable_query_log
77 -- enable_result_log
79 insert into t2 select id from t1;
81 create table t3 (kill_id int);
82 insert into t3 values(connection_id());
84 connect (conn2, localhost, root,,);
85 connection conn2;
87 connection conn1;
88 -- disable_result_log
89 # This is a very long running query. If this test start failing, it may
90 # be necessary to change to an even longer query.
91 send select id from t1 where id in (select distinct a.id from t2 a, t2 b, t2 c, t2 d group by a.id, b.id, c.id, d.id having a.id between 10 and 20);
92 -- enable_result_log
94 connection conn2;
95 select ((@id := kill_id) - kill_id) from t3;
96 -- sleep 1
97 kill @id;
99 connection conn1;
100 -- error 1317,2013
101 reap;
103 connection default;
105 drop table t1, t2, t3;
107 # End of 4.1 tests
110 # test of blocking of sending ERROR after OK or EOF
112 connection con1;
113 select get_lock("a", 10);
114 connection con2;
115 let $ID= `select connection_id()`;
116 send select get_lock("a", 10);
117 real_sleep 2;
118 connection con1;
119 disable_query_log;
120 eval kill query $ID;
121 enable_query_log;
122 connection con2;
123 reap;
124 select 1;
125 connection con1;
126 select RELEASE_LOCK("a");
129 # Bug#27563: Stored functions and triggers wasn't throwing an error when killed.
131 create table t1(f1 int);
132 delimiter |;
133 create function bug27563() returns int(11)
134 deterministic
135 begin
136   declare continue handler for sqlstate '70100' set @a:= 'killed';
137   declare continue handler for sqlexception set @a:= 'exception';
138   set @a= get_lock("lock27563", 10);
139   return 1;
140 end|
141 delimiter ;|
142 # Test stored functions
143 # Test INSERT
144 connection con1;
145 select get_lock("lock27563",10);
146 connection con2;
147 let $ID= `select connection_id()`;
148 send insert into t1 values (bug27563());
149 real_sleep 2;
150 connection con1;
151 disable_query_log;
152 eval kill query $ID;
153 enable_query_log;
154 connection con2;
155 --error 1317
156 reap;
157 select @a;
158 connection con1;
159 select * from t1;
161 # Test UPDATE
162 insert into t1 values(0);
163 connection con2;
164 send update t1 set f1= bug27563();
165 real_sleep 2;
166 connection con1;
167 disable_query_log;
168 eval kill query $ID;
169 enable_query_log;
170 connection con2;
171 --error 1317
172 reap;
173 select @a;
174 connection con1;
175 select * from t1;
177 # Test DELETE
178 insert into t1 values(1);
179 connection con2;
180 send delete from t1 where bug27563() is null;
181 real_sleep 2;
182 connection con1;
183 disable_query_log;
184 eval kill query $ID;
185 enable_query_log;
186 connection con2;
187 --error 1317
188 reap;
189 select @a;
190 connection con1;
191 select * from t1;
193 # Test SELECT
194 connection con2;
195 send select * from t1 where f1= bug27563();
196 real_sleep 2;
197 connection con1;
198 disable_query_log;
199 eval kill query $ID;
200 enable_query_log;
201 connection con2;
202 --error 1317
203 reap;
204 select @a;
206 # Test PROCEDURE
207 connection con2;
208 delimiter |;
209 create procedure proc27563()
210 begin
211   declare continue handler for sqlstate '70100' set @a:= 'killed';
212   declare continue handler for sqlexception set @a:= 'exception';
213   select get_lock("lock27563",10);
214   select "shouldn't be selected";
215 end|
216 delimiter ;|
217 send call proc27563();
218 real_sleep 2;
219 connection con1;
220 disable_query_log;
221 eval kill query $ID;
222 enable_query_log;
223 connection con2;
224 --error 1317
225 reap;
226 select @a;
228 # Test TRIGGERS
229 connection con2;
230 create table t2 (f2 int);
231 delimiter |;
232 create trigger trg27563 before insert on t1 for each row 
233 begin 
234   declare continue handler for sqlstate '70100' set @a:= 'killed';
235   declare continue handler for sqlexception set @a:= 'exception';
236   set @a:= get_lock("lock27563",10);
237   insert into t2 values(1);
238 end|
239 delimiter ;|
240 send insert into t1 values(2),(3);
241 real_sleep 2;
242 connection con1;
243 disable_query_log;
244 eval kill query $ID;
245 enable_query_log;
246 connection con2;
247 --error 1317
248 reap;
249 select @a;
250 connection con1;
251 select * from t1;
252 select * from t2;
254 # Cleanup
255 select release_lock("lock27563");
256 drop table t1, t2;
257 drop function bug27563;
258 drop procedure proc27563;
261 # Bug#28598: mysqld crash when killing a long-running explain query.
263 --disable_query_log
264 connection con1;
265 let $ID= `select connection_id()`;
266 let $tab_count= 40;
268 let $i= $tab_count;
269 while ($i)
271   eval CREATE TABLE t$i (a$i int, KEY(a$i));
272   eval INSERT INTO t$i VALUES (1),(2),(3),(4),(5),(6),(7);
273   dec $i ;
275 set session optimizer_search_depth=0;
277 let $i=$tab_count;
278 while ($i)
280  let $a= a$i;
281  let $t= t$i;
282  dec $i;
283  if ($i)
285    let $comma=,;
286    let $from=$comma$t$from;
287    let $where=a$i=$a $and $where;
289  if (!$i) 
291    let $from=FROM $t$from;
292    let $where=WHERE $where;
294  let $and=AND;
297 --enable_query_log
298 eval PREPARE stmt FROM 'EXPLAIN SELECT * $from $where';
299 send EXECUTE stmt;
300 --disable_query_log
302 connection con2;
303 real_sleep 2;
304 eval kill query $ID;
305 let $i= $tab_count;
306 while ($i)
308   eval DROP TABLE t$i;
309   dec $i ;
311 --enable_query_log
313 ###########################################################################
315 --echo #
316 --echo # Bug#19723: kill of active connection yields different error code
317 --echo # depending on platform.
318 --echo #
320 --echo
321 --echo # Connection: con2.
322 --connection con2
324 KILL CONNECTION_ID();
326 --echo # CR_SERVER_LOST, CR_SERVER_GONE_ERROR, depending on the timing 
327 --echo # of close of the connection socket
328 --error 2013, 2006 
329 SELECT 1;
330 --connection default
332 ###########################################################################
334 # Restore global concurrent_insert value. Keep in the end of the test file.
335 set @@global.concurrent_insert= @old_concurrent_insert;