diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 1f38e3888a0..c56597e6e44 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -779,7 +779,7 @@ drop procedure bug11394| CREATE PROCEDURE BUG_12490() HELP CONTENTS; ERROR 0A000: HELP is not allowed in stored procedures CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS; -ERROR 0A000: HELP is not allowed in stored procedures +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'HELP CONTENTS' at line 1 CREATE TABLE t_bug_12490(a int); CREATE TRIGGER BUG_12490 BEFORE UPDATE ON t_bug_12490 FOR EACH ROW HELP CONTENTS; ERROR 0A000: HELP is not allowed in stored procedures diff --git a/mysql-test/suite/funcs_1/r/storedproc.result b/mysql-test/suite/funcs_1/r/storedproc.result index f0e1ee74e0b..655a5d3ff96 100644 --- a/mysql-test/suite/funcs_1/r/storedproc.result +++ b/mysql-test/suite/funcs_1/r/storedproc.result @@ -3816,7 +3816,7 @@ return 1' at line 1 CREATE FUNCTION fn1(a char) returns int lang sql return 1; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sql return 1' at line 1 CREATE FUNCTION fn1(a char) returns int deterministic( return 1); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'return 1)' at line 1 +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( return 1)' at line 1 CREATE FUNCTION fn1(a char) returns int non deterministic return 1; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'deterministic return 1' at line 1 CREATE FUNCTION fn1(a char) returns int not deterministic comment 'abc' language sql sql security refiner return 1; diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index a47fbe7a372..d403b19eff7 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -1093,7 +1093,7 @@ delimiter ;| # --error ER_SP_BADSTATEMENT CREATE PROCEDURE BUG_12490() HELP CONTENTS; ---error ER_SP_BADSTATEMENT +--error ER_PARSE_ERROR CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS; CREATE TABLE t_bug_12490(a int); --error ER_SP_BADSTATEMENT diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index a5a62aeeafb..c5e1ab1b51b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -994,10 +994,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %parse-param { THD *thd } %lex-param { THD *thd } /* - Currently there are 160 shift/reduce conflicts. + Currently there are 142 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 160 +%expect 142 /* Comments for TOKENS. @@ -1926,6 +1926,7 @@ END_OF_INPUT %type call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt %type sp_proc_stmt_statement sp_proc_stmt_return + sp_proc_stmt_in_returns_clause %type sp_proc_stmt_compound_ok %type sp_proc_stmt_if %type sp_labeled_control sp_unlabeled_control @@ -3652,18 +3653,31 @@ sp_opt_default: | DEFAULT expr { $$ = $2; } ; -sp_proc_stmt: - sp_proc_stmt_statement - | sp_proc_stmt_return +/* + ps_proc_stmt_in_returns_clause is a statement that is allowed + in the RETURNS clause of a stored function definition directly, + without the BEGIN..END block. + It should not include any syntax structures starting with '(', to avoid + shift/reduce conflicts with the rule "field_type" and its sub-rules + that scan an optional length, like CHAR(1) or YEAR(4). + See MDEV-9166. +*/ +sp_proc_stmt_in_returns_clause: + sp_proc_stmt_return | sp_labeled_block | sp_unlabeled_block | sp_labeled_control + | sp_proc_stmt_compound_ok + ; + +sp_proc_stmt: + sp_proc_stmt_in_returns_clause + | sp_proc_stmt_statement | sp_proc_stmt_leave | sp_proc_stmt_iterate | sp_proc_stmt_open | sp_proc_stmt_fetch | sp_proc_stmt_close - | sp_proc_stmt_compound_ok ; sp_proc_stmt_compound_ok: @@ -16405,7 +16419,7 @@ sf_tail: lex->sphead->set_body_start(thd, lip->get_cpp_tok_start()); } - sp_proc_stmt /* $15 */ + sp_proc_stmt_in_returns_clause /* $15 */ { LEX *lex= thd->lex; sp_head *sp= lex->sphead;