Merge pull request #4279 from 4ertus2/joins

hotfix for duplicates in JOIN ON
This commit is contained in:
alexey-milovidov 2019-02-05 22:07:10 +03:00 committed by GitHub
commit fda5aa31c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;