1 drop procedure if exists empty;
2 drop procedure if exists code_sample;
3 create procedure empty()
6 show procedure code empty;
9 create function almost_empty()
12 show function code almost_empty;
15 drop function almost_empty;
16 create procedure code_sample(x int, out err int, out nulls int)
18 declare count int default 0;
21 declare c cursor for select name from t1;
22 declare exit handler for not found close c;
26 declare n varchar(20);
27 declare continue handler for sqlexception set err=1;
30 set nulls = nulls + 1;
32 set count = count + 1;
33 update t2 set idx = count where name=n;
38 select t.name, t.idx from t2 t order by idx asc;
40 show procedure code code_sample;
50 8 hpush_jump 11 5 CONTINUE
54 12 jump_if_not 15(17) isnull(n@4)
55 13 set nulls@2 (nulls@2 + 1)
57 15 set count@3 (count@3 + 1)
58 16 stmt 4 "update t2 set idx = count where name=n"
63 21 stmt 0 "select t.name, t.idx from t2 t order ..."
64 drop procedure code_sample;
65 drop procedure if exists sudoku_solve;
66 create procedure sudoku_solve(p_naive boolean, p_all boolean)
70 drop temporary table if exists sudoku_work, sudoku_schedule;
71 create temporary table sudoku_work
73 row smallint not null,
74 col smallint not null,
75 dig smallint not null,
77 key using btree (cnt),
78 key using btree (row),
79 key using btree (col),
80 unique key using hash (row,col)
82 create temporary table sudoku_schedule
84 idx int not null auto_increment primary key,
85 row smallint not null,
90 update sudoku_work set cnt = 0 where dig = 0;
94 insert into sudoku_schedule (row,col)
95 select row,col from sudoku_work where cnt is not null order by cnt desc;
97 declare v_scounter bigint default 0;
98 declare v_i smallint default 1;
99 declare v_dig smallint;
100 declare v_schedmax smallint;
101 select count(*) into v_schedmax from sudoku_schedule;
105 declare v_tcounter bigint default 0;
107 while v_i <= v_schedmax do
109 declare v_row, v_col smallint;
110 select row,col into v_row,v_col from sudoku_schedule where v_i = idx;
111 select dig into v_dig from sudoku_work
112 where v_row = row and v_col = col;
116 update sudoku_work set dig = 1
117 where v_row = row and v_col = col;
120 update sudoku_work set dig = 0
121 where v_row = row and v_col = col;
125 select v_scounter as 'Solutions';
129 set v_dig = v_dig + 1;
130 update sudoku_work set dig = v_dig
131 where v_row = row and v_col = col;
133 set v_tcounter = v_tcounter + 1;
134 if not sudoku_digit_ok(v_row, v_col, v_dig) then
140 select dig from sudoku_work;
141 select v_tcounter as 'Tests';
142 set v_scounter = v_scounter + 1;
143 if p_all and v_i > 0 then
151 drop temporary table sudoku_work, sudoku_schedule;
153 show procedure code sudoku_solve;
155 0 stmt 9 "drop temporary table if exists sudoku..."
156 1 stmt 1 "create temporary table sudoku_work ( ..."
157 2 stmt 1 "create temporary table sudoku_schedul..."
158 3 stmt 94 "call sudoku_init()"
159 4 jump_if_not 7(8) p_naive@0
160 5 stmt 4 "update sudoku_work set cnt = 0 where ..."
162 7 stmt 94 "call sudoku_count()"
163 8 stmt 6 "insert into sudoku_schedule (row,col)..."
167 12 set v_schedmax@5 NULL
168 13 stmt 0 "select count(*) into v_schedmax from ..."
169 14 set v_tcounter@6 0
170 15 jump_if_not 39(39) (v_i@3 <= v_schedmax@5)
173 18 stmt 0 "select row,col into v_row,v_col from ..."
174 19 stmt 0 "select dig into v_dig from sudoku_wor..."
175 20 set_case_expr (34) 0 v_dig@4
176 21 jump_if_not 25(34) (case_expr@0 = 0)
178 23 stmt 4 "update sudoku_work set dig = 1 where ..."
180 25 jump_if_not 32(34) (case_expr@0 = 9)
181 26 jump_if_not 30(34) (v_i@3 > 0)
182 27 stmt 4 "update sudoku_work set dig = 0 where ..."
183 28 set v_i@3 (v_i@3 - 1)
185 30 stmt 0 "select v_scounter as 'Solutions'"
187 32 set v_dig@4 (v_dig@4 + 1)
188 33 stmt 4 "update sudoku_work set dig = v_dig wh..."
189 34 set v_tcounter@6 (v_tcounter@6 + 1)
190 35 jump_if_not 37(37) (not(`sudoku_digit_ok`(v_row@7,v_col@8,v_dig@4)))
192 37 set v_i@3 (v_i@3 + 1)
194 39 stmt 0 "select dig from sudoku_work"
195 40 stmt 0 "select v_tcounter as 'Tests'"
196 41 set v_scounter@2 (v_scounter@2 + 1)
197 42 jump_if_not 45(14) (p_all@1 and (v_i@3 > 0))
198 43 set v_i@3 (v_i@3 - 1)
200 45 stmt 9 "drop temporary table sudoku_work, sud..."
201 drop procedure sudoku_solve;
202 DROP PROCEDURE IF EXISTS proc_19194_simple;
203 DROP PROCEDURE IF EXISTS proc_19194_searched;
204 DROP PROCEDURE IF EXISTS proc_19194_nested_1;
205 DROP PROCEDURE IF EXISTS proc_19194_nested_2;
206 DROP PROCEDURE IF EXISTS proc_19194_nested_3;
207 DROP PROCEDURE IF EXISTS proc_19194_nested_4;
208 CREATE PROCEDURE proc_19194_simple(i int)
210 DECLARE str CHAR(10);
212 WHEN 1 THEN SET str="1";
213 WHEN 2 THEN SET str="2";
214 WHEN 3 THEN SET str="3";
215 ELSE SET str="unknown";
219 CREATE PROCEDURE proc_19194_searched(i int)
221 DECLARE str CHAR(10);
223 WHEN i=1 THEN SET str="1";
224 WHEN i=2 THEN SET str="2";
225 WHEN i=3 THEN SET str="3";
226 ELSE SET str="unknown";
230 CREATE PROCEDURE proc_19194_nested_1(i int, j int)
232 DECLARE str_i CHAR(10);
233 DECLARE str_j CHAR(10);
235 WHEN 10 THEN SET str_i="10";
240 WHEN j=1 THEN SET str_j="1";
241 WHEN j=2 THEN SET str_j="2";
242 WHEN j=3 THEN SET str_j="3";
243 ELSE SET str_j="unknown";
247 WHEN 30 THEN SET str_i="30";
248 WHEN 40 THEN SET str_i="40";
249 ELSE SET str_i="unknown";
253 CREATE PROCEDURE proc_19194_nested_2(i int, j int)
255 DECLARE str_i CHAR(10);
256 DECLARE str_j CHAR(10);
258 WHEN i=10 THEN SET str_i="10";
263 WHEN 1 THEN SET str_j="1";
264 WHEN 2 THEN SET str_j="2";
265 WHEN 3 THEN SET str_j="3";
266 ELSE SET str_j="unknown";
270 WHEN i=30 THEN SET str_i="30";
271 WHEN i=40 THEN SET str_i="40";
272 ELSE SET str_i="unknown";
276 CREATE PROCEDURE proc_19194_nested_3(i int, j int)
278 DECLARE str_i CHAR(10);
279 DECLARE str_j CHAR(10);
281 WHEN 10 THEN SET str_i="10";
286 WHEN 1 THEN SET str_j="1";
287 WHEN 2 THEN SET str_j="2";
288 WHEN 3 THEN SET str_j="3";
289 ELSE SET str_j="unknown";
293 WHEN 30 THEN SET str_i="30";
294 WHEN 40 THEN SET str_i="40";
295 ELSE SET str_i="unknown";
299 CREATE PROCEDURE proc_19194_nested_4(i int, j int)
301 DECLARE str_i CHAR(10);
302 DECLARE str_j CHAR(10);
304 WHEN i=10 THEN SET str_i="10";
309 WHEN j=1 THEN SET str_j="1";
310 WHEN j=2 THEN SET str_j="2";
311 WHEN j=3 THEN SET str_j="3";
312 ELSE SET str_j="unknown";
316 WHEN i=30 THEN SET str_i="30";
317 WHEN i=40 THEN SET str_i="40";
318 ELSE SET str_i="unknown";
322 SHOW PROCEDURE CODE proc_19194_simple;
325 1 set_case_expr (12) 0 i@0
326 2 jump_if_not 5(12) (case_expr@0 = 1)
329 5 jump_if_not 8(12) (case_expr@0 = 2)
332 8 jump_if_not 11(12) (case_expr@0 = 3)
335 11 set str@1 'unknown'
336 12 stmt 0 "SELECT str"
337 SHOW PROCEDURE CODE proc_19194_searched;
340 1 jump_if_not 4(11) (i@0 = 1)
343 4 jump_if_not 7(11) (i@0 = 2)
346 7 jump_if_not 10(11) (i@0 = 3)
349 10 set str@1 'unknown'
350 11 stmt 0 "SELECT str"
351 SHOW PROCEDURE CODE proc_19194_nested_1;
355 2 set_case_expr (27) 0 i@0
356 3 jump_if_not 6(27) (case_expr@0 = 10)
359 6 jump_if_not 20(27) (case_expr@0 = 20)
361 8 jump_if_not 11(18) (j@1 = 1)
364 11 jump_if_not 14(18) (j@1 = 2)
367 14 jump_if_not 17(18) (j@1 = 3)
370 17 set str_j@3 'unknown'
371 18 stmt 0 "select "i was 20""
373 20 jump_if_not 23(27) (case_expr@0 = 30)
376 23 jump_if_not 26(27) (case_expr@0 = 40)
379 26 set str_i@2 'unknown'
380 27 stmt 0 "SELECT str_i, str_j"
381 SHOW PROCEDURE CODE proc_19194_nested_2;
385 2 jump_if_not 5(27) (i@0 = 10)
388 5 jump_if_not 20(27) (i@0 = 20)
390 7 set_case_expr (18) 0 j@1
391 8 jump_if_not 11(18) (case_expr@0 = 1)
394 11 jump_if_not 14(18) (case_expr@0 = 2)
397 14 jump_if_not 17(18) (case_expr@0 = 3)
400 17 set str_j@3 'unknown'
401 18 stmt 0 "select "i was 20""
403 20 jump_if_not 23(27) (i@0 = 30)
406 23 jump_if_not 26(27) (i@0 = 40)
409 26 set str_i@2 'unknown'
410 27 stmt 0 "SELECT str_i, str_j"
411 SHOW PROCEDURE CODE proc_19194_nested_3;
415 2 set_case_expr (28) 0 i@0
416 3 jump_if_not 6(28) (case_expr@0 = 10)
419 6 jump_if_not 21(28) (case_expr@0 = 20)
421 8 set_case_expr (19) 1 j@1
422 9 jump_if_not 12(19) (case_expr@1 = 1)
425 12 jump_if_not 15(19) (case_expr@1 = 2)
428 15 jump_if_not 18(19) (case_expr@1 = 3)
431 18 set str_j@3 'unknown'
432 19 stmt 0 "select "i was 20""
434 21 jump_if_not 24(28) (case_expr@0 = 30)
437 24 jump_if_not 27(28) (case_expr@0 = 40)
440 27 set str_i@2 'unknown'
441 28 stmt 0 "SELECT str_i, str_j"
442 SHOW PROCEDURE CODE proc_19194_nested_4;
446 2 jump_if_not 5(26) (i@0 = 10)
449 5 jump_if_not 19(26) (i@0 = 20)
451 7 jump_if_not 10(17) (j@1 = 1)
454 10 jump_if_not 13(17) (j@1 = 2)
457 13 jump_if_not 16(17) (j@1 = 3)
460 16 set str_j@3 'unknown'
461 17 stmt 0 "select "i was 20""
463 19 jump_if_not 22(26) (i@0 = 30)
466 22 jump_if_not 25(26) (i@0 = 40)
469 25 set str_i@2 'unknown'
470 26 stmt 0 "SELECT str_i, str_j"
471 CALL proc_19194_nested_1(10, 1);
474 CALL proc_19194_nested_1(25, 1);
477 CALL proc_19194_nested_1(20, 1);
482 CALL proc_19194_nested_1(20, 2);
487 CALL proc_19194_nested_1(20, 3);
492 CALL proc_19194_nested_1(20, 4);
497 CALL proc_19194_nested_1(30, 1);
500 CALL proc_19194_nested_1(40, 1);
503 CALL proc_19194_nested_1(0, 0);
506 CALL proc_19194_nested_2(10, 1);
509 CALL proc_19194_nested_2(25, 1);
512 CALL proc_19194_nested_2(20, 1);
517 CALL proc_19194_nested_2(20, 2);
522 CALL proc_19194_nested_2(20, 3);
527 CALL proc_19194_nested_2(20, 4);
532 CALL proc_19194_nested_2(30, 1);
535 CALL proc_19194_nested_2(40, 1);
538 CALL proc_19194_nested_2(0, 0);
541 CALL proc_19194_nested_3(10, 1);
544 CALL proc_19194_nested_3(25, 1);
547 CALL proc_19194_nested_3(20, 1);
552 CALL proc_19194_nested_3(20, 2);
557 CALL proc_19194_nested_3(20, 3);
562 CALL proc_19194_nested_3(20, 4);
567 CALL proc_19194_nested_3(30, 1);
570 CALL proc_19194_nested_3(40, 1);
573 CALL proc_19194_nested_3(0, 0);
576 CALL proc_19194_nested_4(10, 1);
579 CALL proc_19194_nested_4(25, 1);
582 CALL proc_19194_nested_4(20, 1);
587 CALL proc_19194_nested_4(20, 2);
592 CALL proc_19194_nested_4(20, 3);
597 CALL proc_19194_nested_4(20, 4);
602 CALL proc_19194_nested_4(30, 1);
605 CALL proc_19194_nested_4(40, 1);
608 CALL proc_19194_nested_4(0, 0);
611 DROP PROCEDURE proc_19194_simple;
612 DROP PROCEDURE proc_19194_searched;
613 DROP PROCEDURE proc_19194_nested_1;
614 DROP PROCEDURE proc_19194_nested_2;
615 DROP PROCEDURE proc_19194_nested_3;
616 DROP PROCEDURE proc_19194_nested_4;
617 DROP PROCEDURE IF EXISTS p1;
618 CREATE PROCEDURE p1() CREATE INDEX idx ON t1 (c1);
619 SHOW PROCEDURE CODE p1;
621 0 stmt 2 "CREATE INDEX idx ON t1 (c1)"
623 drop table if exists t1;
624 drop procedure if exists proc_26977_broken;
625 drop procedure if exists proc_26977_works;
626 create table t1(a int unique);
627 create procedure proc_26977_broken(v int)
629 declare i int default 5;
630 declare continue handler for sqlexception
632 select 'caught something';
641 select 'do something';
642 insert into t1 values (v);
643 select 'do something again';
644 insert into t1 values (v);
646 create procedure proc_26977_works(v int)
648 declare i int default 5;
649 declare continue handler for sqlexception
651 select 'caught something';
659 select 'optimizer: keep hreturn';
661 select 'do something';
662 insert into t1 values (v);
663 select 'do something again';
664 insert into t1 values (v);
666 show procedure code proc_26977_broken;
669 1 hpush_jump 8 2 CONTINUE
670 2 stmt 0 "select 'caught something'"
671 3 jump_if_not 7(7) (i@1 > 0)
673 5 stmt 0 "select 'looping', i"
676 8 stmt 0 "select 'do something'"
677 9 stmt 5 "insert into t1 values (v)"
678 10 stmt 0 "select 'do something again'"
679 11 stmt 5 "insert into t1 values (v)"
681 show procedure code proc_26977_works;
684 1 hpush_jump 9 2 CONTINUE
685 2 stmt 0 "select 'caught something'"
686 3 jump_if_not 7(7) (i@1 > 0)
688 5 stmt 0 "select 'looping', i"
690 7 stmt 0 "select 'optimizer: keep hreturn'"
692 9 stmt 0 "select 'do something'"
693 10 stmt 5 "insert into t1 values (v)"
694 11 stmt 0 "select 'do something again'"
695 12 stmt 5 "insert into t1 values (v)"
697 call proc_26977_broken(1);
714 call proc_26977_works(2);
731 optimizer: keep hreturn
732 optimizer: keep hreturn
734 drop procedure proc_26977_broken;
735 drop procedure proc_26977_works;
736 drop procedure if exists proc_33618_h;
737 drop procedure if exists proc_33618_c;
738 create procedure proc_33618_h(num int)
740 declare count1 int default '0';
741 declare vb varchar(30);
742 declare last_row int;
746 declare cur1 cursor for select `a` from t_33618;
747 declare continue handler for not found set last_row = 1;
753 declare exit handler for 1062 begin end;
755 if (last_row = 1) then
756 ## should generate a hpop instruction here
766 create procedure proc_33618_c(num int)
768 declare count1 int default '0';
769 declare vb varchar(30);
770 declare last_row int;
774 declare cur1 cursor for select `a` from t_33618;
775 declare continue handler for not found set last_row = 1;
781 declare cur2 cursor for select `b` from t_33618;
783 if (last_row = 1) then
784 ## should generate a cpop instruction here
794 show procedure code proc_33618_h;
798 2 set last_row@3 NULL
799 3 jump_if_not 24(24) (num@0 >= 1)
800 4 set num@0 (num@0 - 1)
802 6 hpush_jump 9 4 CONTINUE
807 11 hpush_jump 13 4 EXIT
809 13 cfetch cur1@0 vb@2
810 14 jump_if_not 17(17) (last_row@3 = 1)
814 18 jump_if_not 11(19) (last_row@3 = 1)
819 show procedure code proc_33618_c;
823 2 set last_row@3 NULL
824 3 jump_if_not 23(23) (num@0 >= 1)
825 4 set num@0 (num@0 - 1)
827 6 hpush_jump 9 4 CONTINUE
833 12 cfetch cur1@0 vb@2
834 13 jump_if_not 16(16) (last_row@3 = 1)
838 17 jump_if_not 11(18) (last_row@3 = 1)
843 drop procedure proc_33618_h;
844 drop procedure proc_33618_c;
845 drop procedure if exists p_20906_a;
846 drop procedure if exists p_20906_b;
847 create procedure p_20906_a() SET @a=@a+1, @b=@b+1;
848 show procedure code p_20906_a;
850 0 stmt 31 "SET @a=@a+1"
851 1 stmt 31 "SET @b=@b+1"
858 create procedure p_20906_b() SET @a=@a+1, @b=@b+1, @c=@c+1;
859 show procedure code p_20906_b;
861 0 stmt 31 "SET @a=@a+1"
862 1 stmt 31 "SET @b=@b+1"
863 2 stmt 31 "SET @c=@c+1"
871 drop procedure p_20906_a;
872 drop procedure p_20906_b;
874 CREATE PROCEDURE p1()
876 DECLARE dummy int default 0;
882 SHOW PROCEDURE CODE p1;
885 1 set_case_expr (6) 0 12
886 2 jump_if_not 5(6) (case_expr@0 = 12)
892 # Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
895 CREATE FUNCTION testf_bug11763507() RETURNS INT
900 CREATE PROCEDURE testp_bug11763507()
902 SELECT "PROCEDURE testp_bug11763507";
905 SHOW FUNCTION CODE testf_bug11763507;
908 SHOW FUNCTION CODE TESTF_bug11763507;
911 SHOW PROCEDURE CODE testp_bug11763507;
913 0 stmt 0 "SELECT "PROCEDURE testp_bug11763507""
914 SHOW PROCEDURE CODE TESTP_bug11763507;
916 0 stmt 0 "SELECT "PROCEDURE testp_bug11763507""
917 DROP PROCEDURE testp_bug11763507;
918 DROP FUNCTION testf_bug11763507;
919 #END OF BUG#11763507 test.