mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
fix distinct with join
This commit is contained in:
parent
cdc65eca23
commit
950f8a7042
@ -760,11 +760,11 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt
|
||||
executeExpression(pipeline, expressions.before_order_and_select);
|
||||
executeDistinct(pipeline, true, expressions.selected_columns);
|
||||
|
||||
need_second_distinct_pass = query.distinct && pipeline.hasMoreThanOneStream();
|
||||
need_second_distinct_pass = query.distinct && pipeline.hasMixedStreams();
|
||||
}
|
||||
else
|
||||
{
|
||||
need_second_distinct_pass = query.distinct && pipeline.hasMoreThanOneStream();
|
||||
need_second_distinct_pass = query.distinct && pipeline.hasMixedStreams();
|
||||
|
||||
if (query.group_by_with_totals && !aggregate_final)
|
||||
{
|
||||
@ -1533,6 +1533,7 @@ void InterpreterSelectQuery::executeUnion(Pipeline & pipeline)
|
||||
pipeline.firstStream() = std::make_shared<UnionBlockInputStream>(pipeline.streams, pipeline.stream_with_non_joined_data, max_streams);
|
||||
pipeline.stream_with_non_joined_data = nullptr;
|
||||
pipeline.streams.resize(1);
|
||||
pipeline.union_stream = true;
|
||||
}
|
||||
else if (pipeline.stream_with_non_joined_data)
|
||||
{
|
||||
|
@ -100,6 +100,7 @@ private:
|
||||
* It is appended to the main streams in UnionBlockInputStream or ParallelAggregatingBlockInputStream.
|
||||
*/
|
||||
BlockInputStreamPtr stream_with_non_joined_data;
|
||||
bool union_stream = false;
|
||||
|
||||
BlockInputStreamPtr & firstStream() { return streams.at(0); }
|
||||
|
||||
@ -117,6 +118,11 @@ private:
|
||||
{
|
||||
return streams.size() + (stream_with_non_joined_data ? 1 : 0) > 1;
|
||||
}
|
||||
|
||||
bool hasMixedStreams() const
|
||||
{
|
||||
return hasMoreThanOneStream() || union_stream;
|
||||
}
|
||||
};
|
||||
|
||||
void executeImpl(Pipeline & pipeline, const BlockInputStreamPtr & prepared_input, bool dry_run);
|
||||
|
@ -0,0 +1,2 @@
|
||||
0
|
||||
1
|
15
dbms/tests/queries/0_stateless/00859_distinct_with_join.sql
Normal file
15
dbms/tests/queries/0_stateless/00859_distinct_with_join.sql
Normal file
@ -0,0 +1,15 @@
|
||||
use test;
|
||||
|
||||
drop table if exists fooL;
|
||||
drop table if exists fooR;
|
||||
create table fooL (a Int32, v String) engine = Memory;
|
||||
create table fooR (a Int32, v String) engine = Memory;
|
||||
|
||||
insert into fooL select number, 'L' || toString(number) from numbers(2);
|
||||
insert into fooL select number, 'LL' || toString(number) from numbers(2);
|
||||
insert into fooR select number, 'R' || toString(number) from numbers(2);
|
||||
|
||||
select distinct a from fooL any join fooR using(a) order by a;
|
||||
|
||||
drop table fooL;
|
||||
drop table fooR;
|
Loading…
Reference in New Issue
Block a user