[MDEV-20634] Report disallowed subquery errors as such (instead of parse error) Created: 2019-09-20  Updated: 2019-09-24  Resolved: 2019-09-24

Status: Closed
Project: MariaDB Server
Component/s: Parser
Fix Version/s: 10.4.9

Type: Task Priority: Blocker
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-19956 Queries with subqueries containing UN... Closed

 Description   

Subqueries are not allowed in a number of clauses, e.g.:

  • EXECUTE IMMEDIATE expr
  • EXECUTE .. USING expr
  • PREPARE stmt FROM expr
  • SELECT .. PROCEDURE ANALYSE(expr, expr)
  • PURGE BINARY LOGS BEFORE expr
  • HANDLER t1 READ a=expr

If a subquery appears in a disallowed context, a syntax error is reported:

EXECUTE IMMEDIATE (SELECT 'SELECT 1');

ERROR 42000: You have an error in your SQL syntax ... near 'SELECT 'SELECT 1')' at line 1

The grammar uses remember_tok_start to remember the start position of a subquery, to use this position for error reporting:

subselect:
          remember_tok_start
          query_expression
          {
            if (!($$= Lex->parsed_subselect($2, $1)))
              YYABORT;
          }
        ;

Under terms of MDEV-19956 the grammar will be changed significantly. The remember_tok_start has to be removed to avoid shift/reduce and reduce/reduce conflicts.

Let's change the error message from ER_SYNTAX_ERROR to ER_SUBQUERIES_NOT_SUPPORTED.
So it will look as follows:

EXECUTE IMMEDIATE (SELECT 'SELECT 1');

ERROR 42000: EXECUTE IMMEDIATE does not support subqueries or stored functions

Rationale:

  • Preserving the old messages is challenging
  • The proposed error message is more informative

Generated at Thu Feb 08 09:01:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.