[MDEV-10079] sql_yacc.yy: Remove non-parenthesized SELECT from table_ref Created: 2016-05-17  Updated: 2016-05-17  Resolved: 2016-05-17

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

 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.


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