| 108 | } |
| 109 | |
| 110 | void MergingAggregatedStep::transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings & build_settings) |
| 111 | { |
| 112 | if (hasNonParallelAggregateFunctions(params->params.aggregates)) |
| 113 | { |
| 114 | pipeline.resize(1); |
| 115 | } |
| 116 | |
| 117 | // optimizer use MergingAggregateStep in by-name style, regenerate aggregator params of by-position style |
| 118 | if (!keys.empty()) |
| 119 | { |
| 120 | ColumnNumbers key_positions; |
| 121 | const auto & header = pipeline.getHeader(); |
| 122 | for (const auto & key : keys) |
| 123 | key_positions.emplace_back(header.getPositionByName(key)); |
| 124 | |
| 125 | Aggregator::Params new_params( |
| 126 | header, |
| 127 | key_positions, |
| 128 | params->params.aggregates, |
| 129 | params->params.overflow_row, |
| 130 | build_settings.context->getSettingsRef().max_threads); |
| 131 | params = std::make_shared<AggregatingTransformParams>(new_params, params->final); |
| 132 | } |
| 133 | |
| 134 | // @FIXME: grouping sets + two-level aggregation is incompatible with memory efficient merge |
| 135 | // see also: https://meego.feishu.cn/clickhousech/story/detail/14744099 |
| 136 | if (!memory_efficient_aggregation || input_streams.front().header.has("__grouping_set")) |
| 137 | { |
| 138 | /// We union several sources into one, paralleling the work. |
| 139 | pipeline.resize(1); |
| 140 | |
| 141 | /// Now merge the aggregated blocks |
| 142 | pipeline.addSimpleTransform([&](const Block & header) |
| 143 | { |
| 144 | return std::make_shared<MergingAggregatedTransform>(header, params, max_threads); |
| 145 | }); |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | auto num_merge_threads = memory_efficient_merge_threads |
| 150 | ? static_cast<size_t>(memory_efficient_merge_threads) |
| 151 | : static_cast<size_t>(max_threads); |
| 152 | |
| 153 | pipeline.addMergingAggregatedMemoryEfficientTransform(params, num_merge_threads); |
| 154 | } |
| 155 | |
| 156 | computeGroupingFunctions(pipeline, groupings, keys, grouping_sets_params, build_settings); |
| 157 | |
| 158 | pipeline.resize(should_produce_results_in_order_of_bucket_number ? 1 : max_threads); |
| 159 | } |
| 160 | |
| 161 | void MergingAggregatedStep::describeActions(FormatSettings & settings) const |
| 162 | { |
nothing calls this directly
no test coverage detected