summaryrefslogtreecommitdiff
path: root/mysql-test/t/parser_stack.test
blob: 3330ef418330016b035d4c89dd024310f5570eb9 (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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# Copyright (C) 2008 Sun Microsystems, Inc
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#
# These tests are designed to cause an internal parser stack overflow,
# and trigger my_yyoverflow().
#

use test;

SELECT
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
1
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
;

prepare stmt from
"
SELECT
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
1
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
"
;

execute stmt;

--disable_warnings
drop view if exists view_overflow;
--enable_warnings

CREATE VIEW view_overflow AS
SELECT
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
1
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
;

SELECT * from view_overflow;

drop view view_overflow;

--disable_warnings
drop procedure if exists proc_overflow;
--enable_warnings

delimiter $$;

CREATE PROCEDURE proc_overflow()
BEGIN

  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN

  select 1;
  select 2;
  select 3;

  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;

END $$

delimiter ;$$

call proc_overflow();

drop procedure proc_overflow;

--disable_warnings
drop function if exists func_overflow;
--enable_warnings

delimiter $$;

create function func_overflow() returns int
BEGIN
  DECLARE x int default 0;

  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN

  SET x=x+1;
  SET x=x+2;
  SET x=x+3;

  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;

  return x;
END $$

delimiter ;$$

select func_overflow();

drop function func_overflow;

--disable_warnings
drop table if exists table_overflow;
--enable_warnings

create table table_overflow(a int, b int);

delimiter $$;

create trigger trigger_overflow before insert on table_overflow
for each row
BEGIN

  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN

  SET NEW.b := NEW.a;
  SET NEW.b := NEW.b + 1;
  SET NEW.b := NEW.b + 2;
  SET NEW.b := NEW.b + 3;

  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;

END $$

delimiter ;$$

insert into table_overflow set a=10;
insert into table_overflow set a=20;
select * from table_overflow;

drop table table_overflow;

--disable_warnings
drop procedure if exists proc_35577;
--enable_warnings

delimiter $$;

CREATE PROCEDURE proc_35577()
BEGIN
  DECLARE z_done INT DEFAULT 0;
  DECLARE t_done VARCHAR(5000);
  outer_loop: LOOP
    IF t_done=1  THEN
      LEAVE outer_loop;
    END IF;

    inner_block:BEGIN
      DECLARE z_done INT DEFAULT  0;
      SET z_done = 0;
      inner_loop: LOOP
        IF z_done=1  THEN
          LEAVE inner_loop;
        END IF;
        IF (t_done = 'a') THEN
          IF (t_done <> 0) THEN
            IF ( t_done > 0) THEN
              IF (t_done = 'a') THEN
                SET t_done = 'a';
              ELSEIF (t_done = 'a') THEN
                SET t_done = 'a';
              ELSEIF(t_done = 'a') THEN
                SET t_done = 'a';
              ELSEIF(t_done = 'a') THEN
                SET t_done = 'a';
              ELSEIF(t_done = 'a') THEN
                SET t_done = 'a';
              ELSEIF(t_done = 'a') THEN
                SET t_done = 'a';
              ELSEIF(t_done = 'a') THEN
                SET t_done = 'a';
              ELSEIF(t_done = 'a') THEN
                SET t_done = 'a';
              END IF;
            END IF;
          END IF;
        END IF;
      END LOOP inner_loop;
    END inner_block;
  END LOOP outer_loop;
END $$

delimiter ;$$

drop procedure proc_35577;

#
# Bug#37269 (parser crash when creating stored procedure)
#

--disable_warnings
drop procedure if exists p_37269;
--enable_warnings

delimiter $$;

create procedure p_37269()
begin
  declare done int default 0;
  declare varb int default 0;
  declare vara int default 0;

  repeat
    select now();
  until done end repeat;
  while varb do
    select now();
    begin
      select now();
      repeat
        select now();
      until done end repeat;
      if vara then 
        select now();
        repeat
          select now();
          loop
            select now();
          end loop;
          repeat
            select now();
            label1: while varb do
              select now();
            end while label1;
            if vara then 
              select now();
              repeat
                select now();
              until done end repeat;
              begin
                select now();
                while varb do
                  select now();
                  label1: while varb do
                    select now();
                  end while label1;
                  if vara then 
                    select now();
                    while varb do
                      select now();
                      loop
                        select now();
                      end loop;
                      repeat
                        select now();
                        loop
                          select now();
                          while varb do
                            select now();
                          end while;
                          repeat
                            select now();
                            label1: loop
                              select now();
                              if vara then 
                                select now();
                              end if;
                            end loop label1;
                          until done end repeat;
                        end loop;
                      until done end repeat;
                    end while;
                  end if;
                end while;
              end;
            end if;
          until done end repeat;
        until done end repeat;
      end if;
    end;
  end while;
end $$

delimiter ;$$

drop procedure p_37269;

#
# Bug#37228 (Sever crashes when creating stored procedure with more than
#            10 IF/ELSEIF)
#

--disable_warnings
drop procedure if exists p_37228;
--enable_warnings

delimiter $$;

create procedure p_37228 ()
BEGIN
  DECLARE v INT DEFAULT 123;

  IF (v > 1) THEN SET v = 1; 
  ELSEIF (v < 10) THEN SET v = 10;
  ELSEIF (v < 11) THEN SET v = 11;
  ELSEIF (v < 12) THEN SET v = 12;
  ELSEIF (v < 13) THEN SET v = 13;
  ELSEIF (v < 14) THEN SET v = 14;
  ELSEIF (v < 15) THEN SET v = 15;
  ELSEIF (v < 16) THEN SET v = 16;
  ELSEIF (v < 17) THEN SET v = 17;
  ELSEIF (v < 18) THEN SET v = 18;
  ELSEIF (v < 19) THEN SET v = 19;
  ELSEIF (v < 20) THEN SET v = 20;
  ELSEIF (v < 21) THEN SET v = 21;
  ELSEIF (v < 22) THEN SET v = 22;
  ELSEIF (v < 23) THEN SET v = 23;
  ELSEIF (v < 24) THEN SET v = 24;
  ELSEIF (v < 25) THEN SET v = 25;
  ELSEIF (v < 26) THEN SET v = 26;
  ELSEIF (v < 27) THEN SET v = 27;
  ELSEIF (v < 28) THEN SET v = 28;
  ELSEIF (v < 29) THEN SET v = 29;
  ELSEIF (v < 30) THEN SET v = 30;
  ELSEIF (v < 31) THEN SET v = 31;
  ELSEIF (v < 32) THEN SET v = 32;
  ELSEIF (v < 33) THEN SET v = 33;
  ELSEIF (v < 34) THEN SET v = 34;
  ELSEIF (v < 35) THEN SET v = 35;
  ELSEIF (v < 36) THEN SET v = 36;
  ELSEIF (v < 37) THEN SET v = 37;
  ELSEIF (v < 38) THEN SET v = 38;
  ELSEIF (v < 39) THEN SET v = 39;
  END IF;
END $$

delimiter ;$$

drop procedure p_37228;