summaryrefslogtreecommitdiff
path: root/mysql-test/r/sp-code.result
diff options
context:
space:
mode:
authorunknown <thek@adventure.(none)>2007-05-07 10:23:10 +0200
committerunknown <thek@adventure.(none)>2007-05-07 10:23:10 +0200
commit72569cc66d2a1d8edcc3e368213619f7ea855329 (patch)
tree2bff0cc91cb05a081ba21c79a104862facc39de5 /mysql-test/r/sp-code.result
parentc49e378ac4a690220d86c11ef40f2382848c6d30 (diff)
downloadmariadb-git-72569cc66d2a1d8edcc3e368213619f7ea855329.tar.gz
Bug#26977 exception handlers never hreturn
- In some cases, flow control optimization implemented in sp::optimize removes hreturn instructions, causing SQL exception handlers to: * never return * execute wrong logic - This patch overrides default short cut optimization on hreturn instructions to avoid this problem. mysql-test/r/sp-code.result: Added test case mysql-test/t/sp-code.test: Added test case sql/sp_head.cc: Override opt_mark to get correct execution paths without jump short cut optimization. sql/sp_head.h: Added override sp_instr_hreturn::opt_shortcut_jump so that jump short cuts aren't performed on hreturn instructions operating on handlers which are set to CONTINUE after interruption.
Diffstat (limited to 'mysql-test/r/sp-code.result')
-rw-r--r--mysql-test/r/sp-code.result113
1 files changed, 113 insertions, 0 deletions
diff --git a/mysql-test/r/sp-code.result b/mysql-test/r/sp-code.result
index 9d86a6bc08d..219f3c9b37a 100644
--- a/mysql-test/r/sp-code.result
+++ b/mysql-test/r/sp-code.result
@@ -620,4 +620,117 @@ SHOW PROCEDURE CODE p1;
Pos Instruction
0 stmt 2 "CREATE INDEX idx ON t1 (c1)"
DROP PROCEDURE p1;
+drop table if exists t1;
+drop procedure if exists proc_26977_broken;
+drop procedure if exists proc_26977_works;
+create table t1(a int unique);
+create procedure proc_26977_broken(v int)
+begin
+declare i int default 5;
+declare continue handler for sqlexception
+begin
+select 'caught something';
+retry:
+while i > 0 do
+begin
+set i = i - 1;
+select 'looping', i;
+end;
+end while retry;
+end;
+select 'do something';
+insert into t1 values (v);
+select 'do something again';
+insert into t1 values (v);
+end//
+create procedure proc_26977_works(v int)
+begin
+declare i int default 5;
+declare continue handler for sqlexception
+begin
+select 'caught something';
+retry:
+while i > 0 do
+begin
+set i = i - 1;
+select 'looping', i;
+end;
+end while retry;
+select 'optimizer: keep hreturn';
+end;
+select 'do something';
+insert into t1 values (v);
+select 'do something again';
+insert into t1 values (v);
+end//
+show procedure code proc_26977_broken;
+Pos Instruction
+0 set i@1 5
+1 hpush_jump 8 2 CONTINUE
+2 stmt 0 "select 'caught something'"
+3 jump_if_not 7(7) (i@1 > 0)
+4 set i@1 (i@1 - 1)
+5 stmt 0 "select 'looping', i"
+6 jump 3
+7 hreturn 2
+8 stmt 0 "select 'do something'"
+9 stmt 5 "insert into t1 values (v)"
+10 stmt 0 "select 'do something again'"
+11 stmt 5 "insert into t1 values (v)"
+12 hpop 1
+show procedure code proc_26977_works;
+Pos Instruction
+0 set i@1 5
+1 hpush_jump 9 2 CONTINUE
+2 stmt 0 "select 'caught something'"
+3 jump_if_not 7(7) (i@1 > 0)
+4 set i@1 (i@1 - 1)
+5 stmt 0 "select 'looping', i"
+6 jump 3
+7 stmt 0 "select 'optimizer: keep hreturn'"
+8 hreturn 2
+9 stmt 0 "select 'do something'"
+10 stmt 5 "insert into t1 values (v)"
+11 stmt 0 "select 'do something again'"
+12 stmt 5 "insert into t1 values (v)"
+13 hpop 1
+call proc_26977_broken(1);
+do something
+do something
+do something again
+do something again
+caught something
+caught something
+looping i
+looping 4
+looping i
+looping 3
+looping i
+looping 2
+looping i
+looping 1
+looping i
+looping 0
+call proc_26977_works(2);
+do something
+do something
+do something again
+do something again
+caught something
+caught something
+looping i
+looping 4
+looping i
+looping 3
+looping i
+looping 2
+looping i
+looping 1
+looping i
+looping 0
+optimizer: keep hreturn
+optimizer: keep hreturn
+drop table t1;
+drop procedure proc_26977_broken;
+drop procedure proc_26977_works;
End of 5.0 tests.