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.1986 05/09/10 15:01:54 timour@stripped +4 -0
Fix for BUG#12943.
The problem was that in the first production in rule 'join_table', that
processes simple cross joins, the parser was processing the second join operand
before the first one due to unspecified priorities of JOINs. As a result in the
case of cross joins the parser constructed a tree with incorrect nesting:
the expression "t1 join t2 join t3 on some_cond" was interpreted as
"t1 join (t2 join t3 on some_cond)" instead of
"(t1 join t2) join t3 on some_cond".
Because of this incorrect nesting the method make_join_on_context picked an
incorrect table as the first table of the name resolution context.
The solution assignes correct priorities to the related production.
sql/sql_yacc.yy
1.420 05/09/10 15:01:51 timour@stripped +10 -1
Provide explicit priorities of the JOIN operator and the 'table_ref' rule,
to enforce left-associativity of [INNER | CROSS] JOIN.
sql/sql_parse.cc
1.481 05/09/10 15:01:51 timour@stripped +1 -1
Fixed typo.
mysql-test/t/select.test
1.74 05/09/10 15:01:50 timour@stripped +23 -0
Added test for BUG#12943.
mysql-test/r/select.result
1.89 05/09/10 15:01:50 timour@stripped +20 -0
Added test for BUG#12943.
# 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-12943
--- 1.480/sql/sql_parse.cc 2005-09-07 10:33:21 +03:00
+++ 1.481/sql/sql_parse.cc 2005-09-10 15:01:51 +03:00
@@ -6354,7 +6354,7 @@
SYNOPSIS
make_join_on_context()
thd pointer to current thread
- left_op lefto operand of the JOIN
+ left_op left operand of the JOIN
right_op rigth operand of the JOIN
DESCRIPTION
--- 1.419/sql/sql_yacc.yy 2005-09-07 22:44:12 +03:00
+++ 1.420/sql/sql_yacc.yy 2005-09-10 15:01:51 +03:00
@@ -660,6 +660,9 @@
%token YEAR_SYM
%token ZEROFILL
+%left JOIN_SYM
+/* A dummy token to force the priority of table_ref production in a join. */
+%left TABLE_REF_PRIORITY
%left SET_VAR
%left OR_OR_SYM OR_SYM OR2_SYM XOR
%left AND_SYM AND_AND_SYM
@@ -5189,7 +5192,13 @@
;
join_table:
- table_ref normal_join table_ref { YYERROR_UNLESS($1 && ($$=$3)); }
+ /*
+ Evaluate production 'table_ref' before 'normal_join' so that
+ [INNER | CROSS] JOIN is properly nested as other left-associative
+ joins.
+ */
+ table_ref %prec TABLE_REF_PRIORITY normal_join table_ref
+ { YYERROR_UNLESS($1 && ($$=$3)); }
| table_ref STRAIGHT_JOIN table_factor
{ YYERROR_UNLESS($1 && ($$=$3)); $3->straight=1; }
| table_ref normal_join table_ref
--- 1.88/mysql-test/r/select.result 2005-08-29 16:44:57 +03:00
+++ 1.89/mysql-test/r/select.result 2005-09-10 15:01:50 +03:00
@@ -2897,3 +2897,23 @@
a
b
drop table t1, t2;
+create table t1 (a int, c int);
+create table t2 (b int);
+create table t3 (b int, a int);
+create table t4 (c int);
+insert into t1 values (1,1);
+insert into t2 values (1);
+insert into t3 values (1,1);
+insert into t4 values (1);
+select * from t1 join t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
+a c b b a
+1 1 1 1 1
+select * from t1, t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
+ERROR 42S22: Unknown column 't1.a' in 'on clause'
+select * from t1 join t2 join t3 join t4 on (t1.a = t4.c and t2.b = t4.c);
+a c b b a c
+1 1 1 1 1 1
+select * from t1 join t2 join t4 using (c);
+c a b
+1 1 1
+drop table t1, t2, t3, t4;
--- 1.73/mysql-test/t/select.test 2005-08-29 16:44:57 +03:00
+++ 1.74/mysql-test/t/select.test 2005-09-10 15:01:50 +03:00
@@ -2465,3 +2465,26 @@
select a from t1 natural join t2;
select * from t1 natural join t2 where a = 'b';
drop table t1, t2;
+
+#
+# Bug #12943 Incorrect nesting of [INNER| CROSS] JOIN due to unspecified
+# associativity in the parser.
+#
+
+create table t1 (a int, c int);
+create table t2 (b int);
+create table t3 (b int, a int);
+create table t4 (c int);
+insert into t1 values (1,1);
+insert into t2 values (1);
+insert into t3 values (1,1);
+insert into t4 values (1);
+
+select * from t1 join t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
+# Notice that ',' has lower priority than 'join', thus we have that:
+# t1, t2 join t3 <==> t1, (t2 join t3).
+-- error 1054
+select * from t1, t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
+select * from t1 join t2 join t3 join t4 on (t1.a = t4.c and t2.b = t4.c);
+select * from t1 join t2 join t4 using (c);
+drop table t1, t2, t3, t4;
| Thread |
|---|
| • bk commit into 5.0 tree (timour:1.1986) BUG#12943 | timour | 10 Sep |