diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index 4feefb67c1f..63be7eb8f77 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -454,13 +454,13 @@ void InterpreterSelectQuery::executeSingleQuery() settings.limits.max_rows_to_group_by && settings.limits.group_by_overflow_mode == OverflowMode::ANY && settings.totals_mode != TotalsMode::AFTER_HAVING_EXCLUSIVE; + /// Нужно ли после агрегации сразу финализировать агрегатные функции. bool aggregate_final = need_aggregate && to_stage > QueryProcessingStage::WithMergeableState && !query.group_by_with_totals; - if (need_aggregate || has_order_by) do_execute_union = true; @@ -769,10 +769,6 @@ void InterpreterSelectQuery::executeAggregation(BlockInputStreams & streams, Exp void InterpreterSelectQuery::executeMergeAggregated(BlockInputStreams & streams, bool overflow_row, bool final) { - /// Если объединять нечего - if (streams.size() == 1) - return; - /// Склеим несколько источников в один executeUnion(streams); diff --git a/dbms/tests/queries/0_stateless/00123_unmerged_result_when_max_distributed_connections_is_one.reference b/dbms/tests/queries/0_stateless/00123_unmerged_result_when_max_distributed_connections_is_one.reference new file mode 100644 index 00000000000..00750edc07d --- /dev/null +++ b/dbms/tests/queries/0_stateless/00123_unmerged_result_when_max_distributed_connections_is_one.reference @@ -0,0 +1 @@ +3 diff --git a/dbms/tests/queries/0_stateless/00123_unmerged_result_when_max_distributed_connections_is_one.sql b/dbms/tests/queries/0_stateless/00123_unmerged_result_when_max_distributed_connections_is_one.sql new file mode 100644 index 00000000000..2e944b43dae --- /dev/null +++ b/dbms/tests/queries/0_stateless/00123_unmerged_result_when_max_distributed_connections_is_one.sql @@ -0,0 +1,2 @@ +SET max_distributed_connections = 1; +SELECT count() + 1 FROM remote('127.0.0.{1,2}', system, one);