hotfix for duplicates in JOIN ON #4271

This commit is contained in:
chertus 2019-02-05 19:58:57 +03:00
parent dea4f7e817
commit 396d4fb921
3 changed files with 35 additions and 1 deletions

View File

@ -469,9 +469,15 @@ bool Join::insertFromBlock(const Block & block)
}
else
{
NameSet erased; /// HOTFIX: there could be duplicates in JOIN ON section
/// Remove the key columns from stored_block, as they are not needed.
for (const auto & name : key_names_right)
stored_block->erase(stored_block->getPositionByName(name));
{
if (!erased.count(name))
stored_block->erase(stored_block->getPositionByName(name));
erased.insert(name);
}
}
size_t size = stored_block->columns();

View File

@ -0,0 +1,9 @@
1 1 a 1 1 a
2 2 b \N \N \N
1 1 a 1 1 a
2 2 b \N \N \N
1 1 a 1 1 a
1 1 a 1 1 a
2 2 b \N \N \N
1 1 a 1 1 a
2 2 b \N \N \N

View File

@ -0,0 +1,19 @@
use test;
drop table if exists t;
drop table if exists s;
create table t(a Nullable(Int64), b Nullable(Int64), c Nullable(String)) engine = Memory;
create table s(a Nullable(Int64), b Nullable(Int64), c Nullable(String)) engine = Memory;
insert into t values(1,1,'a'), (2,2,'b');
insert into s values(1,1,'a');
select * from t left join s on t.a = s.a;
select * from t left join s on t.a = s.a and t.a = s.b;
select * from t left join s on t.a = s.a where s.a = 1;
select * from t left join s on t.a = s.a and t.a = s.a;
select * from t left join s on t.a = s.a and t.b = s.a;
drop table t;
drop table s;