[MDEV-10036] sql_yacc.yy: Split select_part2 to disallow syntactically bad constructs with INTO, PROCEDURE, UNION Created: 2016-05-06  Updated: 2016-05-10  Resolved: 2016-05-10

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

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

Issue Links:
Blocks
blocks MDEV-8909 union parser cleanup Closed
Sprint: 10.2.1-1

 Description   

sql_yacc.yy has the following code:

select_part2:
          select_options_and_item_list
          opt_order_clause
          opt_limit_clause
          opt_select_lock_type
        | select_options_and_item_list into opt_select_lock_type
        | select_options_and_item_list
          opt_into
          table_expression
          opt_order_clause
          opt_limit_clause
          opt_procedure_clause
          opt_into
          opt_select_lock_type
          {
            if ($2 && $7)
            {
              /* double "INTO" clause */
              my_error(ER_WRONG_USAGE, MYF(0), "INTO", "INTO");
              MYSQL_YYABORT;
            }
            if ($6 && ($2 || $7))
            {
              /* "INTO" with "PROCEDURE ANALYSE" */
              my_error(ER_WRONG_USAGE, MYF(0), "PROCEDURE", "INTO");
              MYSQL_YYABORT;
            }
          }
        ;

This task will refactor select_part2 to disallow wrong constructs so instead of

Incorrect usage of INTO and INTO
Incorrect usage of INTO and PROCEDURE
Incorrect usage of INTO and UNION
Incorrect usage of UNON and PROCEDURE

the parser will generate "syntax error", like this:

SELECT * FROM t1 LIMIT 1  UNION ALL SELECT 1;

ERROR 1064 (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 'UNION ALL SELECT 1' at line 1

Note, this change will not affect subselects, they will still return "Incorrect usage":

SELECT (SELECT * FROM t1 LIMIT 1  UNION ALL SELECT 1);

ERROR 1221 (HY000): Incorrect usage of UNION and LIMIT

Subselect will be fixed in a separate patch. We'll do one small step at a time!


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