2
# Testing of table locking
6
drop table if exists t1,t2;
8
CREATE TABLE t1 ( `id` int(11) NOT NULL default '0', `id2` int(11) NOT NULL default '0', `id3` int(11) NOT NULL default '0', `dummy1` char(30) default NULL, PRIMARY KEY (`id`,`id2`), KEY `index_id3` (`id3`)) ENGINE=MyISAM;
9
insert into t1 (id,id2) values (1,1),(1,2),(1,3);
11
select dummy1,count(distinct id) from t1 group by dummy1;
12
update t1 set id=-1 where id=1;
15
update t1 set id=1 where id=1;
17
create table t2 SELECT * from t1;
18
create temporary table t2 SELECT * from t1;
19
drop table if exists t2;
21
create table t2 SELECT * from t1;
22
LOCK TABLE t1 WRITE,t2 write;
23
insert into t2 SELECT * from t1;
24
update t1 set id=1 where id=-1;
29
# Check bug with INSERT ... SELECT with lock tables
33
index1 smallint(6) default NULL,
34
nr smallint(6) default NULL,
39
nr smallint(6) default NULL,
40
name varchar(20) default NULL
43
INSERT INTO t2 VALUES (1,'item1');
44
INSERT INTO t2 VALUES (2,'item2');
46
# problem begins here!
47
lock tables t1 write, t2 read;
48
insert into t1 select 1,nr from t2 where name='item1';
49
insert into t1 select 2,nr from t2 where name='item2';
57
insert into t1 select index1,nr from t1;
59
lock tables t1 write, t1 as t1_alias read;
60
insert into t1 select index1,nr from t1 as t1_alias;
61
--error ER_TABLE_NOT_LOCKED
67
# BUG#5390 - problems with merge tables
68
# Supplement test for the after-fix optimization
69
# Check that a dropped table is correctly removed from a lock.
70
create table t1 (c1 int);
71
create table t2 (c1 int);
72
create table t3 (c1 int);
73
lock tables t1 write, t2 write, t3 write;
74
# This removes one table after the other from the lock.
75
drop table t2, t3, t1;
77
# Check that a lock merge works.
78
create table t1 (c1 int);
79
create table t2 (c1 int);
80
create table t3 (c1 int);
81
lock tables t1 write, t2 write, t3 write, t1 as t4 read;
82
alter table t2 add column c2 int;
83
drop table t1, t2, t3;
85
# Bug7241 - Invalid response when DELETE .. USING and LOCK TABLES used.
87
create table t1 ( a int(11) not null auto_increment, primary key(a));
88
create table t2 ( a int(11) not null auto_increment, primary key(a));
89
lock tables t1 write, t2 read;
90
delete from t1 using t1,t2 where t1.a=t2.a;
91
delete t1 from t1,t2 where t1.a=t2.a;
93
delete from t2 using t1,t2 where t1.a=t2.a;
95
delete t2 from t1,t2 where t1.a=t2.a;
96
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
101
--echo End of 4.1 tests.
105
# Bug#18884 "lock table + global read lock = crash"
106
# The bug is not repeatable, just add the test case.
109
drop table if exists t1;
111
create table t1 (a int);
113
--error ER_LOCK_OR_ACTIVE_TRANSACTION
114
flush tables with read lock;
120
# Test LOCK TABLE on system tables. See bug#9953: CONVERT_TZ requires
121
# mysql.time_zone_name to be locked.
124
DROP TABLE IF EXISTS t1;
127
CREATE TABLE t1 (i INT);
129
LOCK TABLES mysql.time_zone READ, t1 READ;
132
LOCK TABLES mysql.time_zone READ, t1 WRITE;
135
LOCK TABLES mysql.time_zone READ;
138
LOCK TABLES mysql.time_zone WRITE;
141
# If at least one system table is locked for WRITE, then all other
142
# tables should be system tables locked also for WRITE.
143
LOCK TABLES mysql.time_zone READ, t1 READ;
145
--error ER_WRONG_LOCK_OF_SYSTEM_TABLE
146
LOCK TABLES mysql.time_zone WRITE, t1 READ;
148
--error ER_WRONG_LOCK_OF_SYSTEM_TABLE
149
LOCK TABLES mysql.time_zone WRITE, t1 WRITE;
157
--echo End of 5.1 tests.