~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
# include/deadlock.inc
2
#
3
# The variable
4
#     $engine_type       -- storage engine to be tested
5
# has to be set before sourcing this script.
6
#
7
# Last update:
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
11
#
12
13
--echo # Establish connection con1 (user=root)
14
connect (con1,localhost,root,,);
15
--echo # Establish connection con2 (user=root)
16
connect (con2,localhost,root,,);
17
18
--disable_warnings
19
drop table if exists t1,t2;
20
--enable_warnings
21
22
#
23
# Testing of FOR UPDATE
24
#
25
26
--echo # Switch to connection con1
27
connection con1;
28
eval create table t1 (id integer, x integer) engine = $engine_type;
29
insert into t1 values(0, 0);
30
set autocommit=0;
31
SELECT * from t1 where id = 0 FOR UPDATE;
32
33
--echo # Switch to connection con2
34
connection con2;
35
set autocommit=0;
36
37
# The following query should hang because con1 is locking the record
38
--send
39
update t1 set x=2 where id = 0;
40
41
--echo # Switch to connection con1
42
connection con1;
43
update t1 set x=1 where id = 0;
44
select * from t1;
45
commit;
46
47
--echo # Switch to connection con2
48
connection con2;
49
reap;
50
commit;
51
52
--echo # Switch to connection con1
53
connection con1;
54
select * from t1;
55
commit;
56
57
drop table t1;
58
#
59
# Testing of FOR UPDATE
60
#
61
62
--echo # Switch to connection con1
63
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);
68
commit;
69
set autocommit=0;
70
select * from t2;
1114.1.2 by Monty Taylor
"Fixed" the deadlock test. I'd still like someone to look at what's going on here.
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);
1 by brian
clean slate
73
select * from t2;
74
select * from t1;
75
76
--echo # Switch to connection con2
77
connection con2;
78
set autocommit=0;
79
80
# The following query should hang because con1 is locking the record
81
--send
82
update t1 set x=2 where id = 0;
83
84
--echo # Switch to connection con1
85
connection con1;
86
update t1 set x=1 where id = 0;
87
select * from t1;
88
commit;
89
90
--echo # Switch to connection con2
91
connection con2;
92
reap;
93
commit;
94
95
--echo # Switch to connection con1
96
connection con1;
97
select * from t1;
98
commit;
99
100
drop table t1, t2;
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);
105
commit;
106
107
--echo # Switch to connection con1
108
connection con1;
109
select a,b from t2 UNION SELECT id, x from t1 FOR UPDATE;
110
select * from t2;
111
select * from t1;
112
113
--echo # Switch to connection con2
114
connection con2;
115
116
# The following query should hang because con1 is locking the record
117
update t2 set a=2 where b = 0;
118
select * from t2;
119
--send
120
update t1 set x=2 where id = 0;
121
122
--echo # Switch to connection con1
123
connection con1;
124
update t1 set x=1 where id = 0;
125
select * from t1;
126
commit;
127
128
--echo # Switch to connection con2
129
connection con2;
130
reap;
131
commit;
132
133
--echo # Switch to connection con1
134
connection con1;
135
select * from t1;
136
commit;
137
138
# Cleanup
139
--echo # Switch to connection default + disconnect con1 and con2
140
connection default;
141
disconnect con1;
142
disconnect con2;
143
drop table t1, t2;
144
145
--echo End of 4.1 tests
146
147
#
148
# Bug#25164 create table `a` as select * from `A` hangs
149
#
150
151
set storage_engine=innodb;
152
153
--disable_warnings
154
drop table if exists a;
155
drop table if exists A;
156
--enable_warnings
157
158
create table A (c int);
159
insert into A (c) values (0);
160
--error 0,ER_LOCK_DEADLOCK,ER_UPDATE_TABLE_USED
161
create table a as select * from A;
162
drop table A;
163
164
--disable_warnings
165
drop table if exists a;
166
--enable_warnings
167
168
set storage_engine=default;
169
170
--echo End of 5.0 tests.