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

sql_yacc.yy: Remove non-parenthesized SELECT from table_ref

    XMLWordPrintable

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.2.1
    • Parser
    • None

    Description

      The "table_ref" rule allows non-parenthesized SELECT query.
      table_ref is used in derived_table_list and join_table.

      Non-parenthesized SELECT query is OK in derived_table_list, which is used (among other things) to handle derived tables in FROM clause:

      SELECT * FROM (SELECT * FROM t1);
      

      But when table_ref is used in join_table, non-parenthesized SELECT should not be allowed:

      join_table:
                table_ref normal_join table_ref
              | table_ref normal_join table_ref ON ...
              | table_ref normal_join table_ref USING ...
              | table_ref NATURAL inner_join table_factor
              | table_ref LEFT opt_outer JOIN_SYM table_ref ON ...
              | table_ref LEFT opt_outer JOIN_SYM table_factor USING
              | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
              | table_ref RIGHT opt_outer JOIN_SYM table_ref ON ...
              | table_ref RIGHT opt_outer JOIN_SYM table_factor USING ...
              | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
              ;
      

      Examples of bad queries:

      SELECT * FROM (SELECT 1 NATURAL JOIN t2);  -- SELECT 1 on the left side of JOIN is incorrect
      SELECT * FROM t1 NATURAL JOIN SELECT 1; -- SELECT on the right side of JOIN is incorrect
      

      Currently bad queries are caught by extra code:

      {
        MYSQL_YYABORT_UNLESS($1 && ($$=$4));
        $4->straight=$3;
        add_join_natural($1,$4,NULL,Select);
      }
      

      if (!sel->embedding || sel->end_nested_join(lex->thd))
      {
        /* we are not in parentheses */
        my_parse_error(thd, ER_SYNTAX_ERROR);
          MYSQL_YYABORT;
        }  
      

      Under terms of this task we'll disallow such queries syntactically, by moving non-parenthesized SELECT from table_ref to derived_table_list.
      Unfortunately, it's not possible to remove the extra code at this stage, because it's used for some other purposes as well.

      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.