From 7cd500275866181d2bad056cba52ae0538a9ddcf Mon Sep 17 00:00:00 2001 From: xufei Date: Tue, 7 Feb 2023 11:40:56 +0800 Subject: [PATCH] refine Signed-off-by: xufei --- dbms/src/Interpreters/Aggregator.cpp | 6 ++--- dbms/src/Interpreters/Aggregator.h | 34 ++++++++++++++++------------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/dbms/src/Interpreters/Aggregator.cpp b/dbms/src/Interpreters/Aggregator.cpp index f2518d71cf7..3dc1c98e8b5 100644 --- a/dbms/src/Interpreters/Aggregator.cpp +++ b/dbms/src/Interpreters/Aggregator.cpp @@ -847,9 +847,9 @@ BlockInputStreams Aggregator::restoreSpilledData() void Aggregator::initThresholdByAggregatedDataVariantsSize(size_t aggregated_data_variants_size) { - group_by_two_level_threshold = params.group_by_two_level_threshold; - group_by_two_level_threshold_bytes = getAverageThreshold(params.group_by_two_level_threshold_bytes, aggregated_data_variants_size); - max_bytes_before_external_group_by = getAverageThreshold(params.max_bytes_before_external_group_by, aggregated_data_variants_size); + group_by_two_level_threshold = params.getGroupByTwoLevelThreshold(); + group_by_two_level_threshold_bytes = getAverageThreshold(params.getGroupByTwoLevelThresholdBytes(), aggregated_data_variants_size); + max_bytes_before_external_group_by = getAverageThreshold(params.getMaxBytesBeforeExternalGroupBy(), aggregated_data_variants_size); } void Aggregator::spill(AggregatedDataVariants & data_variants) diff --git a/dbms/src/Interpreters/Aggregator.h b/dbms/src/Interpreters/Aggregator.h index 1cfad34dd00..087f338eb96 100644 --- a/dbms/src/Interpreters/Aggregator.h +++ b/dbms/src/Interpreters/Aggregator.h @@ -917,17 +917,6 @@ class Aggregator size_t keys_size; size_t aggregates_size; - /// Two-level aggregation settings (used for a large number of keys). - /** With how many keys or the size of the aggregation state in bytes, - * two-level aggregation begins to be used. Enough to reach of at least one of the thresholds. - * 0 - the corresponding threshold is not specified. - */ - const size_t group_by_two_level_threshold; - const size_t group_by_two_level_threshold_bytes; - - /// Settings to flush temporary data to the filesystem (external aggregation). - const size_t max_bytes_before_external_group_by; /// 0 - do not use external aggregation. - /// Return empty result when aggregating without keys on empty set. bool empty_result_for_aggregation_by_empty_set; @@ -952,13 +941,13 @@ class Aggregator , aggregates(aggregates_) , keys_size(keys.size()) , aggregates_size(aggregates.size()) - , group_by_two_level_threshold(group_by_two_level_threshold_) - , group_by_two_level_threshold_bytes(group_by_two_level_threshold_bytes_) - , max_bytes_before_external_group_by(max_bytes_before_external_group_by_) , empty_result_for_aggregation_by_empty_set(empty_result_for_aggregation_by_empty_set_) , spill_config(spill_config_) , max_block_size(max_block_size_) , collators(collators_) + , group_by_two_level_threshold(group_by_two_level_threshold_) + , group_by_two_level_threshold_bytes(group_by_two_level_threshold_bytes_) + , max_bytes_before_external_group_by(max_bytes_before_external_group_by_) { } @@ -988,6 +977,17 @@ class Aggregator /// Calculate the column numbers in `keys` and `aggregates`. void calculateColumnNumbers(const Block & block); + + size_t getGroupByTwoLevelThreshold() const { return group_by_two_level_threshold; } + size_t getGroupByTwoLevelThresholdBytes() const { return group_by_two_level_threshold_bytes; } + size_t getMaxBytesBeforeExternalGroupBy() const { return max_bytes_before_external_group_by; } + + private: + /// Note these thresholds should not be used directly, they are only used to + /// init the threshold in Aggregator + const size_t group_by_two_level_threshold; + const size_t group_by_two_level_threshold_bytes; + const size_t max_bytes_before_external_group_by; /// 0 - do not use external aggregation. }; @@ -1101,8 +1101,14 @@ class Aggregator /// Returns true if you can abort the current task. CancellationHook is_cancelled; + /// Two-level aggregation settings (used for a large number of keys). + /** With how many keys or the size of the aggregation state in bytes, + * two-level aggregation begins to be used. Enough to reach of at least one of the thresholds. + * 0 - the corresponding threshold is not specified. + */ size_t group_by_two_level_threshold = 0; size_t group_by_two_level_threshold_bytes = 0; + /// Settings to flush temporary data to the filesystem (external aggregation). size_t max_bytes_before_external_group_by = 0; /// For external aggregation.