summaryrefslogtreecommitdiff
path: root/mysql-test/main/sp-destruct.test
blob: 12299fa230bcd20d288ddbef9b2237264937c1fe (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
#
# Destructive stored procedure tests
#
# We do horrible things to the mysql.proc table here, so any unexpected
# failures here might leave it in an undetermined state.
#
# In the case of trouble you might want to skip this.
#

-- source include/not_embedded.inc

# Supress warnings written to the log file
call mtr.add_suppression("Column count of mysql.proc is wrong. Expected 21, found 20. The table is probably corrupted");
call mtr.add_suppression("Stored routine .test...bug14233_[123].: invalid value in column mysql.proc");

# Backup proc table
let $MYSQLD_DATADIR= `select @@datadir`;
flush table mysql.proc;
--copy_file $MYSQLD_DATADIR/mysql/proc.frm $MYSQLTEST_VARDIR/tmp/proc.frm
--copy_file $MYSQLD_DATADIR/mysql/proc.MAD $MYSQLTEST_VARDIR/tmp/proc.MAD
--copy_file $MYSQLD_DATADIR/mysql/proc.MAI $MYSQLTEST_VARDIR/tmp/proc.MAI

use test;

--disable_warnings
drop procedure if exists bug14233;
drop function if exists bug14233;
drop table if exists t1;
drop view if exists v1;
--enable_warnings

create procedure bug14233()
  set @x = 42;

create function bug14233_f() returns int
  return 42;

create table t1 (id int);
create trigger t1_ai after insert on t1 for each row call bug14233();

# Unsupported tampering with the mysql.proc definition
alter table mysql.proc drop security_type;
--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
call bug14233();
--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
create view v1 as select bug14233_f();
--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
insert into t1 values (0);
--error ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
show procedure status;

flush table mysql.proc;

# Thrashing the .frm file
--remove_file $MYSQLD_DATADIR/mysql/proc.frm
--write_file $MYSQLD_DATADIR/mysql/proc.frm
saljdfa
EOF
--replace_result $MYSQLTEST_VARDIR . master-data// '' '\\' '/'
--error ER_NOT_FORM_FILE
call bug14233();
--replace_result $MYSQLTEST_VARDIR . master-data// '' '\\' '/'
--error ER_NOT_FORM_FILE
create view v1 as select bug14233_f();
--replace_result $MYSQLTEST_VARDIR . master-data// '' '\\' '/'
--error ER_NOT_FORM_FILE
insert into t1 values (0);

flush table mysql.proc;

# Drop the mysql.proc table
--remove_file $MYSQLD_DATADIR/mysql/proc.frm
--remove_file $MYSQLD_DATADIR/mysql/proc.MAD
--remove_file $MYSQLD_DATADIR/mysql/proc.MAI
--error ER_NO_SUCH_TABLE
call bug14233();
--error ER_NO_SUCH_TABLE
create view v1 as select bug14233_f();
--error ER_NO_SUCH_TABLE
insert into t1 values (0);

# Restore mysql.proc
--copy_file $MYSQLTEST_VARDIR/tmp/proc.frm $MYSQLD_DATADIR/mysql/proc.frm
--copy_file $MYSQLTEST_VARDIR/tmp/proc.MAD $MYSQLD_DATADIR/mysql/proc.MAD
--copy_file $MYSQLTEST_VARDIR/tmp/proc.MAI $MYSQLD_DATADIR/mysql/proc.MAI 
--remove_file $MYSQLTEST_VARDIR/tmp/proc.frm
--remove_file $MYSQLTEST_VARDIR/tmp/proc.MAD
--remove_file $MYSQLTEST_VARDIR/tmp/proc.MAI

flush table mysql.proc;
flush privileges;

delete from mysql.proc where name like 'bug14233%';

# Unsupported editing of mysql.proc, circumventing checks in "create ..."
insert into mysql.proc
(
  db, name, type, specific_name, language, sql_data_access, is_deterministic,
  security_type, param_list, returns, body, definer, created, modified,
  sql_mode, comment, character_set_client, collation_connection, db_collation,
  body_utf8
)
values
(
  'test', 'bug14233_1', 'FUNCTION', 'bug14233_1', 'SQL', 'READS_SQL_DATA', 'NO',
  'DEFINER', '', 'int(10)',
  'select count(*) from mysql.user',
  'root@localhost', NOW() , '0000-00-00 00:00:00', '', '',
  '', '', '',
  'select count(*) from mysql.user'
),
(
  'test', 'bug14233_2', 'FUNCTION', 'bug14233_2', 'SQL', 'READS_SQL_DATA', 'NO',
  'DEFINER', '', 'int(10)',
  'begin declare x int; select count(*) into x from mysql.user; end',
  'root@localhost', NOW() , '0000-00-00 00:00:00', '', '',
  '', '', '',
  'begin declare x int; select count(*) into x from mysql.user; end'
),
(
  'test', 'bug14233_3', 'PROCEDURE', 'bug14233_3', 'SQL', 'READS_SQL_DATA','NO',
  'DEFINER', '', '',
  'alksj wpsj sa ^#!@ ',
  'root@localhost', NOW() , '0000-00-00 00:00:00', '', '',
  '', '', '',
  'alksj wpsj sa ^#!@ '
);

--error ER_SP_PROC_TABLE_CORRUPT
select bug14233_1();
--error ER_SP_PROC_TABLE_CORRUPT
create view v1 as select bug14233_1();

--error ER_SP_PROC_TABLE_CORRUPT
select bug14233_2();
--error ER_SP_PROC_TABLE_CORRUPT
create view v1 as select bug14233_2();

--error ER_SP_PROC_TABLE_CORRUPT
call bug14233_3();
drop trigger t1_ai;
create trigger t1_ai after insert on t1 for each row call bug14233_3();
--error ER_SP_PROC_TABLE_CORRUPT
insert into t1 values (0);

# Clean-up
drop trigger t1_ai;
drop table t1;

#
# BUG#16303: erroneus stored procedures and functions should be droppable
#
drop function bug14233_1;
drop function bug14233_2;
drop procedure bug14233_3;
# Assert: These should show nothing.
show procedure status where db=DATABASE();
show function status where db=DATABASE();

#
# Bug#41726 upgrade from 5.0 to 5.1.30 crashes if you didn't run mysql_upgrade
#


--disable_warnings
DROP TABLE IF EXISTS proc_backup;
DROP PROCEDURE IF EXISTS p1;
--enable_warnings

--echo # Backup the proc table

RENAME TABLE mysql.proc TO proc_backup;
CREATE TABLE mysql.proc LIKE proc_backup;
FLUSH TABLE mysql.proc;

--echo # Test with a valid table.

CREATE PROCEDURE p1()
  SET @foo = 10;
CALL p1();
--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
SHOW PROCEDURE STATUS;

--echo # Modify a field of the table.

ALTER TABLE mysql.proc MODIFY comment CHAR (32);

--error ER_CANNOT_LOAD_FROM_TABLE_V2
CREATE PROCEDURE p2()
  SET @foo = 10;
--echo # Procedure loaded from the cache
CALL p1();
--error ER_CANNOT_LOAD_FROM_TABLE_V2
SHOW PROCEDURE STATUS;

DROP TABLE mysql.proc;
RENAME TABLE proc_backup TO mysql.proc;
FLUSH TABLE mysql.proc;


--echo #
--echo # Bug#51376 Assert `! is_set()' failed in 
--echo #           Diagnostics_area::set_ok_status on DROP FUNCTION
--echo #

--disable_warnings
DROP FUNCTION IF EXISTS f1;
--enable_warnings

CREATE FUNCTION f1() RETURNS INT RETURN 1;

--echo # Backup the procs_priv table
RENAME TABLE mysql.procs_priv TO procs_priv_backup;
FLUSH TABLE mysql.procs_priv;

# DROP FUNCTION used to cause an assert.
DROP FUNCTION f1;
SHOW WARNINGS;

--echo # Restore the procs_priv table
RENAME TABLE procs_priv_backup TO mysql.procs_priv;
FLUSH TABLE mysql.procs_priv;


--echo #
--echo # Bug #56137 "Assertion `thd->lock == 0' failed on upgrading from
--echo #             5.1.50 to 5.5.6".
--echo #
--disable_warnings
drop database if exists mysqltest;
--enable_warnings
--echo # Backup mysql.proc.
flush table mysql.proc;
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file $MYSQLD_DATADIR/mysql/proc.frm $MYSQLTEST_VARDIR/tmp/proc.frm
--copy_file $MYSQLD_DATADIR/mysql/proc.MAD $MYSQLTEST_VARDIR/tmp/proc.MAD
--copy_file $MYSQLD_DATADIR/mysql/proc.MAI $MYSQLTEST_VARDIR/tmp/proc.MAI

create database mysqltest;
--echo # Corrupt mysql.proc to make it unusable by current version of server.
alter table mysql.proc drop column security_type;
--echo # The below statement should not cause assertion failure.
drop database mysqltest;

--echo # Restore mysql.proc.
drop table mysql.proc;
--copy_file $MYSQLTEST_VARDIR/tmp/proc.frm $MYSQLD_DATADIR/mysql/proc.frm
--copy_file $MYSQLTEST_VARDIR/tmp/proc.MAD $MYSQLD_DATADIR/mysql/proc.MAD
--copy_file $MYSQLTEST_VARDIR/tmp/proc.MAI $MYSQLD_DATADIR/mysql/proc.MAI 
--remove_file $MYSQLTEST_VARDIR/tmp/proc.frm
--remove_file $MYSQLTEST_VARDIR/tmp/proc.MAD
--remove_file $MYSQLTEST_VARDIR/tmp/proc.MAI


--echo #
--echo # Bug#58414 mysql_upgrade fails on dump upgrade between 5.1.53 -> 5.5.8
--echo #

--disable_warnings
DROP TABLE IF EXISTS proc_backup;
DROP DATABASE IF EXISTS db1;
--enable_warnings

--echo # Backup the proc table
RENAME TABLE mysql.proc TO proc_backup;
CREATE TABLE mysql.proc LIKE proc_backup;

CREATE DATABASE db1;
CREATE PROCEDURE db1.p1() SET @foo = 10;

--echo # Modify a field of the table.
ALTER TABLE mysql.proc MODIFY comment CHAR (32);

# This should not fail even if mysql.proc is invalid.
DROP DATABASE db1;

--echo # Restore mysql.proc
DROP TABLE mysql.proc;
RENAME TABLE proc_backup TO mysql.proc;

#
# BUG#19875331 - HANDLE_FATAL_SIGNAL 11 IN STRMAKE
#
create database mysqltest1;
create procedure mysqltest1.foo() select "foo";
update mysql.proc set name='' where db='mysqltest1';
drop database mysqltest1;

#
# BUG#26881798: SERVER EXITS WHEN PRIMARY KEY IN MYSQL.PROC IS DROPPED
#
create procedure p1() set @foo = 10;
alter table mysql.proc drop primary key;
--error ER_CANNOT_LOAD_FROM_TABLE_V2
drop procedure p1;
alter table mysql.proc add primary key (db,name,type);
drop procedure p1;

--echo # Start of 10.3 tests

--echo #
--echo # MDEV-15444 Querying I_S.PARAMETERS can crash with a corrupted mysql.proc
--echo #

CREATE OR REPLACE FUNCTION f1 (a INT) RETURNS INT RETURN 10;
CREATE OR REPLACE FUNCTION f2 (a INT) RETURNS INT RETURN 10;

# Get the current data type for mysql.proc.type
--vertical_results
SELECT
  @type0:=COLUMN_TYPE AS t0,
  @type1:=REPLACE(COLUMN_TYPE,')',',''XXX'')') AS t1
   FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema='mysql' AND table_name='proc' AND column_name='type';
--horizontal_results

# Change mysql.proc.type and update the record for 'f1'
EXECUTE IMMEDIATE CONCAT('ALTER TABLE mysql.proc MODIFY type ', @type1);
SHOW COLUMNS IN mysql.proc LIKE 'type';
UPDATE mysql.proc SET type='XXX' WHERE name='f1' AND db='test';

# Check the I_S query
--vertical_results
SELECT * FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_SCHEMA='test';
--horizontal_results

# Restore the record for 'f1' and restore mysql.proc.type
UPDATE mysql.proc SET type='FUNCTION' WHERE name='f1' AND db='test';
EXECUTE IMMEDIATE CONCAT('ALTER TABLE mysql.proc MODIFY type ', @type0);
SHOW COLUMNS IN mysql.proc LIKE 'type';

DROP FUNCTION f1;
DROP FUNCTION f2;