diff --git a/src/pl/ob_pl.cpp b/src/pl/ob_pl.cpp index 997a5bda7..559436eb3 100644 --- a/src/pl/ob_pl.cpp +++ b/src/pl/ob_pl.cpp @@ -2579,11 +2579,6 @@ int ObPLExecState::set_var(int64_t var_idx, const ObObjParam& value) OZ (ctx_.get_user_type(udt_id, user_type), K(udt_id)); CK (OB_NOT_NULL(user_type)); OZ (init_complex_obj(*get_allocator(), *user_type, params->at(var_idx))); - if (OB_SUCC(ret) && user_type->is_collection_type()) { - ObPLCollection *coll = reinterpret_cast(params->at(var_idx).get_ext()); - CK (OB_NOT_NULL(coll)); - OX (coll->set_count(OB_INVALID_COUNT)); - } } } else if (!copy_value.is_ext()) { bool is_ref_cursor = params->at(var_idx).is_ref_cursor_type(); @@ -2843,6 +2838,7 @@ int ObPLExecState::init_complex_obj(ObIAllocator &allocator, common::ObMySQLProxy *sql_proxy = NULL; ObPLPackageGuard *package_guard = NULL; const ObPLDataType *real_pl_type = &pl_type; + bool set_null = pl_type.is_record_type() ? true : (top_call_ && ctx_.exec_ctx_->get_sql_ctx()->is_execute_call_stmt_) ? false : true; CK (OB_NOT_NULL(session = ctx_.exec_ctx_->get_my_session())); CK (OB_NOT_NULL(schema_guard = ctx_.exec_ctx_->get_sql_ctx()->schema_guard_)); CK (OB_NOT_NULL(sql_proxy = ctx_.exec_ctx_->get_sql_proxy())); @@ -2883,12 +2879,12 @@ int ObPLExecState::init_complex_obj(ObIAllocator &allocator, OX (obj.set_is_ref_cursor_type(true)); } else if (real_pl_type->is_udt_type()) { ObPLUDTNS ns(*schema_guard); - OZ (ns.init_complex_obj(allocator, *real_pl_type, obj, false)); + OZ (ns.init_complex_obj(allocator, *real_pl_type, obj, false, set_null)); } else if (OB_NOT_NULL(session->get_pl_context()) && OB_NOT_NULL(session->get_pl_context()->get_current_ctx())) { pl::ObPLINS *ns = session->get_pl_context()->get_current_ctx(); CK (OB_NOT_NULL(ns)); - OZ (ns->init_complex_obj(allocator, *real_pl_type, obj, false)); + OZ (ns->init_complex_obj(allocator, *real_pl_type, obj, false, set_null)); } else { ObPLResolveCtx ns(allocator, *session, @@ -2896,7 +2892,7 @@ int ObPLExecState::init_complex_obj(ObIAllocator &allocator, *package_guard, *sql_proxy, false); - OZ (ns.init_complex_obj(allocator, *real_pl_type, obj, false)); + OZ (ns.init_complex_obj(allocator, *real_pl_type, obj, false, set_null)); } OX (obj.set_udt_id(real_pl_type->get_user_type_id())); return ret; @@ -4230,7 +4226,7 @@ int ObPLINS::init_complex_obj(ObIAllocator &allocator, const ObPLDataType &pl_type, common::ObObjParam &obj, bool set_allocator, - bool set_record_null) const + bool set_null) const { int ret = OB_SUCCESS; int64_t init_size = 0; @@ -4276,7 +4272,7 @@ int ObPLINS::init_complex_obj(ObIAllocator &allocator, } // f(self object_type, p1 out object_type), p1 will be init here, we have to set it null // but self can't be set to null. - if (OB_SUCC(ret) && user_type->is_object_type() && set_record_null) { + if (OB_SUCC(ret) && user_type->is_object_type() && set_null) { OX (record->set_is_null(true)); } } @@ -4316,10 +4312,12 @@ int ObPLINS::init_complex_obj(ObIAllocator &allocator, CK (OB_NOT_NULL(coll)); OX (set_allocator ? coll->set_allocator(&allocator) : coll->set_allocator(NULL)); if (OB_FAIL(ret)) { - } else if (user_type->is_associative_array_type()) { - coll->set_inited(); - } else { - OX ((obj.is_ext() && obj.get_ext() != 0) ? (void)NULL : coll->set_inited()); + } else if (!set_null) { + if (user_type->is_associative_array_type()) { + OX (coll->set_inited()); + } else { + OX ((obj.is_ext() && obj.get_ext() != 0) ? (void)NULL : coll->set_inited()); + } } OX (coll->set_type(pl_type.get_type())); OZ (get_element_data_type(pl_type, elem_desc, &allocator)); diff --git a/src/pl/ob_pl.h b/src/pl/ob_pl.h index 5433b3124..196c3bb28 100644 --- a/src/pl/ob_pl.h +++ b/src/pl/ob_pl.h @@ -134,7 +134,7 @@ public: const ObPLDataType &pl_type, common::ObObjParam &obj, bool set_allocator = false, - bool set_record_null = true) const; + bool set_null = true) const; }; class ObPLFunctionBase diff --git a/src/pl/ob_pl_resolver.cpp b/src/pl/ob_pl_resolver.cpp index d042ca481..920be29e4 100644 --- a/src/pl/ob_pl_resolver.cpp +++ b/src/pl/ob_pl_resolver.cpp @@ -15220,13 +15220,16 @@ int ObPLResolver::resolve_cursor(ObPLCompileUnitAST &func, } if (OB_SUCC(ret) && OB_ISNULL(package_info)) { ObSchemaChecker checker; - ObSEArray syn_id_array; + ObSynonymChecker synonym_checker; ObString new_package_name; + bool is_exist = false; OZ (checker.init(resolve_ctx_.schema_guard_, resolve_ctx_.session_info_.get_sessid())); - OZ (checker.get_obj_info_recursively_with_synonym( - tenant_id, database_id, package_name, database_id, new_package_name, syn_id_array, true)); - OZ (resolve_ctx_.schema_guard_.get_package_info( - tenant_id, database_id, new_package_name, PACKAGE_TYPE, compatible_mode, package_info)); + OZ (ObResolverUtils::resolve_synonym_object_recursively( + checker, synonym_checker, tenant_id, database_id, package_name, database_id, new_package_name, is_exist)); + if (OB_SUCC(ret) && is_exist) { + OZ (resolve_ctx_.schema_guard_.get_package_info( + tenant_id, database_id, new_package_name, PACKAGE_TYPE, compatible_mode, package_info)); + } if (OB_SUCC(ret) && OB_ISNULL(package_info) && OB_SYS_DATABASE_ID == database_id) { OZ (resolve_ctx_.schema_guard_.get_package_info( diff --git a/src/pl/ob_pl_type.cpp b/src/pl/ob_pl_type.cpp index 7fdf0ae6f..41270b050 100644 --- a/src/pl/ob_pl_type.cpp +++ b/src/pl/ob_pl_type.cpp @@ -614,7 +614,7 @@ int ObPLDataType::get_datum_type(common::ObObjType obj_type, jit::ObLLVMHelper& } int ObPLDataType::generate_assign_with_null(ObPLCodeGenerator &generator, - const ObPLBlockNS &ns, + const ObPLINS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const { @@ -624,7 +624,7 @@ int ObPLDataType::generate_assign_with_null(ObPLCodeGenerator &generator, LOG_WARN("unexpected type to assign NULL", K(*this), K(ret)); } else { const ObUserDefinedType *user_type = NULL; - if (OB_FAIL(ns.get_pl_data_type_by_id(get_user_type_id(), user_type))) { + if (OB_FAIL(ns.get_user_type(get_user_type_id(), user_type))) { LOG_WARN("failed to get user type", K(*this), K(ret)); } else if (OB_ISNULL(user_type)) { ret = OB_ERR_UNEXPECTED; diff --git a/src/pl/ob_pl_type.h b/src/pl/ob_pl_type.h index d0e21ca2b..e6f8e3546 100644 --- a/src/pl/ob_pl_type.h +++ b/src/pl/ob_pl_type.h @@ -484,7 +484,7 @@ public: static int get_datum_type(common::ObObjType obj_type, jit::ObLLVMHelper& helper, ObPLADTService &adt_service, jit::ObLLVMType &type); virtual int generate_assign_with_null(ObPLCodeGenerator &generator, - const ObPLBlockNS &ns, + const ObPLINS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const; virtual int generate_default_value(ObPLCodeGenerator &generator, diff --git a/src/pl/ob_pl_user_type.cpp b/src/pl/ob_pl_user_type.cpp index 19966bc92..45df61046 100644 --- a/src/pl/ob_pl_user_type.cpp +++ b/src/pl/ob_pl_user_type.cpp @@ -51,7 +51,7 @@ const ObPLDataType *ObUserDefinedType::get_member(int64_t i) const int ObUserDefinedType::generate_assign_with_null( ObPLCodeGenerator &generator, - const ObPLBlockNS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const + const ObPLINS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const { UNUSEDx(generator, ns, allocator, dest); return OB_SUCCESS; } @@ -1016,7 +1016,7 @@ int ObRecordType::deep_copy( } int ObRecordType::generate_assign_with_null(ObPLCodeGenerator &generator, - const ObPLBlockNS &ns, + const ObPLINS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const { @@ -1194,27 +1194,58 @@ int ObRecordType::generate_default_value(ObPLCodeGenerator &generator, } if (OB_SUCC(ret)) { ptr_elem.reset(); - if (member->member_type_.is_obj_type() || OB_INVALID_INDEX != member->get_default()) { + OZ (generator.extract_element_ptr_from_record(value, + get_record_member_count(), + i, + ptr_elem)); + if (OB_FAIL(ret)) { + } else if (member->member_type_.is_obj_type() || OB_INVALID_INDEX != member->get_default()) { //不论基础类型还是复杂类型,如果有default,直接把default值存入即可 - OZ (generator.extract_element_ptr_from_record(value, - get_record_member_count(), - i, - ptr_elem)); OZ (generator.get_helper().create_store(obobj_res, ptr_elem)); OZ (generator.generate_check_not_null(*stmt, member->member_type_.get_not_null(), result)); - } else { //复杂类型如果没有default,调用generate_construct + if (OB_SUCC(ret) && !member->member_type_.is_obj_type()) { // process complex null value + ObLLVMBasicBlock null_branch; + ObLLVMBasicBlock final_branch; + ObLLVMValue p_type_value; + ObLLVMValue type_value; + ObLLVMValue is_null; + ObLLVMValue allocator; + ObLLVMValue extend_value; + ObLLVMValue init_value; + ObLLVMValue composite_value; + ObLLVMType ir_type; + ObLLVMType ir_pointer_type; + int64_t init_size = OB_INVALID_SIZE; + OZ (generator.get_helper().create_block(ObString("null_branch"), generator.get_func(), null_branch)); + OZ (generator.get_helper().create_block(ObString("final_branch"), generator.get_func(), final_branch)); + OZ (generator.extract_type_ptr_from_objparam(result, p_type_value)); + OZ (generator.get_helper().create_load(ObString("load_type"), p_type_value, type_value)); + OZ (generator.get_helper().create_icmp_eq(type_value, ObNullType, is_null)); + OZ (generator.get_helper().create_cond_br(is_null, null_branch, final_branch)); + // null branch + OZ (generator.set_current(null_branch)); + OZ (SMART_CALL(member->member_type_.generate_new(generator, ns, extend_value, stmt))); + OZ (generator.get_helper().get_int8(member->member_type_.get_type(), type_value)); + OZ (member->member_type_.get_size(ns, PL_TYPE_INIT_SIZE, init_size)); + OZ (generator.get_helper().get_int32(init_size, init_value)); + OZ (generator.generate_set_extend(ptr_elem, type_value, init_value, extend_value)); + OZ (generator.generate_null(ObIntType, allocator)); + OZ (generator.get_llvm_type(member->member_type_, ir_type)); + OZ (ir_type.get_pointer_to(ir_pointer_type)); + OZ (generator.get_helper().create_int_to_ptr(ObString("cast_extend_to_ptr"), extend_value, ir_pointer_type, composite_value)); + OZ (member->member_type_.generate_assign_with_null(generator, ns, allocator, composite_value)); + OZ (generator.get_helper().create_br(final_branch)); + // final branch + OZ (generator.set_current(final_branch)); + } + } else { //复杂类型如果没有default,调用generate_new ObLLVMValue extend_value; ObLLVMValue type_value; ObLLVMValue init_value; int64_t init_size = OB_INVALID_SIZE; - OZ (generator.extract_element_ptr_from_record(value, - get_record_member_count(), - i, - ptr_elem)); OZ (SMART_CALL(member->member_type_.generate_new(generator, ns, extend_value, stmt))); - OZ (generator.get_helper().get_int8(member->member_type_.get_type(), type_value)); OZ (member->member_type_.get_size(ns, PL_TYPE_INIT_SIZE, init_size)); OZ (generator.get_helper().get_int32(init_size, init_value)); @@ -1939,7 +1970,7 @@ int ObCollectionType::get_size(const ObPLINS &ns, ObPLTypeSize type, int64_t &si } int ObCollectionType::generate_assign_with_null(ObPLCodeGenerator &generator, - const ObPLBlockNS &ns, + const ObPLINS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const { @@ -1951,7 +1982,7 @@ int ObCollectionType::generate_assign_with_null(ObPLCodeGenerator &generator, ObLLVMType int_type; ObLLVMValue int_value; - if (generator.get_helper().get_llvm_type(ObIntType, int_type)) { + if (OB_FAIL(generator.get_helper().get_llvm_type(ObIntType, int_type))) { LOG_WARN("failed to get_llvm_type", K(ret)); } else if (OB_FAIL(generator.get_helper().create_ptr_to_int(ObString("cast_ptr_to_int64"), dest, int_type, int_value))) { diff --git a/src/pl/ob_pl_user_type.h b/src/pl/ob_pl_user_type.h index 7ee6b87a9..b8e492714 100644 --- a/src/pl/ob_pl_user_type.h +++ b/src/pl/ob_pl_user_type.h @@ -64,7 +64,7 @@ public: virtual int64_t get_member_count() const; virtual const ObPLDataType *get_member(int64_t i) const; virtual int generate_assign_with_null( - ObPLCodeGenerator &generator, const ObPLBlockNS &ns, + ObPLCodeGenerator &generator, const ObPLINS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const; virtual int generate_default_value( ObPLCodeGenerator &generator,const ObPLINS &ns, @@ -240,9 +240,10 @@ public: virtual int64_t get_member_count() const { return 0; } virtual const ObPLDataType *get_member(int64_t i) const { UNUSED(i); return NULL; } virtual int generate_assign_with_null(ObPLCodeGenerator &generator, - jit::ObLLVMValue &allocator, - jit::ObLLVMValue &dest) const - { UNUSED(generator); UNUSED(allocator); UNUSED(dest); return OB_SUCCESS;} + ObPLINS &ns, + jit::ObLLVMValue &allocator, + jit::ObLLVMValue &dest) const + { UNUSED(generator); UNUSED(ns), UNUSED(allocator); UNUSED(dest); return OB_SUCCESS;} virtual int generate_construct(ObPLCodeGenerator &generator, const ObPLINS &ns, jit::ObLLVMValue &value, @@ -391,7 +392,7 @@ public: virtual const ObPLDataType *get_member(int64_t i) const { return get_record_member_type(i); } virtual int generate_assign_with_null(ObPLCodeGenerator &generator, - const ObPLBlockNS &ns, + const ObPLINS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const; @@ -549,13 +550,13 @@ public: jit::ObLLVMValue &value, const pl::ObPLStmt *stmt = NULL) const; virtual int generate_assign_with_null(ObPLCodeGenerator &generator, - const ObPLBlockNS &ns, + const ObPLINS &ns, jit::ObLLVMValue &allocator, jit::ObLLVMValue &dest) const; virtual int generate_new(ObPLCodeGenerator &generator, - const ObPLINS &ns, - jit::ObLLVMValue &value, - const pl::ObPLStmt *s = NULL) const; + const ObPLINS &ns, + jit::ObLLVMValue &value, + const pl::ObPLStmt *s = NULL) const; virtual int newx(common::ObIAllocator &allocator, const ObPLINS *ns, int64_t &ptr) const; diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index cc7f23621..d20bf3002 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -1657,7 +1657,7 @@ int ObSPIService::spi_inner_execute(ObPLExecCtx *ctx, out_params, &retry_ctrl, is_forall))) { - LOG_WARN("failed to open", K(type), K(ret)); + LOG_WARN("failed to open", K(ret), K(sql), K(ps_sql)); } else if (OB_FAIL(inner_fetch(ctx, retry_ctrl, spi_result, @@ -5261,7 +5261,7 @@ int ObSPIService::spi_delete_collection(pl::ObPLExecCtx *ctx, if (*key1 <= *key2) { for (int64_t i = 0; OB_SUCC(ret) && i < atable->get_count(); ++i) { bool flag = key!=NULL ? (key[i] >= *key1 && key[i] <= *key2) - : (i >= key1->get_int32() && i <= key2->get_int32()); + : (i+1 >= key1->get_int32() && i+1 <= key2->get_int32()); if (flag) { OZ (atable->delete_collection_elem(i)); if (atable->get_first() - 1 == i) { @@ -6362,7 +6362,7 @@ int ObSPIService::inner_open(ObPLExecCtx *ctx, if (NULL == sql) { OZ (construct_exec_params(ctx, param_allocator, param_exprs, param_count, into_exprs, into_count, exec_params, out_params, is_forall), - K(sql), K(type), K(param_count), K(out_params), K(exec_params)); + K(sql), K(ps_sql), K(type), K(param_count), K(out_params), K(exec_params)); if (OB_SUCC(ret) && OB_NOT_NULL(ctx) && OB_NOT_NULL(ctx->exec_ctx_)