[MDEV-9166] Wrong error message and shift/reduce conflicts in the RETURNS clause Created: 2015-11-23  Updated: 2016-03-02  Resolved: 2015-11-23

Status: Closed
Project: MariaDB Server
Component/s: Parser
Affects Version/s: None
Fix Version/s: 10.2.0

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Sprint: 10.2.0-1

 Description   

There is a shift/reduce conflict in the grammar in sql_yacc.yy when parsing a query like this:

CREATE FUNCTION f1() RETURNS CHAR (....);

The parser does not know what the left parenthesis means, either it continues the data type specifying the length:

CREATE FUNCTION f1() RETURNS CHAR(1) ...;

or it's a CHAR with no length (i.e. length==1) followed by a start of a subselect:

CREATE FUNCTION f1() RETURNS CHAR (SELECT 'a');

Note, the latter query is accepted by the parse, but it's syntactically is wrong. A correct query would be:

CREATE FUNCTION f1() RETURNS CHAR RETURN (SELECT 'a');

Fortunately, currently the wrong query returns an error anyway:

ERROR 1415 (0A000) at line 3: Not allowed to return a result set from a function

But it should be fixed to return a syntax error instead, because the RETURN keyword is obviously missing.

An idea for a fix:

The sp_proc_stmt rule in sql_yacc.yy should be split into two parts:
1. statements that are allowed in RETURN clause
2. statements that are not allowed in RETURN clause
Subselect should go into #2.

This will fix the error message, as well as remove some shift/reduce conflicts.


Generated at Thu Feb 08 07:32:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.