diff --git a/src/sql/engine/sort/ob_prefix_sort_vec_op_impl.h b/src/sql/engine/sort/ob_prefix_sort_vec_op_impl.h index ea6277c2ee..18be014bd6 100644 --- a/src/sql/engine/sort/ob_prefix_sort_vec_op_impl.h +++ b/src/sql/engine/sort/ob_prefix_sort_vec_op_impl.h @@ -55,10 +55,10 @@ protected: LST_DO_CODE(USING_SORT_IMPL, init, is_inited, add_batch, get_next_batch, get_next_batch_stored_rows, init_temp_row_store, adjust_topn_read_rows, attach_rows, - allocator_, eval_ctx_, cmp_sk_exprs_, sk_exprs_, all_exprs_, addon_exprs_, - addon_vec_ptrs_, sk_vec_ptrs_, comp_, part_cnt_, topn_cnt_, outputted_rows_cnt_, - cmp_sort_collations_, exec_ctx_, enable_encode_sortkey_, sk_rows_, addon_rows_, - sk_store_, addon_store_, sk_row_meta_, addon_row_meta_); + allocator_, mem_context_, eval_ctx_, cmp_sk_exprs_, sk_exprs_, all_exprs_, + addon_exprs_, addon_vec_ptrs_, sk_vec_ptrs_, comp_, part_cnt_, topn_cnt_, + outputted_rows_cnt_, cmp_sort_collations_, exec_ctx_, enable_encode_sortkey_, + sk_rows_, addon_rows_, sk_store_, addon_store_, sk_row_meta_, addon_row_meta_); // fetch rows in same prefix && do sort, set %next_prefix_row_ to nullptr // when all child rows are fetched. diff --git a/src/sql/engine/sort/ob_prefix_sort_vec_op_impl.ipp b/src/sql/engine/sort/ob_prefix_sort_vec_op_impl.ipp index a8c0c06bb3..4c898c3192 100644 --- a/src/sql/engine/sort/ob_prefix_sort_vec_op_impl.ipp +++ b/src/sql/engine/sort/ob_prefix_sort_vec_op_impl.ipp @@ -31,10 +31,20 @@ void ObPrefixSortVecImpl::reset() prefix_pos_ = 0; im_sk_store_.reset(); im_addon_store_.reset(); - im_sk_rows_ = nullptr; - im_addon_rows_ = nullptr; immediate_pos_ = 0; brs_ = nullptr; + if (nullptr != mem_context_ && nullptr != selector_) { + mem_context_->get_malloc_allocator().free(selector_); + selector_ = nullptr; + } + if (nullptr != mem_context_ && nullptr != im_sk_rows_) { + mem_context_->get_malloc_allocator().free(im_sk_rows_); + im_sk_rows_ = nullptr; + } + if (nullptr != mem_context_ && nullptr != im_addon_rows_) { + mem_context_->get_malloc_allocator().free(im_addon_rows_); + im_addon_rows_ = nullptr; + } ObSortVecOpImpl::reset(); } @@ -80,10 +90,10 @@ int ObPrefixSortVecImpl::init(ObSortVecOpContext SQL_ENG_LOG(WARN, "failed to init temp row store", K(ret)); } else { selector_ = - (typeof(selector_))ctx.exec_ctx_->get_allocator().alloc(batch_size * sizeof(*selector_)); - im_sk_rows_ = (typeof(im_sk_rows_))ctx.exec_ctx_->get_allocator().alloc( + (typeof(selector_))mem_context_->get_malloc_allocator().alloc(batch_size * sizeof(*selector_)); + im_sk_rows_ = (typeof(im_sk_rows_))mem_context_->get_malloc_allocator().alloc( batch_size * sizeof(*im_sk_rows_)); - im_addon_rows_ = (typeof(im_addon_rows_))ctx.exec_ctx_->get_allocator().alloc( + im_addon_rows_ = (typeof(im_addon_rows_))mem_context_->get_malloc_allocator().alloc( batch_size * sizeof(*im_addon_rows_)); if (nullptr == selector_ || nullptr == im_sk_rows_ || nullptr == im_addon_rows_) { ret = OB_ALLOCATE_MEMORY_FAILED; diff --git a/src/sql/engine/sort/ob_sort_op_impl.cpp b/src/sql/engine/sort/ob_sort_op_impl.cpp index 1df98411c0..d5f0e26b68 100644 --- a/src/sql/engine/sort/ob_sort_op_impl.cpp +++ b/src/sql/engine/sort/ob_sort_op_impl.cpp @@ -2769,10 +2769,16 @@ void ObPrefixSortImpl::reset() selector_size_ = 0; sort_prefix_rows_ = 0; immediate_prefix_store_.reset(); - immediate_prefix_rows_ = 0; immediate_prefix_pos_ = 0; brs_ = NULL; - + if (nullptr != mem_context_ && nullptr != selector_) { + mem_context_->get_malloc_allocator().free(selector_); + selector_ = nullptr; + } + if (nullptr != mem_context_ && nullptr != immediate_prefix_rows_) { + mem_context_->get_malloc_allocator().free(immediate_prefix_rows_); + immediate_prefix_rows_ = nullptr; + } ObSortOpImpl::reset(); } @@ -2833,10 +2839,10 @@ int ObPrefixSortImpl::init(const int64_t tenant_id, LOG_WARN("fetch rows failed"); } } else { - selector_ = (typeof(selector_))eval_ctx->exec_ctx_.get_allocator().alloc( + selector_ = (typeof(selector_))mem_context_->get_malloc_allocator().alloc( batch_size * sizeof(*selector_)); immediate_prefix_rows_ = (typeof(immediate_prefix_rows_)) - eval_ctx->exec_ctx_.get_allocator().alloc(batch_size * sizeof(*immediate_prefix_rows_)); + mem_context_->get_malloc_allocator().alloc(batch_size * sizeof(*immediate_prefix_rows_)); if (NULL == selector_ || NULL == immediate_prefix_rows_) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("allocate memory failed",