summaryrefslogtreecommitdiff
path: root/mysql-test/main/sp-bugs.test
blob: 18fe14dc8bc9cd871e60ebc9f5d604260e92dc55 (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
# Test file for stored procedure bugfixes

--echo #
--echo # Bug #47412: Valgrind warnings / user can read uninitialized memory
--echo # using SP variables
--echo #

CREATE SCHEMA testdb;
USE testdb;
DELIMITER |;
CREATE FUNCTION f2 () RETURNS INTEGER
BEGIN
   DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1;
   RETURN f_not_exists () ;
END|
CREATE PROCEDURE p3 ( arg1 VARCHAR(32) )
BEGIN
   CALL p_not_exists ( );
END|
DELIMITER ;|
--echo # should not return valgrind warnings
--error ER_SP_DOES_NOT_EXIST
CALL p3 ( f2 () );

DROP SCHEMA testdb;

CREATE SCHEMA testdb;
USE testdb;
DELIMITER |;
CREATE FUNCTION f2 () RETURNS INTEGER
BEGIN
   DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1;
   RETURN f_not_exists () ;
END|
CREATE PROCEDURE p3 ( arg2 INTEGER )
BEGIN
   CALL p_not_exists ( );
END|
DELIMITER ;|
--echo # should not return valgrind warnings
--error ER_SP_DOES_NOT_EXIST
CALL p3 ( f2 () );

DROP SCHEMA testdb;

CREATE SCHEMA testdb;
USE testdb;
DELIMITER |;
CREATE FUNCTION f2 () RETURNS INTEGER
BEGIN
   DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1;
   RETURN f_not_exists () ;
END|
DELIMITER ;|
--echo # should not return valgrind warnings
SELECT f2 ();

DROP SCHEMA testdb;

USE test;

--echo #
--echo # Bug#50423: Crash on second call of a procedure dropping a trigger
--echo #

--disable_warnings
DROP TABLE IF EXISTS t1;
DROP TRIGGER IF EXISTS tr1;
DROP PROCEDURE IF EXISTS p1;
--enable_warnings

CREATE TABLE t1 (f1 INTEGER);
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
CREATE PROCEDURE p1 () DROP TRIGGER tr1;

CALL p1 ();
--error ER_TRG_DOES_NOT_EXIST
CALL p1 ();

DROP TABLE t1;
DROP PROCEDURE p1;

--echo #
--echo # Bug#54375: Error in stored procedure leaves connection
--echo # in different default schema
--echo #

--disable_warnings
SET @@SQL_MODE = 'STRICT_ALL_TABLES';
DROP DATABASE IF EXISTS db1;
CREATE DATABASE db1;
USE db1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c1 int NOT NULL PRIMARY KEY);
INSERT INTO t1 VALUES (1);
DELIMITER $$;
CREATE FUNCTION f1 (
	some_value int
)
RETURNS smallint
DETERMINISTIC
BEGIN
	INSERT INTO t1 SET c1 = some_value;
        RETURN(LAST_INSERT_ID());
END$$
DELIMITER ;$$
DROP DATABASE IF EXISTS db2;
CREATE DATABASE db2;
--enable_warnings
USE db2;
SELECT DATABASE();
--error ER_DUP_ENTRY
SELECT db1.f1(1);
SELECT DATABASE();
USE test;
DROP FUNCTION db1.f1;
DROP TABLE db1.t1;
DROP DATABASE db1;
DROP DATABASE db2;
USE test;

--echo #
--echo # Bug#13105873:valgrind warning:possible crash in foreign 
--echo # key handling on subsequent create table if not exists 
--echo #

--disable_warnings
DROP DATABASE IF EXISTS testdb;
--enable_warnings
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE t1 (id1 INT PRIMARY KEY);
DELIMITER $;
CREATE PROCEDURE `p1`()
BEGIN
    CREATE TABLE IF NOT EXISTS t2(id INT PRIMARY KEY,
    CONSTRAINT FK FOREIGN KEY (id) REFERENCES t1( id1 ));
END$
DELIMITER ;$
CALL p1();
--echo # below stmt should not return valgrind warnings
CALL p1(); 
DROP DATABASE testdb;
USE test;

--echo #
--echo # End of 5.1 tests
--echo #

--echo #
--echo # BUG#13489996 valgrind:conditional jump or move depends on
--echo # uninitialised values-field_blob
--echo #

CREATE FUNCTION sf() RETURNS BLOB RETURN "";
SELECT sf();
DROP FUNCTION sf;

--echo #
--echo # Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
--echo #
SET @@SQL_MODE = '';
DELIMITER $;
CREATE FUNCTION testf_bug11763507() RETURNS INT
BEGIN
    RETURN 0;
END
$

CREATE PROCEDURE testp_bug11763507()
BEGIN
    SELECT "PROCEDURE testp_bug11763507";
END
$

DELIMITER ;$

# STORED FUNCTIONS
SELECT testf_bug11763507();
SELECT TESTF_bug11763507();

--replace_column 5 # 6 #
SHOW FUNCTION STATUS LIKE  'testf_bug11763507';
--replace_column 5 # 6 #
SHOW FUNCTION STATUS WHERE NAME='testf_bug11763507';
--replace_column 5 # 6 #
SHOW FUNCTION STATUS LIKE  'TESTF_bug11763507';
--replace_column 5 # 6 #
SHOW FUNCTION STATUS WHERE NAME='TESTF_bug11763507';

SHOW CREATE FUNCTION testf_bug11763507;
SHOW CREATE FUNCTION TESTF_bug11763507;

# STORED PROCEDURE
CALL testp_bug11763507();
CALL TESTP_bug11763507();

--replace_column 5 # 6 #
SHOW PROCEDURE STATUS LIKE  'testp_bug11763507';
--replace_column 5 # 6 #
SHOW PROCEDURE STATUS WHERE NAME='testp_bug11763507';
--replace_column 5 # 6 #
SHOW PROCEDURE STATUS LIKE  'TESTP_bug11763507';
--replace_column 5 # 6 #
SHOW PROCEDURE STATUS WHERE NAME='TESTP_bug11763507';

SHOW CREATE PROCEDURE testp_bug11763507;
SHOW CREATE PROCEDURE TESTP_bug11763507;

# INFORMATION SCHEMA 
SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'testf_bug11763507';
SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'TESTF_bug11763507';

SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='testf_bug11763507';
SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='TESTF_bug11763507';

DROP PROCEDURE testp_bug11763507;
DROP FUNCTION testf_bug11763507;

--echo #END OF BUG#11763507 test.

--echo #
--echo # MDEV-5531 double call procedure in one session
--echo #

CREATE TABLE  `t1` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `create_ts` int(10) unsigned DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

DELIMITER $$;

CREATE PROCEDURE test_5531 (IN step TINYINT(1))
BEGIN
  DECLARE counts INT DEFAULT 0;
  DECLARE cur1 CURSOR FOR

  SELECT ct.id
  FROM (SELECT NULL) AS z
  JOIN (
    SELECT id
    FROM `t1`
    LIMIT 10
  ) AS ct
  JOIN (SELECT NULL) AS x ON(
    EXISTS(
      SELECT 1
      FROM `t1`
      WHERE id=ct.id
      LIMIT 1
    )
  );

  IF step=1 THEN
    TRUNCATE t1;
    REPEAT
      INSERT INTO `t1`
      (create_ts) VALUES
      (UNIX_TIMESTAMP());

      SET counts=counts+1;
    UNTIL counts>150 END REPEAT;

    SET max_sp_recursion_depth=1;

    CALL test_5531(2);
    SET max_sp_recursion_depth=2;
    CALL test_5531(2);
  ELSEIF step=2 THEN
    OPEN cur1; CLOSE cur1;
  END IF;
END $$
DELIMITER ;$$
CALL test_5531(1);
DROP PROCEDURE test_5531;
DROP TABLE t1;

#
# MDEV-6601 Assertion `!thd->in_active_multi_stmt_transa ction() || thd->in_multi_stmt_transaction_mode()' failed on executing a stored procedure with commit
#
delimiter |;
create procedure sp() begin
  commit;
end|
delimiter ;|
start transaction;
call sp();
drop procedure sp;

--echo #
--echo # MDEV-11146 SP variables of the SET data type erroneously allow values with comma
--echo #

DELIMITER $$;
--error ER_ILLEGAL_VALUE_FOR_TYPE
CREATE PROCEDURE p1()
BEGIN
  DECLARE a SET('a','b','c','a,b');
  SET a='a,b';
  SELECT a, a+0;
END;
$$
DELIMITER ;$$


--echo #
--echo # Start of 10.3 tests
--echo #

--echo #
--echo # MDEV-16117 SP with a single FOR statement creates but further fails to load
--echo #

DELIMITER $$;
CREATE PROCEDURE p1()
  FOR i IN 1..10 DO
      set @x = 5;
  END FOR;
$$
DELIMITER ;$$
CALL p1;
SELECT body FROM mysql.proc WHERE db='test' AND specific_name='p1';
DROP PROCEDURE p1;


DELIMITER $$;
CREATE PROCEDURE p1() WITH t1 AS (SELECT 1) SELECT 1;
$$
DELIMITER ;$$
CALL p1;
SELECT body FROM mysql.proc WHERE db='test' AND specific_name='p1';
DROP PROCEDURE p1;


DELIMITER $$;
CREATE PROCEDURE p1() VALUES (1);
$$
DELIMITER ;$$
CALL p1;
SELECT body FROM mysql.proc WHERE db='test' AND specific_name='p1';
DROP PROCEDURE p1;


DELIMITER $$;
CREATE FUNCTION f1() RETURNS INT
  FOR i IN 1..10 DO
    RETURN 1;
  END FOR;
$$
DELIMITER ;$$
SELECT f1();
SELECT body FROM mysql.proc WHERE db='test' AND specific_name='f1';
DROP FUNCTION f1;

--echo #
--echo # End of 10.2 tests
--echo #

--echo #
--echo # MDEV-25501 routine_definition in information_schema.routines loses tablename if it starts with an _ and is not backticked
--echo #
create table _t1 (a int);
create procedure p1() select * from _t1;
show create procedure p1;
select routine_definition from information_schema.routines where routine_schema=database() and specific_name='p1';
select body, body_utf8 from mysql.proc where name='p1';
drop procedure p1;
drop table _t1;

--echo #
--echo # End of 10.3 tests
--echo #

--echo #
--echo #  MDEV-22001: Server crashes in st_select_lex_unit::exclude_level upon execution of SP
--echo #
--delimiter $
BEGIN NOT ATOMIC DECLARE a INT DEFAULT 0 IN ( SELECT 1 ) OR 2 ; END $
BEGIN NOT ATOMIC DECLARE a INT DEFAULT 0 IN ( SELECT 1 ) OR (SELECT 2) ; END $
--delimiter ;

--error ER_NO_SUCH_THREAD
KILL  (('x' IN ( SELECT 1)) MOD 44);

--echo #
--echo # End of 10.4 tests
--echo #