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;
42 --echo # Switch
to connection con1
44 update t1
set x=1 where
id = 0;
48 --echo # Switch
to connection con2
53 --echo # Switch
to connection con1
60 # Testing of FOR UPDATE
63 --echo # Switch
to connection con1
65 eval create
table t1 (
id integer, x integer) engine = $engine_type;
66 eval create
table t2 (b integer, a integer) engine = $engine_type;
67 insert into t1 values(0, 0), (300, 300);
68 insert into t2 values(0, 10), (1, 20), (2, 30);
72 update t2
set a=100 where b=(SELECT x from t1 where
id = b FOR UPDATE);
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;
85 --echo # Switch
to connection con1
87 update t1
set x=1 where
id = 0;
91 --echo # Switch
to connection con2
96 --echo # Switch
to connection con1
102 eval create
table t1 (
id integer, x integer) engine = $engine_type;
103 eval create
table t2 (b integer, a integer) engine = $engine_type;
104 insert into t1 values(0, 0), (300, 300);
105 insert into t2 values(0, 0), (1, 20), (2, 30);
108 --echo # Switch
to connection con1
110 select a,b from t2 UNION SELECT
id, x from t1 FOR UPDATE;
114 --echo # Switch
to connection con2
117 # The following query should hang because con1 is locking the record
118 update t2
set a=2 where b = 0;
121 update t1
set x=2 where
id = 0;
124 --echo # Switch
to connection con1
126 update t1
set x=1 where
id = 0;
130 --echo # Switch
to connection con2
135 --echo # Switch
to connection con1
141 --echo # Switch
to connection
default + disconnect con1 and con2
147 --echo End of 4.1 tests
150 # Bug#25164 create table `a` as select * from `A` hangs
153 set default_storage_engine=innodb;
156 drop
table if exists a;
160 create
table A (c
int);
161 insert into A (c) values (0);
162 --error 0,ER_LOCK_DEADLOCK,ER_TABLE_EXISTS_ERROR
163 create
table a as select * from A;
167 drop
table if exists a;
170 set default_storage_engine=default;
172 --echo End of 5.0 tests.