2
# Test the debugging feature "show procedure/function code <name>"
5
-- source include/is_debug_build.inc
8
drop procedure if exists empty;
9
drop procedure if exists code_sample;
12
create procedure empty()
15
show procedure code empty;
18
create function almost_empty()
21
show function code almost_empty;
22
drop function almost_empty;
25
create procedure code_sample(x int, out err int, out nulls int)
27
declare count int default 0;
31
declare c cursor for select name from t1;
32
declare exit handler for not found close c;
37
declare n varchar(20);
38
declare continue handler for sqlexception set err=1;
42
set nulls = nulls + 1;
44
set count = count + 1;
45
update t2 set idx = count where name=n;
50
select t.name, t.idx from t2 t order by idx asc;
53
show procedure code code_sample;
54
drop procedure code_sample;
58
# BUG#15737: Stored procedure optimizer bug with LEAVE
60
# This is a much more extensive test case than is strictly needed,
61
# but it was kept as is for two reasons:
62
# - The bug occurs under some quite special circumstances, so it
63
# wasn't trivial to create a smaller test,
64
# - There's some value in having another more complex code sample
65
# in this test file. This might catch future code generation bugs
66
# that doesn't show in behaviour in any obvious way.
69
drop procedure if exists sudoku_solve;
73
create procedure sudoku_solve(p_naive boolean, p_all boolean)
77
drop temporary table if exists sudoku_work, sudoku_schedule;
79
create temporary table sudoku_work
81
row smallint not null,
82
col smallint not null,
83
dig smallint not null,
85
key using btree (cnt),
86
key using btree (row),
87
key using btree (col),
88
unique key using hash (row,col)
91
create temporary table sudoku_schedule
93
idx int not null auto_increment primary key,
94
row smallint not null,
101
update sudoku_work set cnt = 0 where dig = 0;
105
insert into sudoku_schedule (row,col)
106
select row,col from sudoku_work where cnt is not null order by cnt desc;
109
declare v_scounter bigint default 0;
110
declare v_i smallint default 1;
111
declare v_dig smallint;
112
declare v_schedmax smallint;
114
select count(*) into v_schedmax from sudoku_schedule;
119
declare v_tcounter bigint default 0;
122
while v_i <= v_schedmax do
124
declare v_row, v_col smallint;
126
select row,col into v_row,v_col from sudoku_schedule where v_i = idx;
128
select dig into v_dig from sudoku_work
129
where v_row = row and v_col = col;
134
update sudoku_work set dig = 1
135
where v_row = row and v_col = col;
138
update sudoku_work set dig = 0
139
where v_row = row and v_col = col;
143
select v_scounter as 'Solutions';
147
set v_dig = v_dig + 1;
148
update sudoku_work set dig = v_dig
149
where v_row = row and v_col = col;
152
set v_tcounter = v_tcounter + 1;
153
if not sudoku_digit_ok(v_row, v_col, v_dig) then
160
select dig from sudoku_work;
161
select v_tcounter as 'Tests';
162
set v_scounter = v_scounter + 1;
164
if p_all and v_i > 0 then
173
drop temporary table sudoku_work, sudoku_schedule;
177
# The interestings parts are where the code for the two "leave" are:
179
#| 26 | jump_if_not 30 (v_i@3 > 0) |
181
#| 30 | stmt 0 "select v_scounter as 'Solutions'" |
184
#| 42 | jump_if_not 45 (p_all@1 and (v_i@3 > 0)) |
185
#| 43 | set v_i@3 (v_i@3 - 1) |
187
#| 45 | stmt 9 "drop temporary table sudoku_work, sud..." |
188
#+-----+-----------------------------------------------------------------------+
189
# The bug appeared at position 42 (with the wrong destination).
190
show procedure code sudoku_solve;
192
drop procedure sudoku_solve;
196
# Bug#19207: Final parenthesis omitted for CREATE INDEX in Stored
199
# Wrong criteria was used to distinguish the case when there was no
200
# lookahead performed in the parser. Bug affected only statements
201
# ending in one-character token without any optional tail, like CREATE
205
DROP PROCEDURE IF EXISTS p1;
208
CREATE PROCEDURE p1() CREATE INDEX idx ON t1 (c1);
209
SHOW PROCEDURE CODE p1;
214
--echo End of 5.0 tests.