From: Date: October 24 2005 5:07pm Subject: bk commit into 5.0 tree (timour:1.2024) BUG#13832 List-Archive: http://lists.mysql.com/internals/31378 X-Bug: 13832 Message-Id: <20051024150710.196A61997EB@lamia.home> Below is the list of changes that have just been committed into a local 5.0 repository of timka. When timka does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2024 05/10/24 18:07:04 timour@stripped +3 -0 Fix for BUG#13832 - Unknown column t1.a in 'on clause'. The cause for the bug is that the priorities of all rules/terminals that process the FROM clause are not fully specified, and the parser generator produces a parser that doesn't always parse the FROM clause so that JOINs are left-associative. As a result the final join tree produced by the parser is incorrect, which is the cause for subsequent name resolution to fail. sql/sql_yacc.yy 1.435 05/10/24 18:06:48 timour@stripped +14 -6 Fix for BUG#13832 - Unknown column t1.a in 'on clause'. List all join-related operators as having lower priority than the join operands to make the parser process join- related productions from left to right. mysql-test/t/select.test 1.87 05/10/24 18:06:48 timour@stripped +14 -0 Test for BUG#13832. mysql-test/r/select.result 1.106 05/10/24 18:06:48 timour@stripped +12 -0 Test for BUG#13832. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: timour # Host: lamia.home # Root: /home/timka/mysql/src/5.0-bug-13832 --- 1.434/sql/sql_yacc.yy 2005-10-13 17:27:29 +03:00 +++ 1.435/sql/sql_yacc.yy 2005-10-24 18:06:48 +03:00 @@ -660,7 +660,7 @@ %token YEAR_SYM %token ZEROFILL -%left JOIN_SYM +%left JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT /* A dummy token to force the priority of table_ref production in a join. */ %left TABLE_REF_PRIORITY %left SET_VAR @@ -5231,8 +5231,10 @@ [INNER | CROSS] JOIN is properly nested as other left-associative joins. */ + +/* INNER JOIN variants */ table_ref %prec TABLE_REF_PRIORITY normal_join table_ref - { YYERROR_UNLESS($1 && ($$=$3)); } + { YYERROR_UNLESS($1 && ($$=$3)); } | table_ref STRAIGHT_JOIN table_factor { YYERROR_UNLESS($1 && ($$=$3)); $3->straight=1; } | table_ref normal_join table_ref @@ -5274,6 +5276,13 @@ } '(' using_list ')' { add_join_natural($1,$3,$7); $$=$3; } + | table_ref NATURAL JOIN_SYM table_factor + { + YYERROR_UNLESS($1 && ($$=$4)); + add_join_natural($1,$4,NULL); + } + +/* LEFT JOIN variants */ | table_ref LEFT opt_outer JOIN_SYM table_ref ON { @@ -5305,6 +5314,8 @@ $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; } + +/* RIGHT JOIN variants */ | table_ref RIGHT opt_outer JOIN_SYM table_ref ON { @@ -5342,10 +5353,7 @@ LEX *lex= Lex; if (!($$= lex->current_select->convert_right_join())) YYABORT; - } - | table_ref NATURAL JOIN_SYM table_factor - { YYERROR_UNLESS($1 && ($$=$4)); add_join_natural($1,$4,NULL); }; - + }; normal_join: JOIN_SYM {} --- 1.105/mysql-test/r/select.result 2005-10-14 00:04:45 +03:00 +++ 1.106/mysql-test/r/select.result 2005-10-24 18:06:48 +03:00 @@ -3124,3 +3124,15 @@ count(*) 6 drop table t1,t2,t3; +create table t1 (a int); +create table t2 (b int); +create table t3 (c int); +select * from t1 join t2 join t3 on (t1.a=t3.c); +a b c +select * from t1 join t2 left join t3 on (t1.a=t3.c); +a b c +select * from t1 join t2 right join t3 on (t1.a=t3.c); +a b c +select * from t1 join t2 straight_join t3 on (t1.a=t3.c); +a b c +drop table t1, t2 ,t3; --- 1.86/mysql-test/t/select.test 2005-10-14 00:04:46 +03:00 +++ 1.87/mysql-test/t/select.test 2005-10-24 18:06:48 +03:00 @@ -2649,3 +2649,17 @@ from t1 inner join (t2 right join t3 on t2.id = t3.b_id) on t1.id = t3.a_id; drop table t1,t2,t3; + +# +# Bug #13832 Incorrect parse order of join productions due to unspecified +# operator priorities results in incorrect join tree. +# + +create table t1 (a int); +create table t2 (b int); +create table t3 (c int); +select * from t1 join t2 join t3 on (t1.a=t3.c); +select * from t1 join t2 left join t3 on (t1.a=t3.c); +select * from t1 join t2 right join t3 on (t1.a=t3.c); +select * from t1 join t2 straight_join t3 on (t1.a=t3.c); +drop table t1, t2 ,t3;