~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/sp-prelocking.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Tests of prelocking-free execution of stored procedures.
 
3
# Currently two properties of prelocking-free SP execution are checked:
 
4
#  - It is possible to execute DDL statements in prelocking-free stored
 
5
#    procedure
 
6
#  - The same procedure can be called in prelocking-free mode and 
 
7
#    in prelocked mode (from within a function).
 
8
 
 
9
--disable_warnings
 
10
drop database if exists mysqltest;
 
11
drop table if exists t1, t2, t3, t4;
 
12
drop procedure if exists sp1;
 
13
drop procedure if exists sp2;
 
14
drop procedure if exists sp3;
 
15
drop procedure if exists sp4;
 
16
drop function if exists f1;
 
17
drop function if exists f2;
 
18
drop function if exists f3;
 
19
--enable_warnings
 
20
 
 
21
# BUG#8072 
 
22
 
 
23
create database mysqltest;
 
24
delimiter //;
 
25
use mysqltest//
 
26
create procedure sp1 () 
 
27
begin
 
28
  drop table if exists t1;
 
29
  select 1 as "my-col";
 
30
end;
 
31
//
 
32
delimiter ;//
 
33
 
 
34
select database();
 
35
call sp1();
 
36
select database();
 
37
 
 
38
use test;
 
39
select database();
 
40
call mysqltest.sp1();
 
41
select database();
 
42
 
 
43
drop procedure mysqltest.sp1;
 
44
drop database mysqltest;
 
45
 
 
46
# BUG#8766
 
47
 
 
48
delimiter //;
 
49
create procedure sp1() 
 
50
begin 
 
51
  create table t1 (a int); 
 
52
  insert into t1 values (10); 
 
53
end//
 
54
 
 
55
create procedure sp2()
 
56
begin
 
57
  create table t2(a int);
 
58
  insert into t2 values(1);
 
59
  call sp1();
 
60
end//
 
61
 
 
62
create function f1() returns int
 
63
begin 
 
64
  return (select max(a) from t1);
 
65
end//
 
66
 
 
67
create procedure sp3()
 
68
begin 
 
69
  call sp1();
 
70
  select 'func', f1();
 
71
end//
 
72
 
 
73
delimiter ;//
 
74
 
 
75
call sp1();
 
76
select 't1',a from t1;
 
77
 
 
78
drop table t1;
 
79
call sp2();
 
80
select 't1',a from t1;
 
81
select 't2',a from t2;
 
82
drop table t1, t2;
 
83
 
 
84
call sp3();
 
85
select 't1',a from t1;
 
86
 
 
87
drop table t1;
 
88
 
 
89
drop procedure sp1;
 
90
drop procedure sp2;
 
91
drop procedure sp3;
 
92
drop function f1;
 
93
 
 
94
delimiter //;
 
95
create procedure sp1()
 
96
begin
 
97
  create temporary table t2(a int);
 
98
  insert into t2 select * from t1;
 
99
end//
 
100
 
 
101
create procedure sp2()
 
102
begin
 
103
  create temporary table t1 (a int);
 
104
  insert into t1 values(1);
 
105
  call sp1();
 
106
  select 't1', a from t1;
 
107
  select 't2', a from t2;
 
108
  drop table t1;
 
109
  drop table t2;
 
110
end//
 
111
 
 
112
delimiter ;//
 
113
call sp2();
 
114
 
 
115
drop procedure sp1;
 
116
drop procedure sp2;
 
117
 
 
118
# Miscelaneous tests
 
119
create table t1 (a int);
 
120
insert into t1 values(1),(2);
 
121
create table t2 as select * from t1;
 
122
create table t3 as select * from t1;
 
123
create table t4 as select * from t1;
 
124
delimiter //;
 
125
create procedure sp1(a int)
 
126
begin
 
127
  select a;
 
128
end //
 
129
 
 
130
create function f1() returns int
 
131
begin
 
132
  return (select max(a) from t1);
 
133
end //
 
134
 
 
135
delimiter ;//
 
136
 
 
137
CALL sp1(f1());
 
138
 
 
139
#############
 
140
delimiter //;
 
141
create procedure sp2(a int)
 
142
begin
 
143
  select * from t3;
 
144
  select a;
 
145
end //
 
146
 
 
147
create procedure sp3()
 
148
begin 
 
149
  select * from t1;
 
150
  call sp2(5);
 
151
end //
 
152
 
 
153
create procedure sp4()
 
154
begin 
 
155
  select * from t2;
 
156
  call sp3();
 
157
end //
 
158
 
 
159
delimiter ;//
 
160
call sp4();
 
161
 
 
162
drop procedure sp1;
 
163
drop procedure sp2;
 
164
drop procedure sp3;
 
165
drop procedure sp4;
 
166
drop function f1;
 
167
 
 
168
# Test that prelocking state restoration works with cursors
 
169
--disable_warnings
 
170
drop view if exists v1;
 
171
--enable_warnings
 
172
delimiter //;
 
173
 
 
174
create function f1(ab int) returns int
 
175
begin
 
176
  declare i int;
 
177
  set i= (select max(a) from t1 where a < ab) ;
 
178
  return i;
 
179
end //
 
180
 
 
181
create function f2(ab int) returns int
 
182
begin
 
183
  declare i int;
 
184
  set i= (select max(a) from t2 where a < ab) ;
 
185
  return i;
 
186
end //
 
187
 
 
188
create view v1 as 
 
189
  select t3.a as x, t4.a as y, f2(3) as z
 
190
  from t3, t4 where t3.a = t4.a //
 
191
 
 
192
create procedure sp1()
 
193
begin
 
194
  declare a int;
 
195
  set a= (select f1(4) + count(*) A from t1, v1);
 
196
end //
 
197
 
 
198
 
 
199
create function f3() returns int
 
200
begin
 
201
  call sp1();
 
202
  return 1;
 
203
end //
 
204
 
 
205
call sp1() //
 
206
 
 
207
select f3() //
 
208
select f3() //
 
209
 
 
210
call sp1() //
 
211
 
 
212
# ---------------
 
213
drop procedure sp1//
 
214
drop function f3//
 
215
 
 
216
create procedure sp1() 
 
217
begin 
 
218
  declare x int;
 
219
  declare c cursor for select f1(3) + count(*) from v1;
 
220
  open c;
 
221
  fetch c into x;
 
222
end;//
 
223
 
 
224
create function f3() returns int
 
225
begin
 
226
  call sp1();
 
227
  return 1;
 
228
end //
 
229
 
 
230
call sp1() //
 
231
call sp1() //
 
232
 
 
233
select f3() //
 
234
call sp1() //
 
235
 
 
236
delimiter ;//
 
237
drop view v1;
 
238
drop table t1,t2,t3,t4;
 
239
drop function f1;
 
240
drop function f2;
 
241
drop function f3;
 
242
drop procedure sp1;
 
243
 
 
244
#
 
245
# Bug#15683 "crash, Function on nested VIEWs, Prepared statement"
 
246
# Check that when creating the prelocking list a nested view 
 
247
# is not merged until it's used.
 
248
#
 
249
--disable_warnings
 
250
drop table if exists t1;
 
251
drop view if exists v1, v2, v3;
 
252
drop function if exists bug15683;
 
253
--enable_warnings
 
254
create table t1 (f1 bigint, f2 varchar(20), f3 bigint);
 
255
insert into t1 set f1 = 1, f2 = 'schoenenbourg', f3 = 1;
 
256
create view v1 as select 1 from t1 union all select 1;
 
257
create view v2 as select 1 from v1;
 
258
create view v3 as select 1 as f1 from v2;
 
259
 
 
260
delimiter |;
 
261
create function bug15683() returns bigint
 
262
begin
 
263
return (select count(*) from v3);
 
264
end|
 
265
delimiter ;|
 
266
 
 
267
prepare stmt from "select bug15683()";
 
268
execute stmt;
 
269
execute stmt;
 
270
deallocate prepare stmt;
 
271
drop table t1;
 
272
drop view v1, v2, v3;
 
273
drop function bug15683;
 
274
 
 
275
 
 
276
#
 
277
# Bug#19634 "Re-execution of multi-delete which involve trigger/stored 
 
278
#            function crashes server"
 
279
#
 
280
--disable_warnings
 
281
drop table if exists t1, t2, t3;
 
282
drop function if exists bug19634;
 
283
--enable_warnings
 
284
create table t1 (id int, data int);
 
285
create table t2 (id int);
 
286
create table t3 (data int);
 
287
create function bug19634() returns int return (select count(*) from t3);
 
288
prepare stmt from "delete t1 from t1, t2 where t1.id = t2.id and bug19634()";
 
289
# This should not crash server
 
290
execute stmt;
 
291
execute stmt;
 
292
deallocate prepare stmt;
 
293
 
 
294
create trigger t1_bi before delete on t1 for each row insert into t3 values (old.data);
 
295
prepare stmt from "delete t1 from t1, t2 where t1.id = t2.id";
 
296
 
 
297
execute stmt;
 
298
execute stmt;
 
299
deallocate prepare stmt;
 
300
 
 
301
drop function bug19634;
 
302
drop table t1, t2, t3;
 
303
 
 
304
#
 
305
# Bug #27907 Misleading error message when opening/locking tables
 
306
#
 
307
 
 
308
--disable_warnings
 
309
drop table if exists bug_27907_logs;
 
310
drop table if exists bug_27907_t1;
 
311
--enable_warnings
 
312
 
 
313
create table bug_27907_logs (a int);
 
314
create table bug_27907_t1 (a int);
 
315
 
 
316
delimiter |;
 
317
 
 
318
create trigger bug_27907_t1_ai after insert on bug_27907_t1
 
319
for each row
 
320
begin
 
321
  insert into bug_27907_logs (a) values (1);
 
322
end|
 
323
 
 
324
delimiter ;|
 
325
 
 
326
drop table bug_27907_logs;
 
327
 
 
328
#
 
329
# was failing before with error ER_NOT_LOCKED
 
330
#
 
331
--error ER_NO_SUCH_TABLE
 
332
insert into bug_27907_t1(a) values (1);
 
333
 
 
334
drop table bug_27907_t1;
 
335
 
 
336
--echo
 
337
--echo Bug#22427 create table if not exists + stored function results in
 
338
--echo inconsistent behavior
 
339
--echo
 
340
--echo Add a test case, the bug itself was fixed by the patch for
 
341
--echo Bug#20662
 
342
--echo
 
343
--disable_warnings
 
344
drop table if exists t1;
 
345
drop function if exists f_bug22427;
 
346
--enable_warnings
 
347
create table t1 (i int);
 
348
insert into t1 values (1);
 
349
create function f_bug22427() returns int return (select max(i) from t1);
 
350
select f_bug22427();
 
351
# Until this bug was fixed, the following emitted error
 
352
# ERROR 1213: Deadlock found when trying to get lock
 
353
create table if not exists t1 select f_bug22427() as i;
 
354
--error ER_TABLE_EXISTS_ERROR
 
355
create table t1 select f_bug22427() as i;
 
356
drop table t1;
 
357
drop function f_bug22427;
 
358
 
 
359
--echo #
 
360
--echo # Bug #29929 LOCK TABLES does not pre-lock tables used in triggers of the locked tables
 
361
--echo #
 
362
--disable_warnings
 
363
DROP table IF EXISTS t1,t2;
 
364
--enable_warnings
 
365
CREATE TABLE t1 (c1 INT);
 
366
CREATE TABLE t2 (c2 INT);
 
367
INSERT INTO t1 VALUES (1);
 
368
INSERT INTO t2 VALUES (2);
 
369
DELIMITER //;
 
370
CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
 
371
BEGIN
 
372
UPDATE t2 SET c2= c2 + 1;
 
373
END//
 
374
DELIMITER ;//
 
375
--echo # Take a table lock on t1.
 
376
--echo # This should pre-lock t2 through the trigger.
 
377
LOCK TABLE t1 WRITE;
 
378
INSERT INTO t1 VALUES (3);
 
379
UNLOCK TABLES;
 
380
LOCK TABLE t1 READ;
 
381
--error ER_TABLE_NOT_LOCKED
 
382
INSERT INTO t2 values(4);
 
383
UNLOCK TABLES;
 
384
SELECT * FROM t1;
 
385
SELECT * FROM t2;
 
386
DROP TRIGGER t1_ai;
 
387
DROP TABLE t1, t2;
 
388
 
 
389
--echo End of 5.0 tests
 
390