diff --git a/dbms/src/Interpreters/CollectJoinOnKeysVisitor.h b/dbms/src/Interpreters/CollectJoinOnKeysVisitor.h index 1857bc88cf4..7dc3051167a 100644 --- a/dbms/src/Interpreters/CollectJoinOnKeysVisitor.h +++ b/dbms/src/Interpreters/CollectJoinOnKeysVisitor.h @@ -110,6 +110,9 @@ private: static const ASTIdentifier * unrollAliases(const ASTIdentifier * identifier, const Aliases & aliases) { + if (identifier->compound()) + return identifier; + UInt32 max_attempts = 100; for (auto it = aliases.find(identifier->name); it != aliases.end();) { diff --git a/dbms/tests/queries/0_stateless/00974_fix_join_on.reference b/dbms/tests/queries/0_stateless/00974_fix_join_on.reference index 1d0b18e4f96..90c76d8b931 100644 --- a/dbms/tests/queries/0_stateless/00974_fix_join_on.reference +++ b/dbms/tests/queries/0_stateless/00974_fix_join_on.reference @@ -12,6 +12,12 @@ y y y y y y y y +2 2 +2 2 +2 2 +2 2 +2 2 +2 2 2 y 2 w 2 y 2 w 2 2 @@ -26,3 +32,9 @@ y y y y y y y y +2 2 +2 2 +2 2 +2 2 +2 2 +2 2 diff --git a/dbms/tests/queries/0_stateless/00974_fix_join_on.sql b/dbms/tests/queries/0_stateless/00974_fix_join_on.sql index 1a3126f981d..feffe046d4f 100644 --- a/dbms/tests/queries/0_stateless/00974_fix_join_on.sql +++ b/dbms/tests/queries/0_stateless/00974_fix_join_on.sql @@ -10,6 +10,7 @@ insert into t1 values (1, 'x'), (2, 'y'), (3, 'z'); insert into t2 values (2, 'w'), (4, 'y'); set enable_optimize_predicate_expression = 0; + select * from t1 join t2 on a = c; select * from t1 join t2 on c = a; @@ -28,14 +29,13 @@ select b as a, d as c from t1 join t2 on c = a; select b as c, d as a from t1 join t2 on a = c; select b as c, d as a from t1 join t2 on c = a; --- TODO --- select t1.a as a, t2.c as c from t1 join t2 on a = c; --- select t1.a as a, t2.c as c from t1 join t2 on c = a; --- select t1.a as c, t2.c as a from t1 join t2 on a = c; --- select t1.a as c, t2.c as a from t1 join t2 on c = a; --- --- select t1.a as c, t2.c as a from t1 join t2 on t1.a = t2.c; --- select t1.a as c, t2.c as a from t1 join t2 on t2.c = t1.a; +select t1.a as a, t2.c as c from t1 join t2 on a = c; +select t1.a as a, t2.c as c from t1 join t2 on c = a; +select t1.a as c, t2.c as a from t1 join t2 on a = c; +select t1.a as c, t2.c as a from t1 join t2 on c = a; + +select t1.a as c, t2.c as a from t1 join t2 on t1.a = t2.c; +select t1.a as c, t2.c as a from t1 join t2 on t2.c = t1.a; set enable_optimize_predicate_expression = 1; @@ -57,5 +57,13 @@ select b as a, d as c from t1 join t2 on c = a; select b as c, d as a from t1 join t2 on a = c; select b as c, d as a from t1 join t2 on c = a; +select t1.a as a, t2.c as c from t1 join t2 on a = c; +select t1.a as a, t2.c as c from t1 join t2 on c = a; +select t1.a as c, t2.c as a from t1 join t2 on a = c; +select t1.a as c, t2.c as a from t1 join t2 on c = a; + +select t1.a as c, t2.c as a from t1 join t2 on t1.a = t2.c; +select t1.a as c, t2.c as a from t1 join t2 on t2.c = t1.a; + drop table t1; drop table t2;