Commit 53a0e299 authored by unknown's avatar unknown

SCRUM Task 430: Allowing braces in joins by simply removing them.

Fixed the remaining join variations, (left, right, natural, etc).
(Previous fix only solved "," and "[cross] join".)


mysql-test/r/select.result:
  Added more test case results for more braced join fixes.
mysql-test/t/select.test:
  Added more tests for braced join fixes.
sql/sql_yacc.yy:
  Changed the remaining join_table_list cases to handle braces.
  Also added some precedence declaration to silence shift/reduce conflicts
  warnings that turned up after these fixes.
parent b9ce7600
......@@ -3292,4 +3292,179 @@ a a a
1 3 3
2 3 3
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
a a a
1 1 1
2 2 1
3 3 1
1 1 2
2 2 2
3 3 2
1 1 3
2 2 3
3 3 3
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 1 1
3 1 1
1 2 2
2 2 2
3 2 2
1 3 3
2 3 3
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
a a a
1 1 2
2 2 2
3 3 2
1 1 3
2 2 3
3 3 3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
1 1 NULL
2 1 1
3 1 1
1 2 NULL
2 2 2
3 2 2
1 3 NULL
2 3 3
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );
a a a
1 1 1
2 2 2
3 3 3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
1 1 1
2 1 NULL
3 1 NULL
1 2 NULL
2 2 2
3 2 NULL
1 3 NULL
2 3 NULL
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
a a a
1 1 2
1 1 3
2 2 2
2 2 3
3 3 2
3 3 3
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
1 1 NULL
2 1 1
3 1 1
1 2 NULL
2 2 2
3 2 2
1 3 NULL
2 3 3
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );
a a a
1 1 1
2 2 2
3 3 3
select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
1 1 1
2 1 NULL
3 1 NULL
1 2 NULL
2 2 2
3 2 NULL
1 3 NULL
2 3 NULL
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
a a a
1 1 1
2 2 2
3 3 3
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 1 NULL
3 1 NULL
1 2 NULL
2 2 2
3 2 NULL
1 3 NULL
2 3 NULL
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
a a a
1 NULL 1
2 NULL 1
3 NULL 1
1 1 2
2 2 2
3 3 2
1 1 3
2 2 3
3 3 3
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
2 1 1
3 1 1
2 2 2
3 2 2
2 3 3
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
a a a
1 1 1
2 NULL 1
3 NULL 1
1 NULL 2
2 2 2
3 NULL 2
1 NULL 3
2 NULL 3
3 3 3
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
1 1 1
2 2 2
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;
a a a
1 1 1
2 NULL 1
3 NULL 1
1 NULL 2
2 2 2
3 NULL 2
1 NULL 3
2 NULL 3
3 3 3
select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 2 2
3 3 3
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 1 NULL
3 1 NULL
1 2 NULL
2 2 2
3 2 NULL
1 3 NULL
2 3 NULL
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
a a a
1 1 1
2 2 2
3 3 3
drop table t1;
......@@ -1754,13 +1754,46 @@ drop table t1;
#
# Test of removing redundant braces in the FROM part
# (The second case used to cause a syntax error)
# (We test each construct with the braced join to the left and right;
# the latter case used to cause a syntax errors.)
#
create table t1 (a int not null auto_increment primary key);
insert into t1 values ();
insert into t1 values ();
insert into t1 values ();
# ,
select * from (t1 as t2 left join t1 as t3 using (a)), t1;
select * from t1, (t1 as t2 left join t1 as t3 using (a));
# stright_join
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
# inner join on
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
# inner join using
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );
# left [outer] join on
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
# left join using
select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );
select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
# natural left join
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
# right join on
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
# right [outer] joing using
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );
# natural right join
select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;
select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));
# natural join
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
drop table t1;
......@@ -491,6 +491,12 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%right NOT
%right BINARY
/* These don't actually affect the way the query is really evaluated, but
they silence a few warnings for shift/reduce conflicts. */
%left ','
%left STRAIGHT_JOIN JOIN_SYM
%nonassoc CROSS INNER_SYM NATURAL LEFT RIGHT
%type <lex_str>
IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
ULONGLONG_NUM field_ident select_alias ident ident_or_text
......@@ -2027,10 +2033,11 @@ join_table_list:
'(' join_table_list ')' { $$=$2; }
| join_table { $$=$1; }
| join_table_list normal_join join_table_list { $$=$3; }
| join_table_list STRAIGHT_JOIN join_table { $$=$3 ; $$->straight=1; }
| join_table_list INNER_SYM JOIN_SYM join_table ON expr
| join_table_list STRAIGHT_JOIN join_table_list
{ $$=$3 ; $$->straight=1; }
| join_table_list INNER_SYM JOIN_SYM join_table_list ON expr
{ add_join_on($4,$6); $$=$4; }
| join_table_list INNER_SYM JOIN_SYM join_table
| join_table_list INNER_SYM JOIN_SYM join_table_list
{
SELECT_LEX *sel=Select;
sel->db1=$1->db; sel->table1=$1->alias;
......@@ -2038,9 +2045,9 @@ join_table_list:
}
USING '(' using_list ')'
{ add_join_on($4,$8); $$=$4; }
| join_table_list LEFT opt_outer JOIN_SYM join_table ON expr
| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
{ add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
| join_table_list LEFT opt_outer JOIN_SYM join_table
| join_table_list LEFT opt_outer JOIN_SYM join_table_list
{
SELECT_LEX *sel=Select;
sel->db1=$1->db; sel->table1=$1->alias;
......@@ -2048,11 +2055,11 @@ join_table_list:
}
USING '(' using_list ')'
{ add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table
| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
{ add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; }
| join_table_list RIGHT opt_outer JOIN_SYM join_table ON expr
| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
{ add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
| join_table_list RIGHT opt_outer JOIN_SYM join_table
| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
{
SELECT_LEX *sel=Select;
sel->db1=$1->db; sel->table1=$1->alias;
......@@ -2060,9 +2067,9 @@ join_table_list:
}
USING '(' using_list ')'
{ add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table
| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
{ add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
| join_table_list NATURAL JOIN_SYM join_table
| join_table_list NATURAL JOIN_SYM join_table_list
{ add_join_natural($1,$4); $$=$4; };
normal_join:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment