📄 sp-code.result
字号:
drop procedure if exists empty;drop procedure if exists code_sample;create procedure empty()beginend;show procedure code empty;Pos Instructiondrop procedure empty;create function almost_empty()returns intreturn 0;show function code almost_empty;Pos Instruction0 freturn 3 0drop function almost_empty;create procedure code_sample(x int, out err int, out nulls int)begindeclare count int default 0;set nulls = 0;begindeclare c cursor for select name from t1;declare exit handler for not found close c;open c;loopbegindeclare n varchar(20);declare continue handler for sqlexception set err=1;fetch c into n;if isnull(n) thenset nulls = nulls + 1;elseset count = count + 1;update t2 set idx = count where name=n;end if;end;end loop;end;select t.name, t.idx from t2 t order by idx asc;end//show procedure code code_sample;Pos Instruction0 set count@3 01 set nulls@2 02 cpush c@03 hpush_jump 6 4 EXIT4 cclose c@05 hreturn 0 196 copen c@07 set n@4 NULL8 hpush_jump 11 5 CONTINUE9 set err@1 110 hreturn 511 cfetch c@0 n@412 jump_if_not 15(17) isnull(n@4)13 set nulls@2 (nulls@2 + 1)14 jump 1715 set count@3 (count@3 + 1)16 stmt 4 "update t2 set idx = count where name=n"17 hpop 118 jump 719 hpop 120 cpop 121 stmt 0 "select t.name, t.idx from t2 t order ..."drop procedure code_sample;drop procedure if exists sudoku_solve;create procedure sudoku_solve(p_naive boolean, p_all boolean)deterministicmodifies sql databegindrop temporary table if exists sudoku_work, sudoku_schedule;create temporary table sudoku_work(row smallint not null,col smallint not null,dig smallint not null,cnt smallint,key using btree (cnt),key using btree (row),key using btree (col),unique key using hash (row,col));create temporary table sudoku_schedule(idx int not null auto_increment primary key,row smallint not null,col smallint not null);call sudoku_init();if p_naive thenupdate sudoku_work set cnt = 0 where dig = 0;elsecall sudoku_count();end if;insert into sudoku_schedule (row,col)select row,col from sudoku_work where cnt is not null order by cnt desc;begindeclare v_scounter bigint default 0;declare v_i smallint default 1;declare v_dig smallint;declare v_schedmax smallint;select count(*) into v_schedmax from sudoku_schedule;more: loopbegindeclare v_tcounter bigint default 0;sched:while v_i <= v_schedmax dobegindeclare v_row, v_col smallint;select row,col into v_row,v_col from sudoku_schedule where v_i = idx;select dig into v_dig from sudoku_workwhere v_row = row and v_col = col;case v_digwhen 0 thenset v_dig = 1;update sudoku_work set dig = 1where v_row = row and v_col = col;when 9 thenif v_i > 0 thenupdate sudoku_work set dig = 0where v_row = row and v_col = col;set v_i = v_i - 1;iterate sched;elseselect v_scounter as 'Solutions';leave more;end if;elseset v_dig = v_dig + 1;update sudoku_work set dig = v_digwhere v_row = row and v_col = col;end case;set v_tcounter = v_tcounter + 1;if not sudoku_digit_ok(v_row, v_col, v_dig) theniterate sched;end if;set v_i = v_i + 1;end;end while sched;select dig from sudoku_work;select v_tcounter as 'Tests';set v_scounter = v_scounter + 1;if p_all and v_i > 0 thenset v_i = v_i - 1;elseleave more;end if;end;end loop more;end;drop temporary table sudoku_work, sudoku_schedule;end//show procedure code sudoku_solve;Pos Instruction0 stmt 9 "drop temporary table if exists sudoku..."1 stmt 1 "create temporary table sudoku_work ( ..."2 stmt 1 "create temporary table sudoku_schedul..."3 stmt 95 "call sudoku_init()"4 jump_if_not 7(8) p_naive@05 stmt 4 "update sudoku_work set cnt = 0 where ..."6 jump 87 stmt 95 "call sudoku_count()"8 stmt 6 "insert into sudoku_schedule (row,col)..."9 set v_scounter@2 010 set v_i@3 111 set v_dig@4 NULL12 set v_schedmax@5 NULL13 stmt 0 "select count(*) into v_schedmax from ..."14 set v_tcounter@6 015 jump_if_not 39(39) (v_i@3 <= v_schedmax@5)16 set v_row@7 NULL17 set v_col@8 NULL18 stmt 0 "select row,col into v_row,v_col from ..."19 stmt 0 "select dig into v_dig from sudoku_wor..."20 set_case_expr (34) 0 v_dig@421 jump_if_not 25(34) (case_expr@0 = 0)22 set v_dig@4 123 stmt 4 "update sudoku_work set dig = 1 where ..."24 jump 3425 jump_if_not 32(34) (case_expr@0 = 9)26 jump_if_not 30(34) (v_i@3 > 0)27 stmt 4 "update sudoku_work set dig = 0 where ..."28 set v_i@3 (v_i@3 - 1)29 jump 1530 stmt 0 "select v_scounter as 'Solutions'"31 jump 4532 set v_dig@4 (v_dig@4 + 1)33 stmt 4 "update sudoku_work set dig = v_dig wh..."34 set v_tcounter@6 (v_tcounter@6 + 1)35 jump_if_not 37(37) (not(`sudoku_digit_ok`(v_row@7,v_col@8,v_dig@4)))36 jump 1537 set v_i@3 (v_i@3 + 1)38 jump 1539 stmt 0 "select dig from sudoku_work"40 stmt 0 "select v_tcounter as 'Tests'"41 set v_scounter@2 (v_scounter@2 + 1)42 jump_if_not 45(14) (p_all@1 and (v_i@3 > 0))43 set v_i@3 (v_i@3 - 1)44 jump 1445 stmt 9 "drop temporary table sudoku_work, sud..."drop procedure sudoku_solve;DROP PROCEDURE IF EXISTS proc_19194_simple;DROP PROCEDURE IF EXISTS proc_19194_searched;DROP PROCEDURE IF EXISTS proc_19194_nested_1;DROP PROCEDURE IF EXISTS proc_19194_nested_2;DROP PROCEDURE IF EXISTS proc_19194_nested_3;DROP PROCEDURE IF EXISTS proc_19194_nested_4;CREATE PROCEDURE proc_19194_simple(i int)BEGINDECLARE str CHAR(10);CASE iWHEN 1 THEN SET str="1";WHEN 2 THEN SET str="2";WHEN 3 THEN SET str="3";ELSE SET str="unknown";END CASE;SELECT str;END|CREATE PROCEDURE proc_19194_searched(i int)BEGINDECLARE str CHAR(10);CASEWHEN i=1 THEN SET str="1";WHEN i=2 THEN SET str="2";WHEN i=3 THEN SET str="3";ELSE SET str="unknown";END CASE;SELECT str;END|CREATE PROCEDURE proc_19194_nested_1(i int, j int)BEGINDECLARE str_i CHAR(10);DECLARE str_j CHAR(10);CASE iWHEN 10 THEN SET str_i="10";WHEN 20 THENBEGINset str_i="20";CASEWHEN j=1 THEN SET str_j="1";WHEN j=2 THEN SET str_j="2";WHEN j=3 THEN SET str_j="3";ELSE SET str_j="unknown";END CASE;select "i was 20";END;WHEN 30 THEN SET str_i="30";WHEN 40 THEN SET str_i="40";ELSE SET str_i="unknown";END CASE;SELECT str_i, str_j;END|CREATE PROCEDURE proc_19194_nested_2(i int, j int)BEGINDECLARE str_i CHAR(10);DECLARE str_j CHAR(10);CASEWHEN i=10 THEN SET str_i="10";WHEN i=20 THENBEGINset str_i="20";CASE jWHEN 1 THEN SET str_j="1";WHEN 2 THEN SET str_j="2";WHEN 3 THEN SET str_j="3";ELSE SET str_j="unknown";END CASE;select "i was 20";END;WHEN i=30 THEN SET str_i="30";WHEN i=40 THEN SET str_i="40";ELSE SET str_i="unknown";END CASE;SELECT str_i, str_j;END|CREATE PROCEDURE proc_19194_nested_3(i int, j int)BEGINDECLARE str_i CHAR(10);DECLARE str_j CHAR(10);CASE iWHEN 10 THEN SET str_i="10";WHEN 20 THENBEGINset str_i="20";CASE jWHEN 1 THEN SET str_j="1";WHEN 2 THEN SET str_j="2";WHEN 3 THEN SET str_j="3";ELSE SET str_j="unknown";END CASE;select "i was 20";END;WHEN 30 THEN SET str_i="30";WHEN 40 THEN SET str_i="40";ELSE SET str_i="unknown";END CASE;SELECT str_i, str_j;END|CREATE PROCEDURE proc_19194_nested_4(i int, j int)BEGINDECLARE str_i CHAR(10);DECLARE str_j CHAR(10);CASEWHEN i=10 THEN SET str_i="10";WHEN i=20 THENBEGINset str_i="20";CASEWHEN j=1 THEN SET str_j="1";WHEN j=2 THEN SET str_j="2";WHEN j=3 THEN SET str_j="3";ELSE SET str_j="unknown";END CASE;select "i was 20";END;WHEN i=30 THEN SET str_i="30";WHEN i=40 THEN SET str_i="40";ELSE SET str_i="unknown";END CASE;SELECT str_i, str_j;END|SHOW PROCEDURE CODE proc_19194_simple;Pos Instruction0 set str@1 NULL1 set_case_expr (12) 0 i@02 jump_if_not 5(12) (case_expr@0 = 1)3 set str@1 _latin1'1'4 jump 125 jump_if_not 8(12) (case_expr@0 = 2)6 set str@1 _latin1'2'7 jump 128 jump_if_not 11(12) (case_expr@0 = 3)9 set str@1 _latin1'3'10 jump 1211 set str@1 _latin1'unknown'12 stmt 0 "SELECT str"SHOW PROCEDURE CODE proc_19194_searched;Pos Instruction0 set str@1 NULL1 jump_if_not 4(11) (i@0 = 1)2 set str@1 _latin1'1'3 jump 114 jump_if_not 7(11) (i@0 = 2)5 set str@1 _latin1'2'6 jump 117 jump_if_not 10(11) (i@0 = 3)8 set str@1 _latin1'3'9 jump 1110 set str@1 _latin1'unknown'11 stmt 0 "SELECT str"SHOW PROCEDURE CODE proc_19194_nested_1;Pos Instruction0 set str_i@2 NULL1 set str_j@3 NULL2 set_case_expr (27) 0 i@03 jump_if_not 6(27) (case_expr@0 = 10)4 set str_i@2 _latin1'10'5 jump 276 jump_if_not 20(27) (case_expr@0 = 20)7 set str_i@2 _latin1'20'8 jump_if_not 11(18) (j@1 = 1)9 set str_j@3 _latin1'1'10 jump 1811 jump_if_not 14(18) (j@1 = 2)12 set str_j@3 _latin1'2'13 jump 1814 jump_if_not 17(18) (j@1 = 3)15 set str_j@3 _latin1'3'16 jump 18
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -