From 86f65d8f9db722cac087619b57bb0821d0fd6bbd Mon Sep 17 00:00:00 2001 From: Seaven Date: Thu, 2 Jan 2025 19:54:39 +0800 Subject: [PATCH] reserve Signed-off-by: Seaven --- be/src/common/config.h | 2 +- be/src/exec/aggregate/agg_hash_map.h | 2 ++ be/src/exec/aggregate/agg_hash_set.h | 2 ++ be/src/exec/aggregate/agg_hash_variant.h | 6 ++++-- be/src/exec/aggregator.cpp | 8 ++++---- .../src/main/java/com/starrocks/planner/PlanNode.java | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/be/src/common/config.h b/be/src/common/config.h index 46800aba43270d..83d9de4eefd774 100644 --- a/be/src/common/config.h +++ b/be/src/common/config.h @@ -1535,5 +1535,5 @@ CONF_mBool(enable_hk_shuffle_sort, "false"); CONF_mBool(enable_hk_string_select, "false"); -CONF_mBool(enable_aggregate_reserve, "false"); +CONF_mBool(enable_hk_aggregate_reserve, "false"); } // namespace starrocks::config diff --git a/be/src/exec/aggregate/agg_hash_map.h b/be/src/exec/aggregate/agg_hash_map.h index 27c6f4f2ad7f81..3bb591c32291fb 100644 --- a/be/src/exec/aggregate/agg_hash_map.h +++ b/be/src/exec/aggregate/agg_hash_map.h @@ -106,6 +106,8 @@ struct AggHashMapWithKey { HashMap hash_map; AggStatistics* agg_stat; + void reserve(size_t capacity) { hash_map.reserve(capacity); } + ////// Common Methods //////// template void build_hash_map(size_t chunk_size, const Columns& key_columns, MemPool* pool, Func&& allocate_func, diff --git a/be/src/exec/aggregate/agg_hash_set.h b/be/src/exec/aggregate/agg_hash_set.h index b05bd0c57ac88c..96db67da137c97 100644 --- a/be/src/exec/aggregate/agg_hash_set.h +++ b/be/src/exec/aggregate/agg_hash_set.h @@ -105,6 +105,8 @@ struct AggHashSet { return x.rehash_number; } + void reserve(size_t n) { hash_set.reserve(n); } + ////// Common Methods //////// void build_hash_set(size_t chunk_size, const Columns& key_columns, MemPool* pool) { return static_cast(this)->template build_set(chunk_size, key_columns, pool, nullptr); diff --git a/be/src/exec/aggregate/agg_hash_variant.h b/be/src/exec/aggregate/agg_hash_variant.h index 951881199ef0e8..54732539fdfb30 100644 --- a/be/src/exec/aggregate/agg_hash_variant.h +++ b/be/src/exec/aggregate/agg_hash_variant.h @@ -488,7 +488,9 @@ struct AggHashMapVariant { size_t allocated_memory_usage(const MemPool* pool) const; - void reserve(int capacity) {} + void reserve(size_t capacity) { + visit([&](const auto& hash_map_with_key) { return hash_map_with_key->reserve(capacity); }); + } private: Type _type = Type::phase1_slice; @@ -600,7 +602,7 @@ struct AggHashSetVariant { return visit([](auto& hash_set_with_key) { return hash_set_with_key->rehash_count(); }); } - void reserve(int capacity) { + void reserve(size_t capacity) { visit([&](auto& hash_set_with_key) { hash_set_with_key->reserve(capacity); }); } diff --git a/be/src/exec/aggregator.cpp b/be/src/exec/aggregator.cpp index e5f26e4c2ed35e..8f12c0ba3c327a 100644 --- a/be/src/exec/aggregator.cpp +++ b/be/src/exec/aggregator.cpp @@ -1367,10 +1367,6 @@ void Aggregator::_init_agg_hash_variant(HashVariantType& hash_variant) { } } - if (config::enable_aggregate_reserve) { - hash_variant.reserve(_params->predicted_rows / 2); - } - VLOG_ROW << "hash type is " << static_cast::type>(type); hash_variant.init(_state, type, _agg_stat); @@ -1381,6 +1377,10 @@ void Aggregator::_init_agg_hash_variant(HashVariantType& hash_variant) { variant->fixed_byte_size = fixed_byte_size; } }); + + if (config::enable_hk_aggregate_reserve) { + hash_variant.reserve(_params->predicted_rows / 2); + } } void Aggregator::build_hash_map(size_t chunk_size, bool agg_group_by_with_limit) { diff --git a/fe/fe-core/src/main/java/com/starrocks/planner/PlanNode.java b/fe/fe-core/src/main/java/com/starrocks/planner/PlanNode.java index 189c43be94f4c9..5c852df26220f7 100644 --- a/fe/fe-core/src/main/java/com/starrocks/planner/PlanNode.java +++ b/fe/fe-core/src/main/java/com/starrocks/planner/PlanNode.java @@ -521,7 +521,7 @@ private void treeToThriftHelper(TPlan container) { msg.node_id = id.asInt(); msg.num_children = children.size(); msg.limit = limit; - msg.predicted_rows = predictedRows; + msg.setPredicted_rows(predictedRows); for (TupleId tid : tupleIds) { msg.addToRow_tuples(tid.asInt());