|
51 | 51 | #include <Storages/StorageDummy.h> |
52 | 52 | #include <Storages/StorageMerge.h> |
53 | 53 |
|
| 54 | +#include <AggregateFunctions/IAggregateFunction.h> |
| 55 | + |
54 | 56 | #include <Analyzer/Utils.h> |
55 | 57 | #include <Analyzer/ColumnNode.h> |
56 | 58 | #include <Analyzer/ConstantNode.h> |
@@ -564,13 +566,21 @@ void addMergingAggregatedStep(QueryPlan & query_plan, |
564 | 566 | * but it can work more slowly. |
565 | 567 | */ |
566 | 568 |
|
567 | | - auto keys = aggregation_analysis_result.aggregation_keys; |
| 569 | + const auto & keys = aggregation_analysis_result.aggregation_keys; |
| 570 | + |
| 571 | + /// For count() without parameters try to use just one thread |
| 572 | + /// Typically this will either be a trivial count or a really small number of states |
| 573 | + size_t max_threads = settings[Setting::max_threads]; |
| 574 | + if (keys.empty() && aggregation_analysis_result.aggregate_descriptions.size() == 1 |
| 575 | + && aggregation_analysis_result.aggregate_descriptions[0].function->getName() == String{"count"} |
| 576 | + && aggregation_analysis_result.grouping_sets_parameters_list.empty()) |
| 577 | + max_threads = 1; |
568 | 578 |
|
569 | 579 | Aggregator::Params params( |
570 | 580 | keys, |
571 | 581 | aggregation_analysis_result.aggregate_descriptions, |
572 | 582 | query_analysis_result.aggregate_overflow_row, |
573 | | - settings[Setting::max_threads], |
| 583 | + max_threads, |
574 | 584 | settings[Setting::max_block_size], |
575 | 585 | settings[Setting::min_hit_rate_to_use_consecutive_keys_optimization]); |
576 | 586 |
|
|
0 commit comments