summaryrefslogtreecommitdiff
path: root/mysql-test/main/sp_stress_case.test
blob: 1b5bd8991a982ef75e65e401a93354485b2b55f2 (plain)
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
#
# Bug#19194 (Right recursion in parser for CASE causes excessive stack
#   usage, limitation)
#

--disable_warnings
DROP PROCEDURE IF EXISTS proc_19194_codegen;
DROP PROCEDURE IF EXISTS bug_19194_simple;
DROP PROCEDURE IF EXISTS bug_19194_searched;
--enable_warnings

delimiter |;

CREATE PROCEDURE proc_19194_codegen(
  IN proc_name VARCHAR(50),
  IN count INTEGER,
  IN simple INTEGER,
  OUT body MEDIUMTEXT)
BEGIN
  DECLARE code MEDIUMTEXT;
  DECLARE i INT DEFAULT 1;

  SET code = concat("CREATE PROCEDURE ", proc_name, "(i INT)\n");
  SET code = concat(code, "BEGIN\n");
  SET code = concat(code, "  DECLARE str CHAR(10);\n");

  IF (simple)
  THEN
    SET code = concat(code, "  CASE i\n");
  ELSE
    SET code = concat(code, "  CASE\n");
  END IF;

  WHILE (i <= count)
  DO
    IF (simple)
    THEN
      SET code = concat(code, "    WHEN ", i, " THEN SET str=\"", i, "\";\n");
    ELSE
      SET code = concat(code, "    WHEN i=", i, " THEN SET str=\"", i, "\";\n");
    END IF;

    SET i = i + 1;
  END WHILE;

  SET code = concat(code, "    ELSE SET str=\"unknown\";\n");
  SET code = concat(code, "  END CASE;\n");
  SET code = concat(code, "  SELECT str;\n");

  SET code = concat(code, "END\n");

  SET body = code;
END|

delimiter ;|

set @body="";
call proc_19194_codegen("test_simple", 10, 1, @body);
select @body;
call proc_19194_codegen("test_searched", 10, 0, @body);
select @body;

--disable_query_log
call proc_19194_codegen("bug_19194_simple", 5000, 1, @body);
let $proc_body = `select @body`;
eval $proc_body;
call proc_19194_codegen("bug_19194_searched", 5000, 1, @body);
let $proc_body = `select @body`;
eval $proc_body;
--enable_query_log

CALL bug_19194_simple(1);
CALL bug_19194_simple(2);
CALL bug_19194_simple(1000);
CALL bug_19194_simple(4998);
CALL bug_19194_simple(4999);
CALL bug_19194_simple(9999);

CALL bug_19194_searched(1);
CALL bug_19194_searched(2);
CALL bug_19194_searched(1000);
CALL bug_19194_searched(4998);
CALL bug_19194_searched(4999);
CALL bug_19194_searched(9999);

DROP PROCEDURE proc_19194_codegen;
DROP PROCEDURE bug_19194_simple;
DROP PROCEDURE bug_19194_searched;