diff --git a/src/Planner/Planner.cpp b/src/Planner/Planner.cpp index 73a6bc5d810..f2def571325 100644 --- a/src/Planner/Planner.cpp +++ b/src/Planner/Planner.cpp @@ -257,8 +257,9 @@ public: && !query_node.isGroupByWithTotals() && !query_node.isGroupByWithRollup() && !query_node.isGroupByWithCube(); aggregation_with_rollup_or_cube_or_grouping_sets = query_node.isGroupByWithRollup() || query_node.isGroupByWithCube() || query_node.isGroupByWithGroupingSets(); - aggregation_should_produce_results_in_order_of_bucket_number = query_processing_info.getToStage() == QueryProcessingStage::WithMergeableState && - settings.distributed_aggregation_memory_efficient; + aggregation_should_produce_results_in_order_of_bucket_number + = query_processing_info.getToStage() == QueryProcessingStage::WithMergeableState + && (settings.distributed_aggregation_memory_efficient || settings.enable_memory_bound_merging_of_aggregation_results); query_has_array_join_in_join_tree = queryHasArrayJoinInJoinTree(query_tree); query_has_with_totals_in_any_subquery_in_join_tree = queryHasWithTotalsInAnySubqueryInJoinTree(query_tree);