4
# $engine_type -- storage engine to be tested
5
# has to be set before sourcing this script.
8
# 2006-07-26 ML refactoring + print when connection is switched
9
# old name was t/innodb-deadlock.test
10
# main code went into include/deadlock.inc
13
--echo # Establish connection con1 (user=root)
14
connect (con1,localhost,root,,);
15
--echo # Establish connection con2 (user=root)
16
connect (con2,localhost,root,,);
19
drop table if exists t1,t2;
23
# Testing of FOR UPDATE
26
--echo # Switch to connection con1
28
eval create table t1 (id integer, x integer) engine = $engine_type;
29
insert into t1 values(0, 0);
31
SELECT * from t1 where id = 0 FOR UPDATE;
33
--echo # Switch to connection con2
37
# The following query should hang because con1 is locking the record
39
update t1 set x=2 where id = 0;
41
--echo # Switch to connection con1
43
update t1 set x=1 where id = 0;
47
--echo # Switch to connection con2
52
--echo # Switch to connection con1
59
# Testing of FOR UPDATE
62
--echo # Switch to connection con1
64
eval create table t1 (id integer, x integer) engine = $engine_type;
65
eval create table t2 (b integer, a integer) engine = $engine_type;
66
insert into t1 values(0, 0), (300, 300);
67
insert into t2 values(0, 10), (1, 20), (2, 30);
71
select x from t1 where id=0 FOR UPDATE;
72
update t2 set a=100 where b=(SELECT x from t1 where id = b);
76
--echo # Switch to connection con2
80
# The following query should hang because con1 is locking the record
82
update t1 set x=2 where id = 0;
84
--echo # Switch to connection con1
86
update t1 set x=1 where id = 0;
90
--echo # Switch to connection con2
95
--echo # Switch to connection con1
101
eval create table t1 (id integer, x integer) engine = $engine_type;
102
eval create table t2 (b integer, a integer) engine = $engine_type;
103
insert into t1 values(0, 0), (300, 300);
104
insert into t2 values(0, 0), (1, 20), (2, 30);
107
--echo # Switch to connection con1
109
select a,b from t2 UNION SELECT id, x from t1 FOR UPDATE;
113
--echo # Switch to connection con2
116
# The following query should hang because con1 is locking the record
117
update t2 set a=2 where b = 0;
120
update t1 set x=2 where id = 0;
122
--echo # Switch to connection con1
124
update t1 set x=1 where id = 0;
128
--echo # Switch to connection con2
133
--echo # Switch to connection con1
139
--echo # Switch to connection default + disconnect con1 and con2
145
--echo End of 4.1 tests
148
# Bug#25164 create table `a` as select * from `A` hangs
151
set storage_engine=innodb;
154
drop table if exists a;
155
drop table if exists A;
158
create table A (c int);
159
insert into A (c) values (0);
160
--error EE_OK,ER_LOCK_DEADLOCK,ER_UPDATE_TABLE_USED
161
create table a as select * from A;
165
drop table if exists a;
168
set storage_engine=default;
170
--echo End of 5.0 tests.