~vkolesnikov/pbxt/pbxt-07-diskfull

« back to all changes in this revision

Viewing changes to pbxt/mysql-test-update/mysql-test/t/sp_trans.test

  • Committer: paul-mccullagh
  • Date: 2006-10-23 09:14:04 UTC
  • Revision ID: paul-mccullagh-918861e03d351978a9541168a96e58cc826734ee
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# tests that require InnoDB...
 
3
#
 
4
 
 
5
-- source include/have_innodb.inc
 
6
 
 
7
--disable_warnings
 
8
drop table if exists t1, t2, t3;
 
9
--enable_warnings
 
10
 
 
11
delimiter |;
 
12
 
 
13
#
 
14
# BUG#8850: Truncate table in a stored procedure locks the tables
 
15
#
 
16
--disable_warnings
 
17
drop procedure if exists bug8850|
 
18
--enable_warnings
 
19
create table t1 (a int) engine=innodb|
 
20
create procedure bug8850()
 
21
begin
 
22
  truncate table t1; insert t1 values (1); rollback;
 
23
end|
 
24
 
 
25
set autocommit=0|
 
26
insert t1 values (2)|
 
27
call bug8850()|
 
28
commit|
 
29
select * from t1|
 
30
 
 
31
call bug8850()|
 
32
set autocommit=1|
 
33
select * from t1|
 
34
drop table t1|
 
35
drop procedure bug8850|
 
36
 
 
37
 
 
38
#
 
39
# BUG#10015: Crash in InnoDB if stored routines are used
 
40
# (crash happens in auto-commit mode)
 
41
#
 
42
--disable_warnings
 
43
drop function if exists bug10015_1|
 
44
drop function if exists bug10015_2|
 
45
drop function if exists bug10015_3|
 
46
drop function if exists bug10015_4|
 
47
drop function if exists bug10015_5|
 
48
drop function if exists bug10015_6|
 
49
drop function if exists bug10015_7|
 
50
drop procedure if exists bug10015_8|
 
51
--enable_warnings
 
52
create table t1 (id int) engine=innodb|
 
53
create table t2 (id int primary key, j int) engine=innodb|
 
54
insert into t1 values (1),(2),(3)|
 
55
create function bug10015_1() returns int return (select count(*) from t1)|
 
56
select *, bug10015_1() from t1|
 
57
drop function bug10015_1|
 
58
# Test couple of a bit more complex cases
 
59
create function bug10015_2() returns int 
 
60
  begin
 
61
    declare i, s int;
 
62
    set i:= (select min(id) from t1);
 
63
    set s:= (select max(id) from t1);
 
64
    return (s - i);
 
65
  end|
 
66
select *, bug10015_2() from t1|
 
67
drop function bug10015_2|
 
68
create function bug10015_3() returns int 
 
69
  return (select max(a.id - b.id) from t1 as a, t1 as b where a.id >= b.id)|
 
70
select *, bug10015_3() from t1|
 
71
drop function bug10015_3|
 
72
create function bug10015_4(i int) returns int 
 
73
  begin
 
74
    declare m int;
 
75
    set m:= (select max(id) from t2);
 
76
    insert into t2 values (i, m);
 
77
    return m;
 
78
  end|
 
79
select *, bug10015_4(id) from t1|
 
80
select * from t2|
 
81
drop function bug10015_4|
 
82
# Now let us test how statement rollback works
 
83
# This function will cause the whole stmt to be rolled back,
 
84
# there should not be any traces left.
 
85
create function bug10015_5(i int) returns int
 
86
  begin
 
87
    if (i = 5) then
 
88
      insert into t2 values (1, 0);
 
89
    end if;
 
90
    return i;
 
91
  end|
 
92
--error 1062
 
93
insert into t1 values (bug10015_5(4)), (bug10015_5(5))|
 
94
select * from t1|
 
95
drop function bug10015_5|
 
96
# Thanks to error-handler this function should not cause rollback
 
97
# of statement calling it. But insert statement in it should be 
 
98
# rolled back completely and don't leave any traces in t2.
 
99
# Unfortunately we can't implement such behavior in 5.0, so it
 
100
# is something to be fixed in later 5.* releases (TODO).
 
101
create function bug10015_6(i int) returns int
 
102
  begin
 
103
    declare continue handler for sqlexception set @error_in_func:= 1;
 
104
    if (i = 5) then
 
105
      insert into t2 values (4, 0), (1, 0);
 
106
    end if;
 
107
    return i;
 
108
  end|
 
109
set @error_in_func:= 0|
 
110
insert into t1 values (bug10015_6(5)), (bug10015_6(6))|
 
111
select @error_in_func|
 
112
select * from t1|
 
113
select * from t2|
 
114
drop function bug10015_6|
 
115
# Let us test that we don't allow any statements causing transaction
 
116
# commit in stored functions (we test only most interesting cases here).
 
117
# Cases which can be caught at creation time:
 
118
--error 1422
 
119
create function bug10015_7() returns int
 
120
  begin
 
121
    alter table t1 add k int;
 
122
    return 1;
 
123
  end|
 
124
--error 1422
 
125
create function bug10015_7() returns int
 
126
  begin
 
127
    start transaction;
 
128
    return 1;
 
129
  end|
 
130
--error 1422
 
131
create function bug10015_7() returns int
 
132
  begin
 
133
    drop table t1;
 
134
    return 1;
 
135
  end|
 
136
# It should be OK to drop temporary table.
 
137
create function bug10015_7() returns int
 
138
  begin
 
139
    drop temporary table t1;
 
140
    return 1;
 
141
  end|
 
142
drop function bug10015_7|
 
143
--error 1422
 
144
create function bug10015_7() returns int
 
145
  begin
 
146
    commit;
 
147
    return 1;
 
148
  end|
 
149
# Now let us test cases which we can catch only at run-time:
 
150
create function bug10015_7() returns int
 
151
  begin
 
152
    call bug10015_8();
 
153
    return 1;
 
154
  end|
 
155
create procedure bug10015_8() alter table t1 add k int|
 
156
--error 1422
 
157
select *, bug10015_7() from t1|
 
158
drop procedure bug10015_8|
 
159
create procedure bug10015_8() start transaction|
 
160
--error 1422
 
161
select *, bug10015_7() from t1|
 
162
drop procedure bug10015_8|
 
163
# Again it is OK to drop temporary table
 
164
# We are surpressing warnings since they are not essential
 
165
create procedure bug10015_8() drop temporary table if exists t1_temp|
 
166
--disable_warnings
 
167
select *, bug10015_7() from t1|
 
168
--enable_warnings
 
169
drop procedure bug10015_8|
 
170
create procedure bug10015_8() commit|
 
171
--error 1422
 
172
select *, bug10015_7() from t1|
 
173
drop procedure bug10015_8|
 
174
drop function bug10015_7|
 
175
drop table t1, t2|
 
176
 
 
177
 
 
178
#
 
179
# BUG#13825 "Triggers: crash if release savepoint".
 
180
# Also general test for handling of savepoints in stored routines.
 
181
#
 
182
# According to SQL standard we should establish new savepoint
 
183
# level before executing stored function/trigger and destroy 
 
184
# this savepoint level after execution. Stored procedures by
 
185
# default should be executed using the same savepoint level
 
186
# as their caller (to execute stored procedure using new 
 
187
# savepoint level one should explicitly specify NEW SAVEPOINT
 
188
# LEVEL clause in procedure creation statement which MySQL
 
189
# does not support yet).
 
190
--disable_warnings
 
191
drop function if exists bug13825_0|
 
192
drop function if exists bug13825_1|
 
193
drop function if exists bug13825_2|
 
194
drop function if exists bug13825_3|
 
195
drop function if exists bug13825_4|
 
196
drop function if exists bug13825_5|
 
197
drop procedure if exists bug13825_0|
 
198
drop procedure if exists bug13825_1|
 
199
drop procedure if exists bug13825_2|
 
200
drop table if exists t1|
 
201
--enable_warnings
 
202
create table t1 (i int) engine=innodb|
 
203
create table t2 (i int) engine=innodb|
 
204
create function bug13825_0() returns int
 
205
begin
 
206
  rollback to savepoint x;
 
207
  return 1;
 
208
end|
 
209
create function bug13825_1() returns int
 
210
begin
 
211
  release savepoint x;
 
212
  return 1;
 
213
end|
 
214
create function bug13825_2() returns int
 
215
begin
 
216
  insert into t1 values (2);
 
217
  savepoint x;
 
218
  insert into t1 values (3);
 
219
  rollback to savepoint x;
 
220
  insert into t1 values (4);
 
221
  return 1;
 
222
end|
 
223
create procedure bug13825_0()
 
224
begin
 
225
  rollback to savepoint x;
 
226
end|
 
227
create procedure bug13825_1()
 
228
begin
 
229
  release savepoint x;
 
230
end|
 
231
create procedure bug13825_2()
 
232
begin
 
233
  savepoint x;
 
234
end|
 
235
insert into t2 values (1)|
 
236
create trigger t2_bi before insert on t2 for each row
 
237
  rollback to savepoint x|
 
238
create trigger t2_bu before update on t2 for each row
 
239
  release savepoint x|
 
240
create trigger t2_bd before delete on t2 for each row
 
241
begin
 
242
  insert into t1 values (2);
 
243
  savepoint x;
 
244
  insert into t1 values (3);
 
245
  rollback to savepoint x;
 
246
  insert into t1 values (4);
 
247
end|
 
248
create function bug13825_3(rb int) returns int
 
249
begin
 
250
  insert into t1 values(1);
 
251
  savepoint x;
 
252
  insert into t1 values(2);
 
253
  if rb then
 
254
    rollback to savepoint x;
 
255
  end if;
 
256
  insert into t1 values(3);
 
257
  return rb;
 
258
end|
 
259
create function bug13825_4() returns int
 
260
begin
 
261
  savepoint x;
 
262
  insert into t1 values(2);
 
263
  rollback to savepoint x;
 
264
  return 0;
 
265
end|
 
266
create function bug13825_5(p int) returns int
 
267
begin
 
268
  savepoint x;
 
269
  insert into t2 values(p);
 
270
  rollback to savepoint x;
 
271
  insert into t2 values(p+1);
 
272
  return p;
 
273
end|
 
274
set autocommit= 0|
 
275
# Test of savepoint level handling for stored functions and triggers
 
276
begin |
 
277
insert into t1 values (1)|
 
278
savepoint x|
 
279
--error ER_SP_DOES_NOT_EXIST
 
280
set @a:= bug13825_0()|
 
281
--error ER_SP_DOES_NOT_EXIST
 
282
insert into t2 values (2)|
 
283
--error ER_SP_DOES_NOT_EXIST
 
284
set @a:= bug13825_1()|
 
285
--error ER_SP_DOES_NOT_EXIST
 
286
update t2 set i = 2|
 
287
set @a:= bug13825_2()|
 
288
select * from t1|
 
289
rollback to savepoint x|
 
290
select * from t1|
 
291
delete from t2|
 
292
select * from t1|
 
293
rollback to savepoint x|
 
294
select * from t1|
 
295
# Of course savepoints set in function should not be visible from its caller
 
296
release savepoint x|
 
297
set @a:= bug13825_2()|
 
298
select * from t1|
 
299
--error ER_SP_DOES_NOT_EXIST
 
300
rollback to savepoint x|
 
301
delete from t1|
 
302
commit|
 
303
# Test of savepoint level handling for stored procedures
 
304
begin|
 
305
insert into t1 values (5)|
 
306
savepoint x|
 
307
insert into t1 values (6)|
 
308
call bug13825_0()|
 
309
select * from t1|
 
310
call bug13825_1()|
 
311
--error ER_SP_DOES_NOT_EXIST
 
312
rollback to savepoint x|
 
313
savepoint x|
 
314
insert into t1 values (7)|
 
315
call bug13825_2()|
 
316
rollback to savepoint x|
 
317
select * from t1|
 
318
delete from t1|
 
319
commit|
 
320
set autocommit= 1|
 
321
# Let us test that savepoints work inside of functions
 
322
# even in auto-commit mode
 
323
select bug13825_3(0)|
 
324
select * from t1|
 
325
delete from t1|
 
326
select bug13825_3(1)|
 
327
select * from t1|
 
328
delete from t1|
 
329
# Curious case: rolling back to savepoint which is set by first
 
330
# statement in function should not rollback whole transaction.
 
331
set autocommit= 0|
 
332
begin|
 
333
insert into t1 values (1)|
 
334
set @a:= bug13825_4()|
 
335
select * from t1|
 
336
delete from t1|
 
337
commit|
 
338
set autocommit= 1|
 
339
# Other curious case: savepoint in the middle of statement
 
340
drop table t2|
 
341
create table t2 (i int) engine=innodb|
 
342
insert into t1 values (1), (bug13825_5(2)), (3)|
 
343
select * from t1|
 
344
select * from t2|
 
345
# Cleanup
 
346
drop function bug13825_0|
 
347
drop function bug13825_1|
 
348
drop function bug13825_2|
 
349
drop function bug13825_3|
 
350
drop function bug13825_4|
 
351
drop function bug13825_5|
 
352
drop procedure bug13825_0|
 
353
drop procedure bug13825_1|
 
354
drop procedure bug13825_2|
 
355
drop table t1, t2|
 
356
 
 
357
 
 
358
#
 
359
# BUG#14840: CONTINUE handler problem
 
360
#
 
361
--disable_warnings
 
362
drop table if exists t3|
 
363
drop procedure if exists bug14840_1|
 
364
drop procedure if exists bug14840_2|
 
365
--enable_warnings
 
366
 
 
367
create table t3
 
368
(
 
369
  x int,
 
370
  y int,
 
371
  primary key (x)
 
372
) engine=InnoDB|
 
373
 
 
374
# This used to hang the client since the insert returned with an
 
375
# error status (left over from the update) even though it succeeded,
 
376
# which caused the execution to end at that point.
 
377
create procedure bug14840_1()
 
378
begin
 
379
  declare err int default 0;
 
380
  declare continue handler for sqlexception
 
381
    set err = err + 1;
 
382
 
 
383
  start transaction;
 
384
  update t3 set x = 1, y = 42 where x = 2;
 
385
  insert into t3 values (3, 4711);
 
386
  if err > 0 then
 
387
    rollback;
 
388
  else
 
389
    commit;
 
390
  end if;
 
391
  select * from t3;
 
392
end|
 
393
 
 
394
# A simpler (non-transactional) case: insert at select should be done
 
395
create procedure bug14840_2()
 
396
begin
 
397
  declare err int default 0;
 
398
  declare continue handler for sqlexception
 
399
    begin
 
400
      set err = err + 1;
 
401
      select err as 'Ping';
 
402
    end;
 
403
 
 
404
  update t3 set x = 1, y = 42 where x = 2;
 
405
  update t3 set x = 1, y = 42 where x = 2;
 
406
  insert into t3 values (3, 4711);
 
407
  select * from t3;
 
408
end|
 
409
 
 
410
insert into t3 values (1, 3), (2, 5)|
 
411
call bug14840_1()|
 
412
 
 
413
delete from t3|
 
414
insert into t3 values (1, 3), (2, 5)|
 
415
call bug14840_2()|
 
416
 
 
417
drop procedure bug14840_1|
 
418
drop procedure bug14840_2|
 
419
drop table t3|
 
420
 
 
421
 
 
422
#
 
423
# BUG#10656: Stored Procedure - Create index and Truncate table command error
 
424
#
 
425
--disable_warnings
 
426
drop procedure if exists bug10656_create_index|
 
427
drop procedure if exists bug10656_myjoin|
 
428
drop procedure if exists bug10656_truncate_table|
 
429
--enable_warnings
 
430
 
 
431
CREATE TABLE t3 (
 
432
  `ID` int(11) default NULL,
 
433
  `txt` char(5) default NULL
 
434
) ENGINE=InnoDB DEFAULT CHARSET=latin1|
 
435
 
 
436
INSERT INTO t3 (`ID`,`txt`) VALUES
 
437
 (1,'a'), (2,'b'), (3,'c'), (4,'d')|
 
438
 
 
439
CREATE TABLE t4 (
 
440
  `ID` int(11) default NULL,
 
441
  `txt` char(5) default NULL
 
442
) ENGINE=InnoDB DEFAULT CHARSET=latin1|
 
443
 
 
444
INSERT INTO t4 (`ID`,`txt`) VALUES
 
445
 (1,'a'), (2,'b'), (3,'c'), (4,'d')|
 
446
 
 
447
create procedure bug10656_create_index()
 
448
begin
 
449
  create index bug10656_my_index on t3 (ID);
 
450
end|
 
451
call bug10656_create_index()|
 
452
 
 
453
create procedure bug10656_myjoin()
 
454
begin
 
455
  update t3, t4 set t3.txt = t4.txt where t3.id = t4.id;
 
456
end|
 
457
call bug10656_myjoin()|
 
458
 
 
459
create procedure bug10656_truncate_table()
 
460
begin
 
461
  truncate table t3;
 
462
end|
 
463
call bug10656_truncate_table()|
 
464
 
 
465
 
 
466
drop procedure bug10656_create_index|
 
467
drop procedure bug10656_myjoin|
 
468
drop procedure bug10656_truncate_table|
 
469
drop table t3, t4|
 
470
 
 
471
#
 
472
# BUG#3448
 
473
#
 
474
--disable_warnings
 
475
create table t3 (
 
476
  a int primary key,
 
477
  ach char(1)
 
478
) engine = innodb|
 
479
 
 
480
create table t4 (
 
481
  b int  primary key,
 
482
  bch char(1)
 
483
) engine = innodb|
 
484
--enable_warnings
 
485
 
 
486
insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')|
 
487
insert into t4 values (1 , 'bCh1' )|
 
488
 
 
489
--disable_warnings
 
490
drop procedure if exists bug3448|
 
491
--enable_warnings
 
492
create procedure bug3448()
 
493
  select * from t3 inner join t4 on t3.a = t4.b|
 
494
 
 
495
select * from t3 inner join t4 on t3.a = t4.b|
 
496
call bug3448()|
 
497
call bug3448()|
 
498
 
 
499
drop procedure bug3448|
 
500
drop table t3, t4|
 
501
 
 
502
#
 
503
# BUG#14210: "Simple query with > operator on large table gives server
 
504
# crash"
 
505
# Check that cursors work in case when HEAP tables are converted to
 
506
# MyISAM
 
507
#
 
508
--disable_warnings
 
509
drop procedure if exists bug14210|
 
510
--enable_warnings
 
511
set @@session.max_heap_table_size=16384|
 
512
select @@session.max_heap_table_size|
 
513
# To trigger the memory corruption the original table must be InnoDB.
 
514
# No harm if it's not, so don't warn if the suite is run with --skip-innodb
 
515
--disable_warnings
 
516
create table t3 (a char(255)) engine=InnoDB|
 
517
--enable_warnings
 
518
create procedure bug14210_fill_table()
 
519
begin
 
520
  declare table_size, max_table_size int default 0;
 
521
  select @@session.max_heap_table_size into max_table_size;
 
522
  delete from t3;
 
523
  insert into t3 (a) values (repeat('a', 255));
 
524
  repeat
 
525
    insert into t3 select a from t3;
 
526
    select count(*)*255 from t3 into table_size;
 
527
  until table_size > max_table_size*2 end repeat;
 
528
end|
 
529
call bug14210_fill_table()|
 
530
drop procedure bug14210_fill_table|
 
531
create table t4 like t3|
 
532
 
 
533
create procedure bug14210()
 
534
begin
 
535
  declare a char(255);
 
536
  declare done int default 0;
 
537
  declare c cursor for select * from t3;
 
538
  declare continue handler for sqlstate '02000' set done = 1;
 
539
  open c;
 
540
  repeat
 
541
    fetch c into a;
 
542
    if not done then
 
543
       insert into t4 values (upper(a));
 
544
    end if;
 
545
  until done end repeat;
 
546
  close c;
 
547
end|
 
548
call bug14210()|
 
549
select count(*) from t4|
 
550
 
 
551
drop table t3, t4|
 
552
drop procedure bug14210|
 
553
set @@session.max_heap_table_size=default|
 
554
 
 
555
#
 
556
# BUG#7787: Stored procedures: improper warning for "grant execute" statement
 
557
#
 
558
 
 
559
# Prepare.
 
560
 
 
561
CREATE DATABASE db_bug7787|
 
562
use db_bug7787|
 
563
 
 
564
# Test.
 
565
 
 
566
CREATE PROCEDURE p1()
 
567
  SHOW INNODB STATUS; |
 
568
 
 
569
GRANT EXECUTE ON PROCEDURE p1 TO user_bug7787@localhost|
 
570
 
 
571
# Cleanup.
 
572
 
 
573
DROP DATABASE db_bug7787|
 
574
drop user user_bug7787@localhost|
 
575
use test|
 
576
 
 
577
#
 
578
# Bug#13575 SP funcs in select with distinct/group and order by can
 
579
#           produce bad data
 
580
#
 
581
create table t3 (f1 int, f2 varchar(3), primary key(f1)) engine=innodb|
 
582
insert into t3 values (1,'aaa'),(2,'bbb'),(3,'ccc')|
 
583
CREATE FUNCTION bug13575 ( p1 integer ) 
 
584
returns varchar(3) 
 
585
BEGIN 
 
586
DECLARE v1 VARCHAR(10) DEFAULT null;
 
587
SELECT f2 INTO v1 FROM t3 WHERE f1 = p1; 
 
588
RETURN v1;
 
589
END|
 
590
select distinct f1, bug13575(f1) from t3 order by f1|
 
591
drop function bug13575|
 
592
drop table t3|
 
593
 
 
594
 
 
595
#
 
596
# BUG#NNNN: New bug synopsis
 
597
#
 
598
#--disable_warnings
 
599
#drop procedure if exists bugNNNN|
 
600
#--enable_warnings
 
601
#create procedure bugNNNN...
 
602
 
 
603
delimiter ;|