1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

Implementation of WL#2486 -

"Process NATURAL and USING joins according to SQL:2003".

* Some of the main problems fixed by the patch:
  - in "select *" queries the * expanded correctly according to
    ANSI for arbitrary natural/using joins
  - natural/using joins are correctly transformed into JOIN ... ON
    for any number/nesting of the joins.
  - column references are correctly resolved against natural joins
    of any nesting and combined with arbitrary other joins.

* This patch also contains a fix for name resolution of items
  inside the ON condition of JOIN ... ON - in this case items must
  be resolved only against the JOIN operands. To support such
  'local' name resolution, the patch introduces a stack of
  name resolution contexts used at parse time.

NOTICE:
- This patch is not complete in the sense that
  - there are 2 test cases that still do not pass -
    one in join.test, one in select.test. Both are marked
    with a comment "TODO: WL#2486".
  - it does not include a new test specific for the task
This commit is contained in:
timour@mysql.com
2005-08-12 17:57:19 +03:00
parent 2889025acc
commit a247282aa6
63 changed files with 3549 additions and 1893 deletions

View File

@@ -519,56 +519,56 @@ a ? a
drop table if exists t2 ;
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
the join statement is:
SELECT * FROM t2 right join t1 using(a) order by t2.a
SELECT * FROM t2 right join t1 using(a) order by a
prepare stmt1 from @query9 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural right join t1 order by t2.a
SELECT * FROM t2 natural right join t1 order by a
prepare stmt1 from @query8 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query7 ;
@@ -591,47 +591,47 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 left join t1 using(a) order by t2.a
SELECT * FROM t2 left join t1 using(a) order by a
prepare stmt1 from @query6 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural left join t1 order by t2.a
SELECT * FROM t2 natural left join t1 order by a
prepare stmt1 from @query5 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query4 ;
@@ -654,28 +654,28 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 join t1 using(a) order by t2.a
SELECT * FROM t2 join t1 using(a) order by a
prepare stmt1 from @query3 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural join t1 order by t2.a
SELECT * FROM t2 natural join t1 order by a
prepare stmt1 from @query2 ;
execute stmt1 ;
a b