2003-03-04 11:22:35 +01:00
|
|
|
drop table if exists t1,t2;
|
2001-10-08 06:24:04 +02:00
|
|
|
create table t1(n int);
|
|
|
|
insert into t1 values (1);
|
|
|
|
lock tables t1 write;
|
2006-10-04 23:48:24 +02:00
|
|
|
update low_priority t1 set n = 4;
|
|
|
|
select n from t1;
|
2001-10-08 06:24:04 +02:00
|
|
|
unlock tables;
|
2001-10-08 03:58:07 +02:00
|
|
|
n
|
|
|
|
4
|
2001-10-08 06:24:04 +02:00
|
|
|
drop table t1;
|
|
|
|
create table t1(n int);
|
|
|
|
insert into t1 values (1);
|
|
|
|
lock tables t1 read;
|
2006-10-04 23:48:24 +02:00
|
|
|
update low_priority t1 set n = 4;
|
|
|
|
select n from t1;
|
2001-10-08 03:58:07 +02:00
|
|
|
n
|
|
|
|
1
|
2007-08-11 12:07:49 +02:00
|
|
|
unlock tables;
|
2001-10-08 06:24:04 +02:00
|
|
|
drop table t1;
|
2004-10-03 01:20:47 +02:00
|
|
|
create table t1 (a int, b int);
|
|
|
|
create table t2 (c int, d int);
|
|
|
|
insert into t1 values(1,1);
|
|
|
|
insert into t1 values(2,2);
|
|
|
|
insert into t2 values(1,2);
|
|
|
|
lock table t1 read;
|
2006-10-04 23:48:24 +02:00
|
|
|
update t1,t2 set c=a where b=d;
|
2004-10-03 01:20:47 +02:00
|
|
|
select c from t2;
|
|
|
|
c
|
2004-11-05 16:29:47 +01:00
|
|
|
2
|
Backport of:
------------------------------------------------------------
revno: 2476.784.3
committer: davi@moksha.local
timestamp: Tue 2007-10-02 21:27:31 -0300
message:
Bug#25858 Some DROP TABLE under LOCK TABLES can cause deadlocks
When a client (connection) holds a lock on a table and attempts to
drop (obtain a exclusive lock) on a second table that is already
held by a second client and the second client then attempts to
drop the table that is held by the first client, leads to a
circular wait deadlock. This scenario is very similar to trying to
drop (or rename) a table while holding read locks and are
correctly forbidden.
The solution is to allow a drop table operation to continue only
if the table being dropped is write (exclusively) locked, or if
the table is temporary, or if the client is not holding any
locks. Using this scheme prevents the creation of a circular
chain in which each client is waiting for one table that the
next client in the chain is holding.
This is incompatible change, as can be seen by number of tests
cases that needed to be fixed, but is consistent with respect to
behavior of the different scenarios in which the circular wait
might happen.
mysql-test/r/drop.result:
Test case result for Bug#25858
mysql-test/r/group_by.result:
Fix test case result wrt drop table under lock tables -- unlock tables
before dropping table.
mysql-test/r/insert_notembedded.result:
Fix test case result wrt drop table under lock tables -- unlock tables
before dropping table
mysql-test/r/lock.result:
Fix test case result wrt drop table under lock tables -- unlock tables
before dropping table.
mysql-test/r/lock_multi.result:
Fix test case result wrt drop table under lock tables -- unlock tables
before dropping table.
mysql-test/r/myisam.result:
Fix test case result wrt drop table under lock tables -- unlock tables
before dropping table.
mysql-test/r/view.result:
Fix test case result wrt drop table under lock tables -- unlock tables
before dropping table.
mysql-test/t/drop.test:
Add test case for Bug#25858
mysql-test/t/group_by.test:
Fix test case: unlock tables in preparation for a drop table. In some
circumstances, dropping tables while holding locks leads to a deadlock.
mysql-test/t/insert_notembedded.test:
Fix test case: unlock tables in preparation for a drop table. In some
circumstances, dropping tables while holding locks leads to a deadlock.
mysql-test/t/lock.test:
Fix test case: unlock tables in preparation for a drop table. In some
circumstances, dropping tables while holding locks leads to a deadlock.
mysql-test/t/lock_multi.test:
Fix test case: unlock tables in preparation for a drop table. In some
circumstances, dropping tables while holding locks leads to a deadlock.
mysql-test/t/myisam.test:
Fix test case: unlock tables in preparation for a drop table. In some
circumstances, dropping tables while holding locks leads to a deadlock.
mysql-test/t/query_cache_notembedded.test:
Fix test case: unlock tables in preparation for a drop table. In some
circumstances, dropping tables while holding locks leads to a deadlock.
mysql-test/t/view.test:
Fix test case: unlock tables in preparation for a drop table. In some
circumstances, dropping tables while holding locks leads to a deadlock.
sql/lock.cc:
When trying to obtain a name lock under lock tables, ensure that the table is properly exclusively locked and fail otherwise.
2009-11-20 20:51:12 +01:00
|
|
|
unlock tables;
|
2004-10-03 01:20:47 +02:00
|
|
|
drop table t1;
|
|
|
|
drop table t2;
|
2003-03-04 11:22:35 +01:00
|
|
|
create table t1 (a int);
|
|
|
|
create table t2 (a int);
|
|
|
|
lock table t1 write, t2 write;
|
2006-10-04 23:48:24 +02:00
|
|
|
insert t1 select * from t2;
|
2003-03-04 11:22:35 +01:00
|
|
|
drop table t2;
|
2003-06-04 17:28:51 +02:00
|
|
|
ERROR 42S02: Table 'test.t2' doesn't exist
|
2003-03-04 11:22:35 +01:00
|
|
|
drop table t1;
|
2006-03-29 13:27:36 +02:00
|
|
|
create table t1 (a int);
|
|
|
|
create table t2 (a int);
|
|
|
|
lock table t1 write, t2 write, t1 as t1_2 write, t2 as t2_2 write;
|
2006-10-05 00:36:03 +02:00
|
|
|
insert t1 select * from t2;
|
2006-03-29 13:27:36 +02:00
|
|
|
drop table t2;
|
|
|
|
ERROR 42S02: Table 'test.t2' doesn't exist
|
|
|
|
drop table t1;
|
2007-08-11 12:07:49 +02:00
|
|
|
End of 4.1 tests
|
2005-06-03 15:29:05 +02:00
|
|
|
create table t1(a int);
|
|
|
|
lock tables t1 write;
|
|
|
|
show columns from t1;
|
|
|
|
Field Type Null Key Default Extra
|
|
|
|
a int(11) YES NULL
|
|
|
|
unlock tables;
|
|
|
|
drop table t1;
|
2009-03-03 21:34:18 +01:00
|
|
|
USE mysql;
|
2006-05-24 16:21:35 +02:00
|
|
|
LOCK TABLES columns_priv WRITE, db WRITE, host WRITE, user WRITE;
|
|
|
|
FLUSH TABLES;
|
2009-03-03 21:34:18 +01:00
|
|
|
USE mysql;
|
2006-10-04 23:48:24 +02:00
|
|
|
SELECT user.Select_priv FROM user, db WHERE user.user = db.user LIMIT 1;
|
2006-05-24 16:21:35 +02:00
|
|
|
OPTIMIZE TABLES columns_priv, db, host, user;
|
|
|
|
Table Op Msg_type Msg_text
|
|
|
|
mysql.columns_priv optimize status OK
|
|
|
|
mysql.db optimize status OK
|
|
|
|
mysql.host optimize status OK
|
|
|
|
mysql.user optimize status OK
|
|
|
|
UNLOCK TABLES;
|
|
|
|
Select_priv
|
|
|
|
N
|
2009-03-03 21:34:18 +01:00
|
|
|
USE test;
|
2006-05-24 16:21:35 +02:00
|
|
|
use test;
|
2006-06-26 19:14:35 +02:00
|
|
|
CREATE TABLE t1 (c1 int);
|
|
|
|
LOCK TABLE t1 WRITE;
|
2006-10-04 23:48:24 +02:00
|
|
|
FLUSH TABLES WITH READ LOCK;
|
2006-06-26 19:14:35 +02:00
|
|
|
CREATE TABLE t2 (c1 int);
|
|
|
|
UNLOCK TABLES;
|
|
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLE t1, t2;
|
|
|
|
CREATE TABLE t1 (c1 int);
|
|
|
|
LOCK TABLE t1 WRITE;
|
2006-10-04 23:48:24 +02:00
|
|
|
FLUSH TABLES WITH READ LOCK;
|
2006-06-26 19:14:35 +02:00
|
|
|
CREATE TABLE t2 AS SELECT * FROM t1;
|
|
|
|
ERROR HY000: Table 't2' was not locked with LOCK TABLES
|
|
|
|
UNLOCK TABLES;
|
|
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLE t1;
|
2006-05-29 15:26:23 +02:00
|
|
|
CREATE DATABASE mysqltest_1;
|
|
|
|
FLUSH TABLES WITH READ LOCK;
|
2006-10-04 23:48:24 +02:00
|
|
|
DROP DATABASE mysqltest_1;
|
2006-05-29 15:26:23 +02:00
|
|
|
DROP DATABASE mysqltest_1;
|
|
|
|
ERROR HY000: Can't execute the query because you have a conflicting read lock
|
|
|
|
UNLOCK TABLES;
|
|
|
|
DROP DATABASE mysqltest_1;
|
|
|
|
ERROR HY000: Can't drop database 'mysqltest_1'; database doesn't exist
|
2006-06-20 19:43:13 +02:00
|
|
|
create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb;
|
|
|
|
lock tables t1 write;
|
2007-08-11 12:07:49 +02:00
|
|
|
alter table t1 auto_increment=0;
|
|
|
|
alter table t1 auto_increment=0;
|
2006-06-20 19:43:13 +02:00
|
|
|
unlock tables;
|
|
|
|
drop table t1;
|
2009-04-03 21:11:54 +02:00
|
|
|
create table t1 (a int);
|
|
|
|
create table t2 like t1;
|
|
|
|
# con1
|
|
|
|
lock tables t1 write;
|
|
|
|
# con2
|
|
|
|
flush tables with read lock;
|
|
|
|
# con5
|
|
|
|
# global read lock is taken
|
|
|
|
# con3
|
|
|
|
select * from t2 for update;
|
|
|
|
# waiting for release of read lock
|
|
|
|
# con4
|
|
|
|
# would hang and later cause a deadlock
|
|
|
|
flush tables t2;
|
|
|
|
# clean up
|
|
|
|
unlock tables;
|
|
|
|
unlock tables;
|
|
|
|
a
|
|
|
|
drop table t1,t2;
|
|
|
|
#
|
|
|
|
# Lightweight version:
|
|
|
|
# Ensure that the wait for a GRL is done before opening tables.
|
|
|
|
#
|
|
|
|
create table t1 (a int);
|
|
|
|
create table t2 like t1;
|
|
|
|
#
|
|
|
|
# UPDATE
|
|
|
|
#
|
|
|
|
# default
|
|
|
|
flush tables with read lock;
|
|
|
|
# con1
|
|
|
|
update t2 set a = 1;
|
|
|
|
# default
|
|
|
|
# statement is waiting for release of read lock
|
|
|
|
# con2
|
|
|
|
flush table t2;
|
|
|
|
# default
|
|
|
|
unlock tables;
|
|
|
|
# con1
|
|
|
|
#
|
|
|
|
# LOCK TABLES .. WRITE
|
|
|
|
#
|
|
|
|
# default
|
|
|
|
flush tables with read lock;
|
|
|
|
# con1
|
|
|
|
lock tables t2 write;
|
|
|
|
# default
|
|
|
|
# statement is waiting for release of read lock
|
|
|
|
# con2
|
|
|
|
flush table t2;
|
|
|
|
# default
|
|
|
|
unlock tables;
|
|
|
|
# con1
|
|
|
|
unlock tables;
|
|
|
|
drop table t1,t2;
|
2007-08-11 12:07:49 +02:00
|
|
|
End of 5.0 tests
|
2007-08-05 11:55:37 +02:00
|
|
|
create table t1 (i int);
|
|
|
|
lock table t1 read;
|
2009-03-06 15:56:17 +01:00
|
|
|
update t1 set i= 10;
|
|
|
|
select * from t1;
|
2007-08-05 11:55:37 +02:00
|
|
|
kill query ID;
|
|
|
|
i
|
|
|
|
ERROR 70100: Query execution was interrupted
|
|
|
|
unlock tables;
|
|
|
|
drop table t1;
|
2007-08-17 16:34:12 +02:00
|
|
|
drop table if exists t1;
|
|
|
|
create table t1 (a int) ENGINE=MEMORY;
|
|
|
|
--> client 2
|
|
|
|
handler t1 open;
|
|
|
|
ERROR HY000: Table storage engine for 't1' doesn't have this option
|
|
|
|
--> client 1
|
|
|
|
drop table t1;
|
2007-12-12 22:44:14 +01:00
|
|
|
drop table if exists t1;
|
|
|
|
create table t1 (i int);
|
|
|
|
connection: default
|
|
|
|
lock tables t1 write;
|
|
|
|
connection: flush
|
|
|
|
flush tables with read lock;;
|
|
|
|
connection: default
|
|
|
|
alter table t1 add column j int;
|
|
|
|
connection: insert
|
|
|
|
insert into t1 values (1,2);;
|
|
|
|
connection: default
|
|
|
|
unlock tables;
|
|
|
|
connection: flush
|
|
|
|
select * from t1;
|
|
|
|
i j
|
|
|
|
unlock tables;
|
|
|
|
select * from t1;
|
|
|
|
i j
|
|
|
|
1 2
|
|
|
|
drop table t1;
|
|
|
|
drop table if exists t1;
|
|
|
|
create table t1 (i int);
|
|
|
|
connection: default
|
|
|
|
lock tables t1 write;
|
|
|
|
connection: flush
|
|
|
|
flush tables with read lock;;
|
|
|
|
connection: default
|
|
|
|
flush tables;
|
|
|
|
unlock tables;
|
|
|
|
drop table t1;
|
2008-01-28 13:52:41 +01:00
|
|
|
drop table if exists t1,t2;
|
|
|
|
create table t1 (a int);
|
|
|
|
flush status;
|
|
|
|
lock tables t1 read;
|
|
|
|
insert into t1 values(1);;
|
2008-01-29 13:37:44 +01:00
|
|
|
unlock tables;
|
2008-01-28 13:52:41 +01:00
|
|
|
drop table t1;
|
2008-01-29 13:37:44 +01:00
|
|
|
select @tlwa < @tlwb;
|
|
|
|
@tlwa < @tlwb
|
|
|
|
1
|
2007-08-05 11:55:37 +02:00
|
|
|
End of 5.1 tests
|