Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-10036

sql_yacc.yy: Split select_part2 to disallow syntactically bad constructs with INTO, PROCEDURE, UNION

    XMLWordPrintable

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.2.1
    • Parser
    • None
    • 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!

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.