fix cross alliasing case with JOIN ON

This commit is contained in:
chertus 2019-07-25 22:25:51 +03:00
parent 06076e67a3
commit 554e4ab5b8
3 changed files with 31 additions and 8 deletions

View File

@ -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();)
{

View File

@ -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

View File

@ -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;