diff --git a/src/pl/ob_pl_user_type.cpp b/src/pl/ob_pl_user_type.cpp index 9dcaf9d6c6..994259df77 100644 --- a/src/pl/ob_pl_user_type.cpp +++ b/src/pl/ob_pl_user_type.cpp @@ -3142,9 +3142,10 @@ int ObPLComposite::copy_element(const ObObj &src, need_new_allocator, ignore_del_element)); CK (OB_NOT_NULL(dest_composite)); + uint8_t extend_type = src.get_meta().get_extend_type(); if (src.get_ext() == dest.get_ext()) { OX (dest.set_extend(reinterpret_cast(src_composite), - src.get_meta().get_extend_type(), + extend_type, src.get_val_len())); OZ (ObUserDefinedType::destruct_obj(dest, session)); OZ (ObPLComposite::deep_copy(*dest_composite, @@ -3155,13 +3156,13 @@ int ObPLComposite::copy_element(const ObObj &src, need_new_allocator, ignore_del_element)); OX (dest.set_extend(reinterpret_cast(dest_composite), - src.get_meta().get_extend_type(), + extend_type, src.get_val_len())); OZ (ObUserDefinedType::destruct_obj(dest, session)); OX (dest_composite = src_composite); } OX (dest.set_extend(reinterpret_cast(dest_composite), - src.get_meta().get_extend_type(), + extend_type, src.get_val_len())); #ifdef OB_BUILD_ORACLE_PL } diff --git a/src/sql/engine/aggregate/ob_aggregate_processor.cpp b/src/sql/engine/aggregate/ob_aggregate_processor.cpp index 6afb37dbdc..ece0f22145 100644 --- a/src/sql/engine/aggregate/ob_aggregate_processor.cpp +++ b/src/sql/engine/aggregate/ob_aggregate_processor.cpp @@ -38,6 +38,7 @@ #include "lib/alloc/malloc_hook.h" #endif #include "pl/ob_pl_user_type.h" +#include "pl/ob_pl.h" namespace oceanbase { @@ -6021,6 +6022,24 @@ int ObAggregateProcessor::get_pl_agg_udf_result(const ObAggrInfo &aggr_info, } else { LOG_TRACE("succeed to get pl agg udf result", K(result_obj), K(result)); } + if (result_obj.is_pl_extend()) { + int tmp_ret = OB_SUCCESS; + if (OB_ISNULL(eval_ctx_.exec_ctx_.get_pl_ctx())) { + tmp_ret = eval_ctx_.exec_ctx_.init_pl_ctx(); + } + if (OB_SUCCESS == tmp_ret && OB_NOT_NULL(eval_ctx_.exec_ctx_.get_pl_ctx())) { + tmp_ret = eval_ctx_.exec_ctx_.get_pl_ctx()->add(result_obj); + } + if (OB_SUCCESS != tmp_ret) { + LOG_ERROR("fail to collect pl collection allocator, may be exist memory issue", K(tmp_ret)); + } + ret = OB_SUCCESS == ret ? tmp_ret : ret; + } + } + + int tmp_ret = OB_SUCCESS; + if ((tmp_ret = pl::ObUserDefinedType::destruct_obj(pl_agg_udf_obj, eval_ctx_.exec_ctx_.get_my_session())) != OB_SUCCESS) { + LOG_WARN("failed to destruct obj, memory may leak", K(ret), K(tmp_ret), K(pl_agg_udf_obj)); } } return ret; diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index 1b40ffe9bc..656bd23021 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -7768,7 +7768,7 @@ int ObSPIService::store_result(ObPLExecCtx *ctx, } else { OZ (deep_copy_obj(*table->get_allocator(), current_obj, tmp)); } - OZ (store_datum(current_datum, tmp)); + OZ (store_datum(current_datum, tmp, ctx->exec_ctx_->get_my_session())); } } } @@ -7865,7 +7865,7 @@ int ObSPIService::store_datums(ObObj &dest_addr, } for (int64_t i = 0; OB_SUCC(ret) && !is_opaque && i < obj_array.count(); ++i) { - if (OB_FAIL(store_datum(current_datum, obj_array.at(i)))) { + if (OB_FAIL(store_datum(current_datum, obj_array.at(i), session_info))) { LOG_WARN("failed to arrange store", K(dest_addr), K(i), K(obj_array.at(i)), K(obj_array), K(ret)); } } @@ -7873,15 +7873,20 @@ int ObSPIService::store_datums(ObObj &dest_addr, return ret; } -int ObSPIService::store_datum(int64_t ¤t_addr, const ObObj &obj) +int ObSPIService::store_datum(int64_t ¤t_addr, const ObObj &obj, ObSQLSessionInfo *session_info) { int ret = OB_SUCCESS; if (OB_UNLIKELY(0 == current_addr) || obj.is_invalid_type()) { ret = OB_INVALID_ARGUMENT; LOG_WARN("Argument passed in is NULL", K(current_addr), K(obj), K(ret)); } else { - new (reinterpret_cast(current_addr))ObObj(obj); - current_addr += sizeof(ObObj); + ObObj *cur_obj = reinterpret_cast(current_addr); + if (OB_FAIL(ObUserDefinedType::destruct_obj(*cur_obj, session_info))) { + LOG_WARN("fail to destruct obj", KPC(cur_obj), K(obj), K(ret)); + } else { + new (cur_obj)ObObj(obj); + current_addr += sizeof(ObObj); + } } return ret; } diff --git a/src/sql/ob_spi.h b/src/sql/ob_spi.h index 07a6ebaa97..2f23635c8d 100644 --- a/src/sql/ob_spi.h +++ b/src/sql/ob_spi.h @@ -976,7 +976,7 @@ private: static int store_datums(ObObj &dest_addr, ObIArray &result, ObIAllocator *alloc, ObSQLSessionInfo *session_info, bool is_schema_object); - static int store_datum(int64_t ¤t_addr, const ObObj &obj); + static int store_datum(int64_t ¤t_addr, const ObObj &obj, ObSQLSessionInfo *session_info); static const ObPostExprItem &get_last_expr_item(const ObSqlExpression &expr);