2
# tests that require InnoDB...
5
-- source include/have_log_bin.inc
6
-- source include/have_innodb.inc
9
drop table if exists t1, t2, t3;
15
# BUG#8850: Truncate table in a stored procedure locks the tables
18
drop procedure if exists bug8850|
20
create table t1 (a int) engine=innodb|
21
create procedure bug8850()
23
truncate table t1; insert t1 values (1); rollback;
36
drop procedure bug8850|
40
# BUG#10015: Crash in InnoDB if stored routines are used
41
# (crash happens in auto-commit mode)
44
drop function if exists bug10015_1|
45
drop function if exists bug10015_2|
46
drop function if exists bug10015_3|
47
drop function if exists bug10015_4|
48
drop function if exists bug10015_5|
49
drop function if exists bug10015_6|
50
drop function if exists bug10015_7|
51
drop procedure if exists bug10015_8|
53
create table t1 (id int) engine=innodb|
54
create table t2 (id int primary key, j int) engine=innodb|
55
insert into t1 values (1),(2),(3)|
56
create function bug10015_1() returns int return (select count(*) from t1)|
57
select *, bug10015_1() from t1|
58
drop function bug10015_1|
59
# Test couple of a bit more complex cases
60
create function bug10015_2() returns int
63
set i:= (select min(id) from t1);
64
set s:= (select max(id) from t1);
67
select *, bug10015_2() from t1|
68
drop function bug10015_2|
69
create function bug10015_3() returns int
70
return (select max(a.id - b.id) from t1 as a, t1 as b where a.id >= b.id)|
71
select *, bug10015_3() from t1|
72
drop function bug10015_3|
73
create function bug10015_4(i int) returns int
76
set m:= (select max(id) from t2);
77
insert into t2 values (i, m);
80
select *, bug10015_4(id) from t1|
82
drop function bug10015_4|
83
# Now let us test how statement rollback works
84
# This function will cause the whole stmt to be rolled back,
85
# there should not be any traces left.
86
create function bug10015_5(i int) returns int
89
insert into t2 values (1, 0);
94
insert into t1 values (bug10015_5(4)), (bug10015_5(5))|
96
drop function bug10015_5|
97
# Thanks to error-handler this function should not cause rollback
98
# of statement calling it. But insert statement in it should be
99
# rolled back completely and don't leave any traces in t2.
100
# Unfortunately we can't implement such behavior in 5.0, so it
101
# is something to be fixed in later 5.* releases (TODO).
102
create function bug10015_6(i int) returns int
104
declare continue handler for sqlexception set @error_in_func:= 1;
106
insert into t2 values (4, 0), (1, 0);
110
set @error_in_func:= 0|
111
insert into t1 values (bug10015_6(5)), (bug10015_6(6))|
112
select @error_in_func|
115
drop function bug10015_6|
116
# Let us test that we don't allow any statements causing transaction
117
# commit in stored functions (we test only most interesting cases here).
118
# Cases which can be caught at creation time:
120
create function bug10015_7() returns int
122
alter table t1 add k int;
126
create function bug10015_7() returns int
132
create function bug10015_7() returns int
137
# It should be OK to drop temporary table.
138
create function bug10015_7() returns int
140
drop temporary table t1;
143
drop function bug10015_7|
145
create function bug10015_7() returns int
150
# Now let us test cases which we can catch only at run-time:
151
create function bug10015_7() returns int
156
create procedure bug10015_8() alter table t1 add k int|
158
select *, bug10015_7() from t1|
159
drop procedure bug10015_8|
160
create procedure bug10015_8() start transaction|
162
select *, bug10015_7() from t1|
163
drop procedure bug10015_8|
164
# Again it is OK to drop temporary table
165
# We are surpressing warnings since they are not essential
166
create procedure bug10015_8() drop temporary table if exists t1_temp|
168
select *, bug10015_7() from t1|
170
drop procedure bug10015_8|
171
create procedure bug10015_8() commit|
173
select *, bug10015_7() from t1|
174
drop procedure bug10015_8|
175
drop function bug10015_7|
180
# BUG#13825 "Triggers: crash if release savepoint".
181
# Also general test for handling of savepoints in stored routines.
183
# According to SQL standard we should establish new savepoint
184
# level before executing stored function/trigger and destroy
185
# this savepoint level after execution. Stored procedures by
186
# default should be executed using the same savepoint level
187
# as their caller (to execute stored procedure using new
188
# savepoint level one should explicitly specify NEW SAVEPOINT
189
# LEVEL clause in procedure creation statement which MySQL
190
# does not support yet).
192
drop function if exists bug13825_0|
193
drop function if exists bug13825_1|
194
drop function if exists bug13825_2|
195
drop function if exists bug13825_3|
196
drop function if exists bug13825_4|
197
drop function if exists bug13825_5|
198
drop procedure if exists bug13825_0|
199
drop procedure if exists bug13825_1|
200
drop procedure if exists bug13825_2|
201
drop table if exists t1|
203
create table t1 (i int) engine=innodb|
204
create table t2 (i int) engine=innodb|
205
create function bug13825_0() returns int
207
rollback to savepoint x;
210
create function bug13825_1() returns int
215
create function bug13825_2() returns int
217
insert into t1 values (2);
219
insert into t1 values (3);
220
rollback to savepoint x;
221
insert into t1 values (4);
224
create procedure bug13825_0()
226
rollback to savepoint x;
228
create procedure bug13825_1()
232
create procedure bug13825_2()
236
insert into t2 values (1)|
237
create trigger t2_bi before insert on t2 for each row
238
rollback to savepoint x|
239
create trigger t2_bu before update on t2 for each row
241
create trigger t2_bd before delete on t2 for each row
243
insert into t1 values (2);
245
insert into t1 values (3);
246
rollback to savepoint x;
247
insert into t1 values (4);
249
create function bug13825_3(rb int) returns int
251
insert into t1 values(1);
253
insert into t1 values(2);
255
rollback to savepoint x;
257
insert into t1 values(3);
260
create function bug13825_4() returns int
263
insert into t1 values(2);
264
rollback to savepoint x;
267
create function bug13825_5(p int) returns int
270
insert into t2 values(p);
271
rollback to savepoint x;
272
insert into t2 values(p+1);
276
# Test of savepoint level handling for stored functions and triggers
278
insert into t1 values (1)|
280
--error ER_SP_DOES_NOT_EXIST
281
set @a:= bug13825_0()|
282
--error ER_SP_DOES_NOT_EXIST
283
insert into t2 values (2)|
284
--error ER_SP_DOES_NOT_EXIST
285
set @a:= bug13825_1()|
286
--error ER_SP_DOES_NOT_EXIST
288
set @a:= bug13825_2()|
290
rollback to savepoint x|
294
rollback to savepoint x|
296
# Of course savepoints set in function should not be visible from its caller
298
set @a:= bug13825_2()|
300
--error ER_SP_DOES_NOT_EXIST
301
rollback to savepoint x|
304
# Test of savepoint level handling for stored procedures
306
insert into t1 values (5)|
308
insert into t1 values (6)|
312
--error ER_SP_DOES_NOT_EXIST
313
rollback to savepoint x|
315
insert into t1 values (7)|
317
rollback to savepoint x|
322
# Let us test that savepoints work inside of functions
323
# even in auto-commit mode
324
select bug13825_3(0)|
327
select bug13825_3(1)|
330
# Curious case: rolling back to savepoint which is set by first
331
# statement in function should not rollback whole transaction.
334
insert into t1 values (1)|
335
set @a:= bug13825_4()|
340
# Other curious case: savepoint in the middle of statement
342
create table t2 (i int) engine=innodb|
343
insert into t1 values (1), (bug13825_5(2)), (3)|
347
drop function bug13825_0|
348
drop function bug13825_1|
349
drop function bug13825_2|
350
drop function bug13825_3|
351
drop function bug13825_4|
352
drop function bug13825_5|
353
drop procedure bug13825_0|
354
drop procedure bug13825_1|
355
drop procedure bug13825_2|
360
# BUG#14840: CONTINUE handler problem
363
drop table if exists t3|
364
drop procedure if exists bug14840_1|
365
drop procedure if exists bug14840_2|
375
# This used to hang the client since the insert returned with an
376
# error status (left over from the update) even though it succeeded,
377
# which caused the execution to end at that point.
378
create procedure bug14840_1()
380
declare err int default 0;
381
declare continue handler for sqlexception
385
update t3 set x = 1, y = 42 where x = 2;
386
insert into t3 values (3, 4711);
395
# A simpler (non-transactional) case: insert at select should be done
396
create procedure bug14840_2()
398
declare err int default 0;
399
declare continue handler for sqlexception
402
select err as 'Ping';
405
update t3 set x = 1, y = 42 where x = 2;
406
update t3 set x = 1, y = 42 where x = 2;
407
insert into t3 values (3, 4711);
411
insert into t3 values (1, 3), (2, 5)|
415
insert into t3 values (1, 3), (2, 5)|
418
drop procedure bug14840_1|
419
drop procedure bug14840_2|
424
# BUG#10656: Stored Procedure - Create index and Truncate table command error
427
drop procedure if exists bug10656_create_index|
428
drop procedure if exists bug10656_myjoin|
429
drop procedure if exists bug10656_truncate_table|
433
`ID` int(11) default NULL,
434
`txt` char(5) default NULL
435
) ENGINE=InnoDB DEFAULT CHARSET=latin1|
437
INSERT INTO t3 (`ID`,`txt`) VALUES
438
(1,'a'), (2,'b'), (3,'c'), (4,'d')|
441
`ID` int(11) default NULL,
442
`txt` char(5) default NULL
443
) ENGINE=InnoDB DEFAULT CHARSET=latin1|
445
INSERT INTO t4 (`ID`,`txt`) VALUES
446
(1,'a'), (2,'b'), (3,'c'), (4,'d')|
448
create procedure bug10656_create_index()
450
create index bug10656_my_index on t3 (ID);
452
call bug10656_create_index()|
454
create procedure bug10656_myjoin()
456
update t3, t4 set t3.txt = t4.txt where t3.id = t4.id;
458
call bug10656_myjoin()|
460
create procedure bug10656_truncate_table()
464
call bug10656_truncate_table()|
467
drop procedure bug10656_create_index|
468
drop procedure bug10656_myjoin|
469
drop procedure bug10656_truncate_table|
487
insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')|
488
insert into t4 values (1 , 'bCh1' )|
491
drop procedure if exists bug3448|
493
create procedure bug3448()
494
select * from t3 inner join t4 on t3.a = t4.b|
496
select * from t3 inner join t4 on t3.a = t4.b|
500
drop procedure bug3448|
504
# BUG#14210: "Simple query with > operator on large table gives server
506
# Check that cursors work in case when HEAP tables are converted to
510
drop procedure if exists bug14210|
512
set @@session.max_heap_table_size=16384|
513
select @@session.max_heap_table_size|
514
# To trigger the memory corruption the original table must be InnoDB.
515
# No harm if it's not, so don't warn if the suite is run with --skip-innodb
517
create table t3 (a char(255)) engine=InnoDB|
519
create procedure bug14210_fill_table()
521
declare table_size, max_table_size int default 0;
522
select @@session.max_heap_table_size into max_table_size;
524
insert into t3 (a) values (repeat('a', 255));
526
insert into t3 select a from t3;
527
select count(*)*255 from t3 into table_size;
528
until table_size > max_table_size*2 end repeat;
530
call bug14210_fill_table()|
531
drop procedure bug14210_fill_table|
532
create table t4 like t3|
534
create procedure bug14210()
537
declare done int default 0;
538
declare c cursor for select * from t3;
539
declare continue handler for sqlstate '02000' set done = 1;
544
insert into t4 values (upper(a));
546
until done end repeat;
550
select count(*) from t4|
553
drop procedure bug14210|
554
set @@session.max_heap_table_size=default|
557
# BUG#7787: Stored procedures: improper warning for "grant execute" statement
562
CREATE DATABASE db_bug7787|
567
CREATE PROCEDURE p1()
568
SHOW INNODB STATUS; |
570
GRANT EXECUTE ON PROCEDURE p1 TO user_bug7787@localhost|
574
DROP DATABASE db_bug7787|
575
drop user user_bug7787@localhost|
579
# Bug#13575 SP funcs in select with distinct/group and order by can
582
create table t3 (f1 int, f2 varchar(3), primary key(f1)) engine=innodb|
583
insert into t3 values (1,'aaa'),(2,'bbb'),(3,'ccc')|
584
CREATE FUNCTION bug13575 ( p1 integer )
587
DECLARE v1 VARCHAR(10) DEFAULT null;
588
SELECT f2 INTO v1 FROM t3 WHERE f1 = p1;
591
select distinct f1, bug13575(f1) from t3 order by f1|
592
drop function bug13575|
597
# BUG#NNNN: New bug synopsis
600
#drop procedure if exists bugNNNN|
602
#create procedure bugNNNN...