summaryrefslogtreecommitdiff
path: root/mysql-test/t/join.test
diff options
context:
space:
mode:
authorunknown <timour@mysql.com>2006-03-02 11:50:15 +0200
committerunknown <timour@mysql.com>2006-03-02 11:50:15 +0200
commitde1e87bbcd5ca4f830e7af42da34ef0d3228b28e (patch)
treecba6c500f38ff8c287a7cd3c153110cfa476108e /mysql-test/t/join.test
parentf095abaa4748c5ad2c302b8697c819d3fbd5de2a (diff)
downloadmariadb-git-de1e87bbcd5ca4f830e7af42da34ef0d3228b28e.tar.gz
Fix for BUG#15229.
The cause of this bug was a design flaw due to which the list of natural join columns was incorrectly computed and stored for nested joins that are not natural joins, but are operands (possibly indirect) of nested joins. The patch corrects the flaw in a such a way, that the result columns of a table reference are materialized only if it is a leaf table (that is, only if it is a view, stored table, or natural/using join). mysql-test/r/join.result: Added test for BUG#15229 and uncommented failing test cases of BUG#15357 (now fixed by this patch). mysql-test/t/join.test: Added test for BUG#15229 and uncommented failing test cases of BUG#15357 (now fixed by this patch). sql/sql_base.cc: - Do not materialize the result columns of regular nested joins (that are not natural/using joins). - Moved most of the code that creates/adds new natural join column references to the method 'get_or_create_column_ref', and simplified 'mark_common_columns'. - Replaced a call to 'get_or_create_column_ref' with 'get_natural_column_ref' where it is for sure all columns are alredy created. sql/table.cc: - Modified the method 'get_or_create_column_ref' so that it adds itself the newly created natural join columns to the respective table reference. sql/table.h: - Modified the method 'get_or_create_column_ref' so that it adds itself the newly created natural join columns to the respective table reference.
Diffstat (limited to 'mysql-test/t/join.test')
-rw-r--r--mysql-test/t/join.test41
1 files changed, 29 insertions, 12 deletions
diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test
index 553aaf987bb..e58227df067 100644
--- a/mysql-test/t/join.test
+++ b/mysql-test/t/join.test
@@ -408,11 +408,10 @@ select * from t1 natural join (t2 natural join (t3 natural join t4));
select * from t5 natural right join (t4 natural right join ((t2 natural right join t1) natural right join t3));
select * from (t1 natural join t2), (t3 natural join t4);
-- MySQL extension - nested comma ',' operator instead of cross join.
--- BUG#15357 - natural join with nested cross-join results in incorrect columns
--- select * from t5 natural join ((t1 natural join t2), (t3 natural join t4));
--- select * from ((t1 natural join t2), (t3 natural join t4)) natural join t5;
--- select * from t5 natural join ((t1 natural join t2) cross join (t3 natural join t4));
--- select * from ((t1 natural join t2) cross join (t3 natural join t4)) natural join t5;
+select * from t5 natural join ((t1 natural join t2), (t3 natural join t4));
+select * from ((t1 natural join t2), (t3 natural join t4)) natural join t5;
+select * from t5 natural join ((t1 natural join t2) cross join (t3 natural join t4));
+select * from ((t1 natural join t2) cross join (t3 natural join t4)) natural join t5;
select * from (t1 join t2 using (b)) join (t3 join t4 using (c)) using (c);
select * from (t1 join t2 using (b)) natural join (t3 join t4 using (c));
@@ -500,8 +499,7 @@ select * from ((t1 natural join t2), (t3 natural join t4)) natural join t6;
-- error 1052
select * from ((t1 natural join t2), (t3 natural join t4)) natural join t6;
-- error 1052
--- BUG#15357: doesn't detect non-unique column 'c', as in the above query.
--- select * from t6 natural join ((t1 natural join t2), (t3 natural join t4));
+select * from t6 natural join ((t1 natural join t2), (t3 natural join t4));
-- error 1052
select * from (t1 join t2 on t1.b=t2.b) natural join (t3 natural join t4);
-- error 1052
@@ -512,11 +510,7 @@ select * from (t3 join (t4 natural join t5) on (b < z))
natural join
(t1 natural join t2);
-- error 1052
--- BUG#15357: this query should return an ambiguous column error
--- Expected result: the query must return error with duplicate column 'c'
---select * from (t1 natural join t2)
--- natural join
--- (t3 join (t4 natural join t5) on (b < z));
+select * from (t1 natural join t2) natural join (t3 join (t4 natural join t5) on (b < z));
-- error 1054
select t1.b from v1a;
@@ -540,4 +534,27 @@ drop view v3a;
drop view v3b;
drop view v4;
+#
+# BUG#15229 - columns of nested joins that are not natural joins incorrectly
+# materialized
+#
+create table t1 (a1 int, a2 int);
+create table t2 (a1 int, b int);
+create table t3 (c1 int, c2 int);
+create table t4 (c2 int);
+
+insert into t1 values (1,1);
+insert into t2 values (1,1);
+insert into t3 values (1,1);
+insert into t4 values (1);
+
+select * from t1 join t2 using (a1) join t3 on b=c1 join t4 using (c2);
+select * from t3 join (t1 join t2 using (a1)) on b=c1 join t4 using (c2);
+select a2 from t1 join t2 using (a1) join t3 on b=c1 join t4 using (c2);
+select a2 from t3 join (t1 join t2 using (a1)) on b=c1 join t4 using (c2);
+select a2 from ((t1 join t2 using (a1)) join t3 on b=c1) join t4 using (c2);
+select a2 from ((t1 natural join t2) join t3 on b=c1) natural join t4;
+
+drop table t1,t2,t3,t4;
+
# End of tests for WL#2486 - natural/using join