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

« back to all changes in this revision

Viewing changes to mysql-test/t/sp-fib.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
# Fibonacci, for recursion test. (Yet Another Numerical series :)
 
2
# Split from main.sp due to problems reported in Bug#15866
 
3
 
 
4
--disable_warnings
 
5
drop table if exists t3;
 
6
--enable_warnings
 
7
create table t3 ( f bigint unsigned not null );
 
8
 
 
9
# We deliberately do it the awkward way, fetching the last two
 
10
# values from the table, in order to exercise various statements
 
11
# and table accesses at each turn.
 
12
--disable_warnings
 
13
drop procedure if exists fib;
 
14
--enable_warnings
 
15
 
 
16
# Now for multiple statements...
 
17
delimiter |;
 
18
 
 
19
create procedure fib(n int unsigned)
 
20
begin
 
21
  if n > 1 then
 
22
    begin
 
23
      declare x, y bigint unsigned;
 
24
      declare c cursor for select f from t3 order by f desc limit 2;
 
25
      open c;
 
26
      fetch c into y;
 
27
      fetch c into x;
 
28
      insert into t3 values (x+y);
 
29
      call fib(n-1);
 
30
      ## Close the cursor AFTER the recursion to ensure that the stack
 
31
      ## frame is somewhat intact.
 
32
      close c;
 
33
    end;
 
34
  end if;
 
35
end|
 
36
 
 
37
# Enable recursion
 
38
set @@max_sp_recursion_depth= 20|
 
39
 
 
40
insert into t3 values (0), (1)|
 
41
 
 
42
# The small number of recursion levels is intentional.
 
43
# We need to avoid
 
44
# Bug#15866 main.sp fails (thread stack limit
 
45
#           insufficient for recursive call "fib(20)")
 
46
# which affects some platforms.
 
47
call fib(4)|
 
48
 
 
49
select * from t3 order by f asc|
 
50
 
 
51
drop table t3|
 
52
drop procedure fib|
 
53
set @@max_sp_recursion_depth= 0|
 
54