1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
SET @session_max_recursion_depth = @@SESSION.max_sp_recursion_depth;
'#--------------------FN_DYNVARS_099_01-------------------------#'
** Connecting test_con1 using username 'root' **
** Connection test_con1 **
SET @@session.max_sp_recursion_depth = 10;
SELECT @@session.max_sp_recursion_depth;
@@session.max_sp_recursion_depth
10
DROP PROCEDURE IF EXISTS sp_addRecords;
CREATE PROCEDURE sp_addRecords (IN var1 INT,IN var2 INT)
BEGIN
SELECT var1,var2;
IF var1 < var2 THEN
CALL sp_addRecords(var1+1,var2);
SELECT var1,var2;
END IF;
END //
CALL sp_addRecords(0,8);
var1 var2
0 8
var1 var2
1 8
var1 var2
2 8
var1 var2
3 8
var1 var2
4 8
var1 var2
5 8
var1 var2
6 8
var1 var2
7 8
var1 var2
8 8
var1 var2
7 8
var1 var2
6 8
var1 var2
5 8
var1 var2
4 8
var1 var2
3 8
var1 var2
2 8
var1 var2
1 8
var1 var2
0 8
'#--------------------FN_DYNVARS_099_02-------------------------#'
** Connecting test_con2 using username 'root' **
** Connection test_con2 **
SET @@session.max_sp_recursion_depth = 4;
SELECT @@session.max_sp_recursion_depth;
@@session.max_sp_recursion_depth
4
DROP PROCEDURE IF EXISTS sp_addRecords1;
CREATE PROCEDURE sp_addRecords1 (IN var1 INT,IN var2 INT)
BEGIN
SELECT var1,var2;
IF var1 < var2 THEN
CALL sp_addRecords1(var1+1,var2);
SELECT var1,var2;
END IF;
END //
CALL sp_addRecords1(0,4);
var1 var2
0 4
var1 var2
1 4
var1 var2
2 4
var1 var2
3 4
var1 var2
4 4
var1 var2
3 4
var1 var2
2 4
var1 var2
1 4
var1 var2
0 4
'#---------------------FN_DYNVARS_99_03----------------------#'
SET @@max_sp_recursion_depth = 10;
DROP PROCEDURE IF EXISTS sp_addRecords2;
CREATE PROCEDURE sp_addRecords2(IN var1 INT,IN var2 INT)
BEGIN
SELECT var1,var2;
IF var1 < var2 THEN
CALL sp_addRecords2(var1+1,var2);
SELECT var1,var2;
END IF;
END //
CALL sp_addRecords2(0,8);
var1 var2
0 8
var1 var2
1 8
var1 var2
2 8
var1 var2
3 8
var1 var2
4 8
var1 var2
5 8
var1 var2
6 8
var1 var2
7 8
var1 var2
8 8
var1 var2
7 8
var1 var2
6 8
var1 var2
5 8
var1 var2
4 8
var1 var2
3 8
var1 var2
2 8
var1 var2
1 8
var1 var2
0 8
'#---------------------FN_DYNVARS_99_04----------------------#'
SET @@max_sp_recursion_depth = 4;
DROP PROCEDURE IF EXISTS sp_addRecords3;
CREATE PROCEDURE sp_addRecords3 (IN var1 INT,IN var2 INT)
BEGIN
SELECT var1,var2;
IF var1 < var2 THEN
CALL sp_addRecords3(var1+1,var2);
SELECT var1,var2;
END IF;
END //
Expected error 'SP Recursion limit'
CALL sp_addRecords3(0,8);
var1 var2
0 8
var1 var2
1 8
var1 var2
2 8
var1 var2
3 8
var1 var2
4 8
ERROR HY000: Recursive limit 4 (as set by the max_sp_recursion_depth variable) was exceeded for routine sp_addRecords3
** Connection default **
** Disconnecting test_con1, test_con2 **
DROP PROCEDURE IF EXISTS sp_addRecords;
DROP PROCEDURE IF EXISTS sp_addRecords1;
DROP PROCEDURE IF EXISTS sp_addRecords2;
DROP PROCEDURE IF EXISTS sp_addRecords3;
SET @@SESSION.max_sp_recursion_depth = @session_max_recursion_depth;