diff --git a/src/pl/ob_pl_allocator.cpp b/src/pl/ob_pl_allocator.cpp index d9b13b64fc..ef780831da 100644 --- a/src/pl/ob_pl_allocator.cpp +++ b/src/pl/ob_pl_allocator.cpp @@ -34,6 +34,9 @@ void* ObPLAllocator::alloc(const int64_t size, const ObMemAttr &attr) } if (OB_SUCC(ret)) { ptr = curr_->alloc(size, attr); + if (curr_->used() > 100 * 1024 * 1024) { + LOG_INFO("[WARNING] PlTemp memory hold too much, should check...", K(curr_->used()), K(lbt())); + } } return ptr; } diff --git a/src/pl/ob_pl_resolver.cpp b/src/pl/ob_pl_resolver.cpp index 3651e63760..423c424cfa 100644 --- a/src/pl/ob_pl_resolver.cpp +++ b/src/pl/ob_pl_resolver.cpp @@ -14046,26 +14046,16 @@ int ObPLResolver::resolve_construct(ObObjAccessIdent &access_ident, return ret; } -int ObPLResolver::resolve_self_element_access(ObObjAccessIdent &access_ident, - const ObPLBlockNS &ns, - ObIArray &access_idxs, - ObPLCompileUnitAST &func) +int ObPLResolver::build_self_access_idx(ObObjAccessIdx &self_access_idx, const ObPLBlockNS &ns) { int ret = OB_SUCCESS; const ObPLBlockNS *udt_routine_ns = ns.get_udt_routine_ns(); - - if (0 == access_idxs.count() // Element Access Without Prefix [SELF.] - && OB_NOT_NULL(udt_routine_ns) // In UDT Routine Namepspace - && OB_NOT_NULL(udt_routine_ns->get_symbol_table()->get_self_param())) { - - ObObjAccessIdx self_access_idx; - ObObjAccessIdx elem_access_idx; - - const ObUserDefinedType *self_user_type = NULL; + CK (OB_NOT_NULL(udt_routine_ns)); + CK (OB_NOT_NULL(udt_routine_ns->get_symbol_table()->get_self_param())); + if (OB_SUCC(ret)) { const ObPLVar *self_var = udt_routine_ns->get_symbol_table()->get_self_param(); ObPLDataType self_data_type = self_var->get_type(); int64_t self_index = udt_routine_ns->get_symbol_table()->get_self_param_idx(); - uint64_t user_type_id = udt_routine_ns->get_package_id(); // Construct A Self AccessIdx new (&self_access_idx) ObObjAccessIdx(self_data_type, @@ -14089,6 +14079,32 @@ int ObPLResolver::resolve_self_element_access(ObObjAccessIdent &access_ident, self_access_idx.get_sysfunc_, &resolve_ctx_.session_info_)); } + } + return ret; +} + +int ObPLResolver::resolve_self_element_access(ObObjAccessIdent &access_ident, + const ObPLBlockNS &ns, + ObIArray &access_idxs, + ObPLCompileUnitAST &func) +{ + int ret = OB_SUCCESS; + const ObPLBlockNS *udt_routine_ns = ns.get_udt_routine_ns(); + + if (0 == access_idxs.count() // Element Access Without Prefix [SELF.] + && OB_NOT_NULL(udt_routine_ns) // In UDT Routine Namepspace + && OB_NOT_NULL(udt_routine_ns->get_symbol_table()->get_self_param())) { + + ObObjAccessIdx self_access_idx; + ObObjAccessIdx elem_access_idx; + + const ObUserDefinedType *self_user_type = NULL; + const ObPLVar *self_var = udt_routine_ns->get_symbol_table()->get_self_param(); + ObPLDataType self_data_type = self_var->get_type(); + int64_t self_index = udt_routine_ns->get_symbol_table()->get_self_param_idx(); + uint64_t user_type_id = udt_routine_ns->get_package_id(); + + OZ (build_self_access_idx(self_access_idx, ns)); OZ (ns.get_pl_data_type_by_id(self_data_type.get_user_type_id(), self_user_type)); CK (OB_NOT_NULL(self_user_type)); OZ (self_user_type->get_all_depended_user_type(resolve_ctx_, ns)); @@ -14456,6 +14472,7 @@ int ObPLResolver::resolve_access_ident(ObObjAccessIdent &access_ident, // 当前 } } else if (ObPLExternalNS::INVALID_VAR == type || (ObPLExternalNS::SELF_ATTRIBUTE == type) + || (ObPLExternalNS::UDT_MEMBER_ROUTINE == type && is_routine) || (ObPLExternalNS::LOCAL_VAR == type && is_routine) || (ObPLExternalNS::TABLE_NS == type && is_routine) || (ObPLExternalNS::LABEL_NS == type && is_routine) @@ -14463,8 +14480,22 @@ int ObPLResolver::resolve_access_ident(ObObjAccessIdent &access_ident, // 当前 || (ObPLExternalNS::PKG_NS == type && is_routine) || (ObPLExternalNS::DBLINK_PKG_NS == type && is_routine)) { if (is_routine) { - OZ (resolve_routine(access_ident, ns, access_idxs, func), - K(access_ident), K(access_idxs)); + if (ObPLExternalNS::UDT_MEMBER_ROUTINE == type && access_idxs.empty()) { + ObObjAccessIdx self_access_idx; + ObSEArray tmp_access_idxs; + OZ (build_self_access_idx(self_access_idx, ns)); + OZ (tmp_access_idxs.push_back(self_access_idx)); + OZ (resolve_routine(access_ident, ns, tmp_access_idxs, func)); + if (OB_SUCC(ret)) { + int64_t i = (tmp_access_idxs.at(0) == self_access_idx) ? 1 : 0; + for (; OB_SUCC(ret) && i < tmp_access_idxs.count(); ++i) { + OZ (access_idxs.push_back(tmp_access_idxs.at(i))); + } + } + } else { + OZ (resolve_routine(access_ident, ns, access_idxs, func), + K(access_ident), K(access_idxs)); + } } else { // [self.]element, user can access element without self prefix, handle it in here. OZ (resolve_self_element_access(access_ident, ns, access_idxs, func), K(access_ident), K(access_idxs), K(type), K(is_routine)); diff --git a/src/pl/ob_pl_resolver.h b/src/pl/ob_pl_resolver.h index 99e88867d5..ce8a322a05 100644 --- a/src/pl/ob_pl_resolver.h +++ b/src/pl/ob_pl_resolver.h @@ -1151,6 +1151,7 @@ private: ObIArray &access_idxs, ObPLCompileUnitAST &func); + int build_self_access_idx(ObObjAccessIdx &self_access_idx, const ObPLBlockNS &ns); int build_current_access_idx(uint64_t parent_id, ObObjAccessIdx &access_idx, ObObjAccessIdent &access_ident, diff --git a/src/pl/ob_pl_stmt.cpp b/src/pl/ob_pl_stmt.cpp index 76ef232eba..e53fbbc950 100644 --- a/src/pl/ob_pl_stmt.cpp +++ b/src/pl/ob_pl_stmt.cpp @@ -2755,7 +2755,29 @@ int ObPLBlockNS::resolve_symbol(const ObString &var_name, type = ObPLExternalNS::LABEL_NS; } } - // 尝试匹配为父NS的VAR或者TYPE + // try routine + if (OB_SUCC(ret) && OB_INVALID_INDEX == var_idx && OB_INVALID_INDEX == parent_id) { + const ObIArray &routines = get_routines(); + for (int64_t i = 0; OB_SUCC(ret) && i < routines.count(); ++i) { + const ObPLRoutineInfo *routine = NULL; + OZ (get_routine_info(routines.at(i), routine)); + CK (OB_NOT_NULL(routine)); + if (OB_SUCC(ret) && 0 == routine->get_routine_name().case_compare(var_name)) { + if (get_block_type() != BLOCK_ROUTINE // subprogram is not member function, distingish with block type + && routine->is_udt_routine() && !routine->is_udt_cons() && !routine->is_udt_static_routine()) { + // only care about member routine without prefix. + type = ObPLExternalNS::UDT_MEMBER_ROUTINE; + var_idx = routine->get_routine_id(); + parent_id = routine->get_package_id(); + } else { + type = ObPLExternalNS::INVALID_VAR; + var_idx = routine->get_routine_id(); + parent_id = routine->get_package_id(); + } + } + } + } + // search to parent namespace, util to top parent, then try self and external symbol. if (OB_SUCC(ret) && OB_INVALID_INDEX == var_idx && OB_INVALID_INDEX == parent_id) { diff --git a/src/pl/ob_pl_stmt.h b/src/pl/ob_pl_stmt.h index 7414f05d77..5bc45fe3a0 100644 --- a/src/pl/ob_pl_stmt.h +++ b/src/pl/ob_pl_stmt.h @@ -1164,6 +1164,7 @@ public: PKG_TYPE, // 包中的自定义类型 SELF_ATTRIBUTE, DBLINK_PKG_NS, // dblink package + UDT_MEMBER_ROUTINE, // }; ObPLExternalNS(const ObPLResolveCtx &resolve_ctx, const ObPLBlockNS *parent_ns) diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index 7bf63048fe..9136829ed1 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -3643,6 +3643,7 @@ int ObSPIService::spi_cursor_open(ObPLExecCtx *ctx, // 如果当前cursor已经有spi_result则复用,避免内存占用过多 retry_ctrl.clear_state_before_each_retry(session_info->get_retry_info_for_update()); OZ (cursor->prepare_spi_result(ctx, spi_result)); + CK (OB_NOT_NULL(spi_result->get_memory_ctx())); OZ (spi_result->start_cursor_stmt(ctx, static_cast(type), for_update)); OZ ((GCTX.schema_service_->get_tenant_schema_guard(session_info->get_effective_tenant_id(), spi_result->get_scheme_guard()))); OX (spi_result->get_sql_ctx().schema_guard_ = &spi_result->get_scheme_guard()); @@ -3656,7 +3657,7 @@ int ObSPIService::spi_cursor_open(ObPLExecCtx *ctx, WITH_CONTEXT(cursor->get_cursor_entity()) { lib::ContextTLOptGuard guard(false); OZ (inner_open(ctx, - spi_result->get_allocaor(), + spi_result->get_memory_ctx()->get_arena_allocator(), sql, ps_sql, type, @@ -3670,7 +3671,7 @@ int ObSPIService::spi_cursor_open(ObPLExecCtx *ctx, } } else { ret = inner_open(ctx, - spi_result->get_allocaor(), + spi_result->get_memory_ctx()->get_arena_allocator(), sql, ps_sql, type, @@ -3769,6 +3770,7 @@ int ObSPIService::spi_cursor_open(ObPLExecCtx *ctx, spi_result.get_out_params().reset(); spi_result.reset_member_for_retry(*session_info); } + CK (OB_NOT_NULL(spi_result.get_memory_ctx())); OX (retry_ctrl.clear_state_before_each_retry(session_info->get_retry_info_for_update())); OZ ((GCTX.schema_service_->get_tenant_schema_guard(session_info->get_effective_tenant_id(), spi_result.get_scheme_guard()))); OX (spi_result.get_sql_ctx().schema_guard_ = &spi_result.get_scheme_guard()); @@ -3778,7 +3780,7 @@ int ObSPIService::spi_cursor_open(ObPLExecCtx *ctx, OX (retry_ctrl.set_sys_local_schema_version(sys_version)); OZ (inner_open(ctx, - spi_result.get_allocaor(), + spi_result.get_memory_ctx()->get_arena_allocator(), sql, ps_sql, type, @@ -6568,7 +6570,7 @@ int ObSPIService::inner_open(ObPLExecCtx *ctx, // add exec_param_info for sql_audit char *tmp_ptr = NULL; int64_t tmp_len = 0; - OZ (ObMPStmtExecute::store_params_value_to_str(spi_result.get_allocaor(), + OZ (ObMPStmtExecute::store_params_value_to_str(spi_result.get_memory_ctx()->get_arena_allocator(), *ctx->exec_ctx_->get_my_session(), &exec_params, tmp_ptr,