Commit b2910906 authored by anozdrin@mysql.com's avatar anozdrin@mysql.com

Fix for Bug#12953 "Stored procedures: crash if OPTIMIZE TABLE in function"

OPTIMIZE TABLE statement is forbidden from usage in stored procedures/functions.

NOTE: OPTIMIZE TABLE statement can be useful in stored procedures. The idea is
that the user/administrator can create a stored procedure for admin
tasks (optimizing, backing up, etc). This procedure can be scheduled to run
automatically (by mean of internal cron (WL#1034)). So, once we can make this
statement work, it is worth doing it.
parent 0cf9ca58
...@@ -758,3 +758,10 @@ execute stmt; ...@@ -758,3 +758,10 @@ execute stmt;
ERROR 42000: FUNCTION test.bug11834_1 does not exist ERROR 42000: FUNCTION test.bug11834_1 does not exist
deallocate prepare stmt; deallocate prepare stmt;
drop function bug11834_2; drop function bug11834_2;
DROP FUNCTION IF EXISTS bug12953|
CREATE FUNCTION bug12953() RETURNS INT
BEGIN
OPTIMIZE TABLE t1;
RETURN 1;
END|
ERROR 0A000: OPTIMIZE TABLE is not allowed in stored procedures
...@@ -1085,6 +1085,21 @@ drop function bug11834_1; ...@@ -1085,6 +1085,21 @@ drop function bug11834_1;
execute stmt; execute stmt;
deallocate prepare stmt; deallocate prepare stmt;
drop function bug11834_2; drop function bug11834_2;
#
# Bug#12953 "Stored procedures: crash if OPTIMIZE TABLE in function"
#
delimiter |;
--disable_warnings
DROP FUNCTION IF EXISTS bug12953|
--enable_warnings
--error ER_SP_BADSTATEMENT
CREATE FUNCTION bug12953() RETURNS INT
BEGIN
OPTIMIZE TABLE t1;
RETURN 1;
END|
# #
# BUG#NNNN: New bug synopsis # BUG#NNNN: New bug synopsis
# #
...@@ -1092,5 +1107,3 @@ drop function bug11834_2; ...@@ -1092,5 +1107,3 @@ drop function bug11834_2;
#drop procedure if exists bugNNNN| #drop procedure if exists bugNNNN|
#--enable_warnings #--enable_warnings
#create procedure bugNNNN... #create procedure bugNNNN...
...@@ -3826,6 +3826,11 @@ optimize: ...@@ -3826,6 +3826,11 @@ optimize:
OPTIMIZE opt_no_write_to_binlog table_or_tables OPTIMIZE opt_no_write_to_binlog table_or_tables
{ {
LEX *lex=Lex; LEX *lex=Lex;
if (lex->sphead)
{
my_error(ER_SP_BADSTATEMENT, MYF(0), "OPTIMIZE TABLE");
YYABORT;
}
lex->sql_command = SQLCOM_OPTIMIZE; lex->sql_command = SQLCOM_OPTIMIZE;
lex->no_write_to_binlog= $2; lex->no_write_to_binlog= $2;
lex->check_opt.init(); lex->check_opt.init();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment