mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / lock_multi.test
blob4df1a0f3478117fc1733658ce1e86c433eb021de
1 -- source include/not_embedded.inc
3 # Save the initial number of concurrent sessions
4 --source include/count_sessions.inc
6 --disable_warnings
7 drop table if exists t1,t2;
8 --enable_warnings
10 # Test to see if select will get the lock ahead of low priority update
12 connect (locker,localhost,root,,);
13 connect (reader,localhost,root,,);
14 connect (writer,localhost,root,,);
16 connection locker;
17 create table t1(n int);
18 insert into t1 values (1);
19 lock tables t1 write;
20 connection writer;
21 send
22 update low_priority t1 set n = 4;
23 connection reader;
24 # Sleep a bit till the update of connection writer is in work and hangs
25 let $wait_condition=
26   select count(*) = 1 from information_schema.processlist
27   where state = "Locked" and info = "update low_priority t1 set n = 4";
28 --source include/wait_condition.inc
29 send
30 select n from t1;
31 connection locker;
32 # Sleep a bit till the select of connection reader is in work and hangs
33 let $wait_condition=
34   select count(*) = 1 from information_schema.processlist
35   where state = "Locked" and info = "select n from t1";
36 --source include/wait_condition.inc
37 unlock tables;
38 connection writer;
39 reap;
40 connection reader;
41 reap;
42 drop table t1;
44 connection locker;
45 create table t1(n int);
46 insert into t1 values (1);
47 lock tables t1 read;
48 connection writer;
49 send
50 update low_priority t1 set n = 4;
51 connection reader;
52 # Sleep a bit till the update of connection writer is in work and hangs
53 let $wait_condition=
54   select count(*) = 1 from information_schema.processlist
55   where state = "Locked" and info = "update low_priority t1 set n = 4";
56 --source include/wait_condition.inc
57 select n from t1;
58 connection locker;
59 unlock tables;
60 connection writer;
61 reap;
62 drop table t1;
65 # Test problem when using locks with multi-updates
66 # It should not block when multi-update is reading on a read-locked table
69 connection locker;
70 create table t1 (a int, b int);
71 create table t2 (c int, d int);
72 insert into t1 values(1,1);
73 insert into t1 values(2,2);
74 insert into t2 values(1,2);
75 lock table t1 read;
76 connection writer;
77 update t1,t2 set c=a where b=d;
78 connection reader;
79 select c from t2;
80 connection locker;
81 drop table t1;
82 drop table t2;
85 # Test problem when using locks on many tables and dropping a table that
86 # is to-be-locked by another thread
89 connection locker;
90 create table t1 (a int);
91 create table t2 (a int);
92 lock table t1 write, t2 write;
93 connection reader;
94 send
95 insert t1 select * from t2;
96 connection locker;
97 let $wait_condition=
98   select count(*) = 1 from information_schema.processlist
99   where state = "Locked" and info = "insert t1 select * from t2";
100 --source include/wait_condition.inc
101 drop table t2;
102 connection reader;
103 --error ER_NO_SUCH_TABLE
104 reap;
105 connection locker;
106 drop table t1;
109 # Same test as above, but with the dropped table locked twice
112 connection locker;
113 create table t1 (a int);
114 create table t2 (a int);
115 lock table t1 write, t2 write, t1 as t1_2 write, t2 as t2_2 write;
116 connection reader;
117 send
118 insert t1 select * from t2;
119 connection locker;
120 # Sleep a bit till the insert of connection reader is in work and hangs
121 let $wait_condition=
122   select count(*) = 1 from information_schema.processlist
123   where state = "Locked" and info = "insert t1 select * from t2";
124 --source include/wait_condition.inc
125 drop table t2;
126 connection reader;
127 --error ER_NO_SUCH_TABLE
128 reap;
129 connection locker;
130 drop table t1;
133 --echo End of 4.1 tests
136 # Bug#9998 MySQL client hangs on USE "database"
138 create table t1(a int);
139 lock tables t1 write;
140 connection reader;
141 show columns from t1;
142 connection locker;
143 unlock tables;
144 drop table t1;
147 # Bug#16986 Deadlock condition with MyISAM tables
150 # Need a matching user in mysql.user for multi-table select
151 --source include/add_anonymous_users.inc
153 connection locker;
154 USE mysql;
155 LOCK TABLES columns_priv WRITE, db WRITE, host WRITE, user WRITE;
156 FLUSH TABLES;
158 connection reader;
159 USE mysql;
160 # Note:  This must be a multi-table select, otherwise the deadlock will not occur
161 send
162 SELECT user.Select_priv FROM user, db WHERE user.user = db.user LIMIT 1;
164 connection locker;
165 # Sleep a bit till the select of connection reader is in work and hangs
166 let $wait_condition=
167   select count(*) = 1 from information_schema.processlist
168   where state = "Waiting for table" and info =
169   "SELECT user.Select_priv FROM user, db WHERE user.user = db.user LIMIT 1";
170 --source include/wait_condition.inc
171 # Make test case independent from earlier grants.
172 --replace_result "Table is already up to date" "OK"
173 OPTIMIZE TABLES columns_priv, db, host, user;
174 UNLOCK TABLES;
176 connection reader;
177 reap;
178 USE test;
180 connection locker;
181 use test;
183 connection default;
185 # Test if CREATE TABLE with LOCK TABLE deadlocks.
187 connection writer;
188 CREATE TABLE t1 (c1 int);
189 LOCK TABLE t1 WRITE;
191 # This waits until t1 is unlocked.
192 connection locker;
193 send
194 FLUSH TABLES WITH READ LOCK;
196 connection writer;
197 # Sleep a bit till the flush of connection locker is in work and hangs
198 let $wait_condition=
199   select count(*) = 1 from information_schema.processlist
200   where state = "Flushing tables" and info = "FLUSH TABLES WITH READ LOCK";
201 --source include/wait_condition.inc
202 # This must not block.
203 CREATE TABLE t2 (c1 int);
204 UNLOCK TABLES;
206 # This awakes now.
207 connection locker;
208 reap;
209 UNLOCK TABLES;
211 connection default;
212 DROP TABLE t1, t2;
214 # Test if CREATE TABLE SELECT with LOCK TABLE deadlocks.
216 connection writer;
217 CREATE TABLE t1 (c1 int);
218 LOCK TABLE t1 WRITE;
220 # This waits until t1 is unlocked.
221 connection locker;
222 send
223 FLUSH TABLES WITH READ LOCK;
225 # This must not block.
226 connection writer;
227 # Sleep a bit till the flush of connection locker is in work and hangs
228 let $wait_condition=
229   select count(*) = 1 from information_schema.processlist
230   where state = "Flushing tables" and info = "FLUSH TABLES WITH READ LOCK";
231 --source include/wait_condition.inc
232 --error ER_TABLE_NOT_LOCKED
233 CREATE TABLE t2 AS SELECT * FROM t1;
234 UNLOCK TABLES;
236 # This awakes now.
237 connection locker;
238 reap;
239 UNLOCK TABLES;
241 connection default;
242 DROP TABLE t1;
244 --source include/delete_anonymous_users.inc
247 # Bug#19815 CREATE/RENAME/DROP DATABASE can deadlock on a global read lock
249 connect (con1,localhost,root,,);
250 connect (con2,localhost,root,,);
252 connection con1;
253 CREATE DATABASE mysqltest_1;
254 FLUSH TABLES WITH READ LOCK;
256 # With bug in place: acquire LOCK_mysql_create_table and
257 # wait in wait_if_global_read_lock().
258 connection con2;
259 send
260 DROP DATABASE mysqltest_1;
262 # With bug in place: try to acquire LOCK_mysql_create_table...
263 # When fixed: Reject dropping db because of the read lock.
264 connection con1;
265 # Wait a bit so that the session con2 is in state "Waiting for release of readlock"
266 let $wait_condition=
267   select count(*) = 1 from information_schema.processlist
268   where state = "Waiting for release of readlock"
269   and info = "DROP DATABASE mysqltest_1";
270 --source include/wait_condition.inc
271 --error ER_CANT_UPDATE_WITH_READLOCK
272 DROP DATABASE mysqltest_1;
273 UNLOCK TABLES;
275 connection con2;
276 reap;
278 connection default;
279 disconnect con1;
280 disconnect con2;
281 # This must have been dropped by connection 2 already,
282 # which waited until the global read lock was released.
283 --error ER_DB_DROP_EXISTS
284 DROP DATABASE mysqltest_1;
287 # Bug#17264 MySQL Server freeze
289 connection locker;
290 # Disable warnings to allow test to run also without InnoDB
291 --disable_warnings
292 create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb;
293 --enable_warnings
294 lock tables t1 write;
295 connection writer;
296 send
297 alter table t1 auto_increment=0;
298 connection reader;
299 # Wait till connection writer is blocked
300 let $wait_condition=
301   select count(*) = 1 from information_schema.processlist
302   where state = "Locked" and info = "alter table t1 auto_increment=0";
303 --source include/wait_condition.inc
304 send
305 alter table t1 auto_increment=0;
306 connection locker;
307 # Wait till connection reader is blocked
308 let $wait_condition=
309   select count(*) = 2 from information_schema.processlist
310   where state = "Locked" and info = "alter table t1 auto_increment=0";
311 --source include/wait_condition.inc
312 unlock tables;
313 connection writer;
314 reap;
315 connection reader;
316 reap;
317 connection locker;
318 drop table t1;
321 # Bug#43230: SELECT ... FOR UPDATE can hang with FLUSH TABLES WITH READ LOCK indefinitely
324 connect (con1,localhost,root,,);
325 connect (con2,localhost,root,,);
326 connect (con3,localhost,root,,);
327 connect (con4,localhost,root,,);
328 connect (con5,localhost,root,,);
330 create table t1 (a int);
331 create table t2 like t1;
333 connection con1;
334 --echo # con1
335 lock tables t1 write;
336 connection con2;
337 --echo # con2
338 send flush tables with read lock;
339 connection con5;
340 --echo # con5
341 let $show_statement= SHOW PROCESSLIST;
342 let $field= State;
343 let $condition= = 'Flushing tables';
344 --source include/wait_show_condition.inc
345 --echo # global read lock is taken
346 connection con3;
347 --echo # con3
348 send select * from t2 for update;
349 connection con5;
350 let $show_statement= SHOW PROCESSLIST;
351 let $field= State;
352 let $condition= = 'Waiting for release of readlock';
353 --source include/wait_show_condition.inc
354 --echo # waiting for release of read lock
355 connection con4;
356 --echo # con4
357 --echo # would hang and later cause a deadlock
358 flush tables t2;
359 connection con1;
360 --echo # clean up
361 unlock tables;
362 connection con2;
363 --reap
364 unlock tables;
365 connection con3;
366 --reap
367 connection default;
368 disconnect con5;
369 disconnect con4;
370 disconnect con3;
371 disconnect con2;
372 disconnect con1;
374 drop table t1,t2;
376 --echo #
377 --echo # Lightweight version:
378 --echo # Ensure that the wait for a GRL is done before opening tables.
379 --echo #
381 connect (con1,localhost,root,,);
382 connect (con2,localhost,root,,);
384 create table t1 (a int);
385 create table t2 like t1;
387 --echo #
388 --echo # UPDATE
389 --echo #
391 connection default;
392 --echo # default
393 flush tables with read lock;
394 connection con1;
395 --echo # con1
396 send update t2 set a = 1;
397 connection default;
398 --echo # default
399 let $show_statement= SHOW PROCESSLIST;
400 let $field= State;
401 let $condition= = 'Waiting for release of readlock';
402 --source include/wait_show_condition.inc
403 --echo # statement is waiting for release of read lock
404 connection con2;
405 --echo # con2
406 flush table t2;
407 connection default;
408 --echo # default
409 unlock tables;
410 connection con1;
411 --echo # con1
412 --reap
414 --echo #
415 --echo # LOCK TABLES .. WRITE
416 --echo #
418 connection default;
419 --echo # default
420 flush tables with read lock;
421 connection con1;
422 --echo # con1
423 send lock tables t2 write;
424 connection default;
425 --echo # default
426 let $show_statement= SHOW PROCESSLIST;
427 let $field= State;
428 let $condition= = 'Waiting for release of readlock';
429 --source include/wait_show_condition.inc
430 --echo # statement is waiting for release of read lock
431 connection con2;
432 --echo # con2
433 flush table t2;
434 connection default;
435 --echo # default
436 unlock tables;
437 connection con1;
438 --echo # con1
439 --reap
440 unlock tables;
442 connection default;
443 disconnect con2;
444 disconnect con1;
446 drop table t1,t2;
449 --echo End of 5.0 tests
453 # Bug#21281 Pending write lock is incorrectly removed when its
454 #           statement being KILLed
456 create table t1 (i int);
457 connection locker;
458 lock table t1 read;
459 connection writer;
460 send
461 update t1 set i= 10;
462 connection reader;
463 let $wait_condition=
464   select count(*) = 1 from information_schema.processlist
465   where state = "Locked" and info = "update t1 set i= 10";
466 --source include/wait_condition.inc
467 send
468 select * from t1;
469 connection default;
470 let $wait_condition=
471   select count(*) = 1 from information_schema.processlist
472   where state = "Locked" and info = "select * from t1";
473 --source include/wait_condition.inc
474 let $ID= `select id from information_schema.processlist where state = "Locked" and info = "update t1 set i= 10"`;
475 --replace_result $ID ID
476 eval kill query $ID;
477 connection reader;
478 --reap
479 connection writer;
480 --error ER_QUERY_INTERRUPTED
481 --reap
482 connection locker;
483 unlock tables;
484 connection default;
485 drop table t1;
488 # Bug#25856 HANDLER table OPEN in one connection lock DROP TABLE in another one
490 --disable_warnings
491 drop table if exists t1;
492 --enable_warnings
493 create table t1 (a int) ENGINE=MEMORY;
494 --echo --> client 2
495 connection locker;
496 --error ER_ILLEGAL_HA
497 handler t1 open;
498 --echo --> client 1
499 connection default;
500 drop table t1;
503 # Disconnect sessions used in many subtests above
504 disconnect locker;
505 disconnect reader;
506 disconnect writer;
510 # Bug#32395 Alter table under a impending global read lock causes a server crash
514 # Test ALTER TABLE under LOCK TABLES and FLUSH TABLES WITH READ LOCK
517 --disable_warnings
518 drop table if exists t1;
519 --enable_warnings
520 create table t1 (i int);
521 connect (flush,localhost,root,,test,,);
522 connection default;
523 --echo connection: default
524 lock tables t1 write;
525 connection flush;
526 --echo connection: flush
527 --send flush tables with read lock;
528 connection default;
529 --echo connection: default
530 let $wait_condition=
531   select count(*) = 1 from information_schema.processlist
532   where state = "Flushing tables";
533 --source include/wait_condition.inc
534 alter table t1 add column j int;
535 connect (insert,localhost,root,,test,,);
536 connection insert;
537 --echo connection: insert
538 let $wait_condition=
539   select count(*) = 1 from information_schema.processlist
540   where state = "Flushing tables";
541 --source include/wait_condition.inc
542 --send insert into t1 values (1,2);
543 --echo connection: default
544 connection default;
545 let $wait_condition=
546   select count(*) = 1 from information_schema.processlist
547   where state = "Waiting for release of readlock";
548 --source include/wait_condition.inc
549 unlock tables;
550 connection flush;
551 --echo connection: flush
552 --reap
553 let $wait_condition=
554   select count(*) = 1 from information_schema.processlist
555   where state = "Waiting for release of readlock";
556 --source include/wait_condition.inc
557 select * from t1;
558 unlock tables;
559 connection insert;
560 --reap
561 connection default;
562 let $wait_condition=
563   select count(*) = 1 from t1;
564 --source include/wait_condition.inc
565 select * from t1;
566 drop table t1;
567 disconnect flush;
568 disconnect insert;
571 # Test that FLUSH TABLES under LOCK TABLES protects write locked tables
572 # from a impending FLUSH TABLES WITH READ LOCK
575 --disable_warnings
576 drop table if exists t1;
577 --enable_warnings
578 create table t1 (i int);
579 connect (flush,localhost,root,,test,,);
580 connection default;
581 --echo connection: default
582 lock tables t1 write;
583 connection flush;
584 --echo connection: flush
585 --send flush tables with read lock;
586 connection default;
587 --echo connection: default
588 let $wait_condition=
589   select count(*) = 1 from information_schema.processlist
590   where state = "Flushing tables";
591 --source include/wait_condition.inc
592 flush tables;
593 let $wait_condition=
594   select count(*) = 1 from information_schema.processlist
595   where state = "Flushing tables";
596 --source include/wait_condition.inc
597 unlock tables;
598 let $wait_condition=
599   select count(*) = 0 from information_schema.processlist
600   where state = "Flushing tables";
601 --source include/wait_condition.inc
602 connection flush;
603 --reap
604 connection default;
605 disconnect flush;
606 drop table t1;
609 # Bug#30331 Table_locks_waited shows inaccurate values
612 --disable_warnings
613 drop table if exists t1,t2;
614 --enable_warnings
615 create table t1 (a int);
616 flush status;
617 lock tables t1 read;
618 let $tlwa= `show status like 'Table_locks_waited'`;
619 connect (waiter,localhost,root,,);
620 connection waiter;
621 --send insert into t1 values(1);
622 connection default;
623 let $wait_condition=
624   select count(*) = 1 from information_schema.processlist
625   where state = "Locked" and info = "insert into t1 values(1)";
626 --source include/wait_condition.inc
627 let $tlwb= `show status like 'Table_locks_waited'`;
628 unlock tables;
629 connection waiter;
630 --reap
631 connection default;
632 drop table t1;
633 disconnect waiter;
634 --disable_query_log
635 eval SET @tlwa= SUBSTRING_INDEX('$tlwa', '      ', -1);
636 eval SET @tlwb= SUBSTRING_INDEX('$tlwb', '      ', -1);
637 --enable_query_log
638 select @tlwa < @tlwb;
640 --echo End of 5.1 tests
642 # Wait till all disconnects are completed
643 --source include/wait_until_count_sessions.inc