diff options
author | Michael Widenius <monty@askmonty.org> | 2013-03-17 14:36:20 +0200 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2013-03-17 14:36:20 +0200 |
commit | 8b047ac5c4b7d326742fd8b7a165a17089a9d83b (patch) | |
tree | 04387528ba7b255c3c15b95989e1ee854c502dc8 /sql/sql_yacc.yy | |
parent | deeed04137908c0a30ef93f12bbdda0ed06e9c0a (diff) | |
download | mariadb-git-8b047ac5c4b7d326742fd8b7a165a17089a9d83b.tar.gz |
Patch by Hartmut Holzgraefe
STRAIGHT_JOIN couldn't be combined with NATURAL or USING(),
INNER JOIN not with NATURAL (MDEV-4271, MySQL Bug #35268)
Separate rules existed for "natural" (non-outer) joins and
for STRAIGHT_JOIN, with the only difference code wise being
that with STRAIGHT_JOIN the "straight" property of the right
side table was set before calling the appropriate add_...()
function.
The "natural_join" parser rule has now been extended to also
accept STRAIGHT_JOIN, and the rule result value is set to
1 for straight joins, 0 otherwise, so acting as a "straight"
flag that can directly be assigned to the "straight" property
of the right side table.
The rule parsing NATURAL JOIN was hard coded to accept just
this keyword combination, without support for either
STRAIGHT_JOIN or the optional INNER.
The "natural_join" rule has now been split up in an inner
"inner_join" rule that matches the JOIN, INNER JOIN and
STRAIGHT_JOIN cases while "natural_join" also matches
CROSS JOIN.
The NATURAL rule has been changed to accept "inner_join"
instead of just JOIN, so now NATURAL STRAIGHT_JOIN and
NATURAL INNER JOIN also work as expected.
As a side effect the removal of the duplciated rules
for STRAIGHT_JOIN handling has reduced the shift/reduce
conflict count by one.
mysql-test/r/join.result:
Added new test cases
mysql-test/t/join.test:
Added new test cases
sql/sql_yacc.yy:
The "natural_join" parser rule was extended to also accept STRAIGHT_JOIN
NATURAL STRAIGHT_JOIN and NATURAL INNER JOIN also now work as expected
Diffstat (limited to 'sql/sql_yacc.yy')
-rw-r--r-- | sql/sql_yacc.yy | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9664aad1e19..3cfd997b2b8 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -789,10 +789,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %pure_parser /* We have threads */ /* - Currently there are 174 shift/reduce conflicts. + Currently there are 173 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 174 +%expect 173 /* Comments for TOKENS. @@ -1623,7 +1623,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); clear_privileges flush_options flush_option opt_with_read_lock flush_options_list equal optional_braces - opt_mi_check_type opt_to mi_check_types normal_join + opt_mi_check_type opt_to mi_check_types table_to_table_list table_to_table opt_table_list opt_as handler_rkey_function handler_read_or_scan single_multi table_wild_list table_wild_one opt_wild @@ -1680,8 +1680,12 @@ END_OF_INPUT '-' '+' '*' '/' '%' '(' ')' ',' '!' '{' '}' '&' '|' AND_SYM OR_SYM OR_OR_SYM BETWEEN_SYM CASE_SYM THEN_SYM WHEN_SYM DIV_SYM MOD_SYM OR2_SYM AND_AND_SYM DELETE_SYM + +%type <num> normal_join inner_join + %% + /* Indentation of grammar rules: @@ -9752,9 +9756,7 @@ join_table: left-associative joins. */ table_ref normal_join table_ref %prec TABLE_REF_PRIORITY - { MYSQL_YYABORT_UNLESS($1 && ($$=$3)); } - | table_ref STRAIGHT_JOIN table_factor - { MYSQL_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; } + { MYSQL_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=$2; } | table_ref normal_join table_ref ON { @@ -9766,22 +9768,7 @@ join_table: } expr { - add_join_on($3,$6); - Lex->pop_context(); - Select->parsing_place= NO_MATTER; - } - | table_ref STRAIGHT_JOIN table_factor - ON - { - MYSQL_YYABORT_UNLESS($1 && $3); - /* Change the current name resolution context to a local context. */ - if (push_new_name_resolution_context(YYTHD, $1, $3)) - MYSQL_YYABORT; - Select->parsing_place= IN_ON; - } - expr - { - $3->straight=1; + $3->straight=$2; add_join_on($3,$6); Lex->pop_context(); Select->parsing_place= NO_MATTER; @@ -9792,10 +9779,15 @@ join_table: MYSQL_YYABORT_UNLESS($1 && $3); } '(' using_list ')' - { add_join_natural($1,$3,$7,Select); $$=$3; } - | table_ref NATURAL JOIN_SYM table_factor + { + $3->straight=$2; + add_join_natural($1,$3,$7,Select); + $$=$3; + } + | table_ref NATURAL inner_join table_factor { MYSQL_YYABORT_UNLESS($1 && ($$=$4)); + $4->straight=$3; add_join_natural($1,$4,NULL,Select); } @@ -9875,10 +9867,16 @@ join_table: } ; + +inner_join: /* $$ set if using STRAIGHT_JOIN, false otherwise */ + JOIN_SYM { $$ = 0; } + | INNER_SYM JOIN_SYM { $$ = 0; } + | STRAIGHT_JOIN { $$ = 1; } + ; + normal_join: - JOIN_SYM {} - | INNER_SYM JOIN_SYM {} - | CROSS JOIN_SYM {} + inner_join { $$ = $1; } + | CROSS JOIN_SYM { $$ = 0; } ; /* |