From c3b83240d7d181820c314887846f0290476c7e6d Mon Sep 17 00:00:00 2001 From: Cerdore Date: Mon, 16 Dec 2024 18:15:17 +0000 Subject: [PATCH] fix allocate memory failed in sort vec op --- src/sql/engine/sort/ob_sort_vec_op_impl.h | 11 ++++++++++- src/sql/engine/sort/ob_sort_vec_op_impl.ipp | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/sql/engine/sort/ob_sort_vec_op_impl.h b/src/sql/engine/sort/ob_sort_vec_op_impl.h index 2eb8388c4..df36a8752 100644 --- a/src/sql/engine/sort/ob_sort_vec_op_impl.h +++ b/src/sql/engine/sort/ob_sort_vec_op_impl.h @@ -202,7 +202,14 @@ protected: bool need_dump() { return sql_mem_processor_.get_data_size() > get_tmp_buffer_mem_bound() - || mem_context_->used() >= profile_.get_max_bound(); + || get_total_used_size() >= profile_.get_max_bound(); + } + int64_t get_total_used_size() + { + int64_t row_cnt = sk_store_.get_row_cnt(); + return mem_context_->used() + ((part_cnt_ == 0) ? 0 : + ((row_cnt * FIXED_PART_NODE_SIZE * 2) + // size of(part_hash_nodes_) + (next_pow2(std::max(16L, row_cnt)) * FIXED_PART_BKT_SIZE * 2))); // size of(buckets_) } inline int64_t get_tmp_buffer_mem_bound() { // The memory reserved for ObSortVecOpEagerFilter should be deducted when topn filter is enabled. @@ -400,6 +407,8 @@ protected: using BucketNodeArray = common::ObSegmentArray; + const static int64_t FIXED_PART_NODE_SIZE = sizeof(PartHashNode); + const static int64_t FIXED_PART_BKT_SIZE = sizeof(PartHashNode *); static const int64_t MAX_ROW_CNT = 268435456; // (2G / 8) static const int64_t EXTEND_MULTIPLE = 2; static const int64_t MAX_MERGE_WAYS = 256; diff --git a/src/sql/engine/sort/ob_sort_vec_op_impl.ipp b/src/sql/engine/sort/ob_sort_vec_op_impl.ipp index 005fd8968..2672df760 100644 --- a/src/sql/engine/sort/ob_sort_vec_op_impl.ipp +++ b/src/sql/engine/sort/ob_sort_vec_op_impl.ipp @@ -1180,7 +1180,7 @@ int ObSortVecOpImpl::preprocess_dump(bool &dumped dumped = false; if (OB_FAIL(sql_mem_processor_.get_max_available_mem_size(&mem_context_->get_malloc_allocator()))) { SQL_ENG_LOG(WARN, "failed to get max available memory size", K(ret)); - } else if (OB_FAIL(sql_mem_processor_.update_used_mem_size(mem_context_->used()))) { + } else if (OB_FAIL(sql_mem_processor_.update_used_mem_size(get_total_used_size()))) { SQL_ENG_LOG(WARN, "failed to update used memory size", K(ret)); } else { dumped = need_dump(); @@ -1203,10 +1203,10 @@ int ObSortVecOpImpl::preprocess_dump(bool &dumped UNUSED(max_memory_size); return need_dump(); }, - dumped, mem_context_->used()))) { + dumped, get_total_used_size()))) { SQL_ENG_LOG(WARN, "failed to extend memory size", K(ret)); } - LOG_TRACE("trace sort need dump", K(dumped), K(mem_context_->used()), K(get_memory_limit()), + LOG_TRACE("trace sort need dump", K(dumped), K(get_total_used_size()), K(get_memory_limit()), K(profile_.get_cache_size()), K(profile_.get_expect_size())); } else { // one-pass