From 2b93405b74e7f1006c44a88358b57cd27d1f898a Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 3 Apr 2023 23:11:16 +0000 Subject: [PATCH] to issue<48456442>:fix dml stmt with udt hit plan issue --- src/pl/ob_pl_resolver.cpp | 13 +++++ src/sql/resolver/dml/ob_dml_resolver.cpp | 24 +++++++++ src/sql/resolver/expr/ob_raw_expr.cpp | 27 ++++++++++ src/sql/resolver/expr/ob_raw_expr.h | 65 +++++++++++++++++++++--- 4 files changed, 123 insertions(+), 6 deletions(-) diff --git a/src/pl/ob_pl_resolver.cpp b/src/pl/ob_pl_resolver.cpp index e6ceec154b..f52ec42125 100644 --- a/src/pl/ob_pl_resolver.cpp +++ b/src/pl/ob_pl_resolver.cpp @@ -9643,6 +9643,11 @@ int ObPLResolver::resolve_record_construct(const ObQualifiedName &q_name, ObObjectConstructRawExpr *object_expr = NULL; ObExprResType res_type; int64_t rowsize = 0; + const ObUDTTypeInfo *udt_info = NULL; + uint64_t tenant_id = OB_INVALID_ID; + bool is_udt_type = false; + CK (OB_NOT_NULL(user_type)); + OX (is_udt_type = user_type->is_udt_type()); CK (OB_NOT_NULL(udf_info.ref_expr_)); CK (OB_NOT_NULL(object_type = static_cast(user_type))); if (OB_SUCC(ret) && udf_info.param_names_.count() > 0) { // 构造函数暂时不允许使用=>赋值 @@ -9676,6 +9681,14 @@ int ObPLResolver::resolve_record_construct(const ObQualifiedName &q_name, OX (res_type.set_udt_id(user_type->get_user_type_id())); OX (object_expr->set_udt_id(user_type->get_user_type_id())); OX (object_expr->set_result_type(res_type)); + if (is_udt_type) { + OX (tenant_id = get_tenant_id_by_object_id(user_type->get_user_type_id())); + OZ (resolve_ctx_.schema_guard_.get_udt_info( + tenant_id, user_type->get_user_type_id(), udt_info)); + CK (OB_NOT_NULL(udt_info)); + OX (object_expr->set_database_id(udt_info->get_database_id())); + OX (object_expr->set_coll_schema_version(udt_info->get_schema_version())); + } for (int64_t i = 0; OB_SUCC(ret) && i < object_type->get_member_count(); ++i) { const ObPLDataType *pl_type = object_type->get_record_member_type(i); ObExprResType elem_type; diff --git a/src/sql/resolver/dml/ob_dml_resolver.cpp b/src/sql/resolver/dml/ob_dml_resolver.cpp index 05fd31ae66..6c84a9860d 100755 --- a/src/sql/resolver/dml/ob_dml_resolver.cpp +++ b/src/sql/resolver/dml/ob_dml_resolver.cpp @@ -10125,6 +10125,30 @@ int ObDMLResolver::resolve_external_name(ObQualifiedName &q_name, //the flag will change to false; OX (expr->set_is_called_in_sql(true)); } + } else if (T_FUN_PL_OBJECT_CONSTRUCT == expr->get_expr_type()) { + ObDMLStmt *stmt = get_stmt(); + ObObjectConstructRawExpr *object_expr = static_cast(expr); + CK (OB_NOT_NULL(object_expr)); + CK (OB_NOT_NULL(stmt)); + if (OB_SUCC(ret) && object_expr->need_add_dependency()) { + uint64_t dep_obj_id = view_ref_id_; + ObSchemaObjVersion coll_schema_version; + OZ (object_expr->get_schema_object_version(coll_schema_version)); + OZ (stmt->add_global_dependency_table(coll_schema_version)); + OZ (stmt->add_ref_obj_version(dep_obj_id, object_expr->get_database_id(), ObObjectType::VIEW, coll_schema_version, *allocator_)); + } + } else if (T_FUN_PL_COLLECTION_CONSTRUCT == expr->get_expr_type()) { + ObDMLStmt *stmt = get_stmt(); + ObCollectionConstructRawExpr *coll_expr = static_cast(expr); + CK (OB_NOT_NULL(coll_expr)); + CK (OB_NOT_NULL(stmt)); + if (OB_SUCC(ret) && coll_expr->need_add_dependency()) { + uint64_t dep_obj_id = view_ref_id_; + ObSchemaObjVersion coll_schema_version; + OZ (coll_expr->get_schema_object_version(coll_schema_version)); + OZ (stmt->add_global_dependency_table(coll_schema_version)); + OZ (stmt->add_ref_obj_version(dep_obj_id, coll_expr->get_database_id(), ObObjectType::VIEW, coll_schema_version, *allocator_)); + } } } if (OB_ERR_SP_UNDECLARED_VAR == ret) { diff --git a/src/sql/resolver/expr/ob_raw_expr.cpp b/src/sql/resolver/expr/ob_raw_expr.cpp index 3b7ff55316..dc054336ed 100644 --- a/src/sql/resolver/expr/ob_raw_expr.cpp +++ b/src/sql/resolver/expr/ob_raw_expr.cpp @@ -4192,6 +4192,18 @@ int ObCollectionConstructRawExpr::set_access_names( return ret; } +int ObCollectionConstructRawExpr::get_schema_object_version(share::schema::ObSchemaObjVersion &obj_version) +{ + int ret = OB_SUCCESS; + CK (coll_schema_version_ != OB_INVALID_VERSION); + CK (udt_id_ != common::OB_INVALID_ID); + OX (obj_version.object_id_ = udt_id_); + OX (obj_version.object_type_ = share::schema::DEPENDENCY_FUNCTION); + OX (obj_version.version_ = coll_schema_version_); + + return ret; +} + int ObCollectionConstructRawExpr::assign(const ObRawExpr &other) { int ret = OB_SUCCESS; @@ -4209,6 +4221,7 @@ int ObCollectionConstructRawExpr::assign(const ObRawExpr &other) capacity_ = tmp.capacity_; udt_id_ = tmp.udt_id_; elem_type_ = tmp.elem_type_; + coll_schema_version_ = tmp.coll_schema_version_; if (OB_FAIL(access_names_.assign(tmp.access_names_))) { LOG_WARN("failed to assign access names", K(ret)); } @@ -4272,6 +4285,19 @@ ObExprOperator *ObCollectionConstructRawExpr::get_op() return OB_SUCCESS == ret ? expr_op : NULL; } +int ObObjectConstructRawExpr::get_schema_object_version(share::schema::ObSchemaObjVersion &obj_version) +{ + int ret = OB_SUCCESS; + CK (object_schema_version_ != OB_INVALID_VERSION); + CK (udt_id_ != common::OB_INVALID_ID); + OX (obj_version.object_id_ = udt_id_); + OX (obj_version.object_type_ = share::schema::DEPENDENCY_FUNCTION); + OX (obj_version.version_ = object_schema_version_); + + return ret; +} + + int ObObjectConstructRawExpr::set_access_names( const common::ObIArray &access_idents) { @@ -4297,6 +4323,7 @@ int ObObjectConstructRawExpr::assign(const ObRawExpr &other) static_cast(other); rowsize_ = tmp.rowsize_; udt_id_ = tmp.udt_id_; + object_schema_version_ = tmp.object_schema_version_; if (OB_FAIL(elem_types_.assign(tmp.elem_types_))) { LOG_WARN("failed to assign elem types", K(ret)); } else if (OB_FAIL(access_names_.assign(tmp.access_names_))) { diff --git a/src/sql/resolver/expr/ob_raw_expr.h b/src/sql/resolver/expr/ob_raw_expr.h index 1e4f699ed2..e8c6ca9d4f 100644 --- a/src/sql/resolver/expr/ob_raw_expr.h +++ b/src/sql/resolver/expr/ob_raw_expr.h @@ -3439,13 +3439,17 @@ public: type_(pl::ObPLType::PL_INVALID_TYPE), elem_type_(), capacity_(OB_INVALID_SIZE), - udt_id_(OB_INVALID_ID) {} + udt_id_(OB_INVALID_ID), + database_id_(OB_INVALID_ID), + coll_schema_version_(common::OB_INVALID_VERSION) {} ObCollectionConstructRawExpr() : ObSysFunRawExpr(), type_(pl::ObPLType::PL_INVALID_TYPE), elem_type_(), capacity_(OB_INVALID_SIZE), - udt_id_(OB_INVALID_ID) {} + udt_id_(OB_INVALID_ID), + database_id_(OB_INVALID_ID), + coll_schema_version_(common::OB_INVALID_VERSION) {} virtual ~ObCollectionConstructRawExpr() {} inline void set_type(pl::ObPLType type) { type_ = type; } @@ -3467,12 +3471,32 @@ public: virtual ObExprOperator *get_op() override; + inline void set_database_id(int64_t database_id) + { + database_id_ = database_id; + } + + OB_INLINE uint64_t get_database_id() const { return database_id_; } + + inline void set_coll_schema_version(int64_t schema_version) + { + coll_schema_version_ = schema_version; + } + + inline bool need_add_dependency() + { + return coll_schema_version_ != common::OB_INVALID_VERSION; + } + + int get_schema_object_version(share::schema::ObSchemaObjVersion &obj_version); + VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_, N_FUNC, get_func_name(), - N_CHILDREN, exprs_); + N_CHILDREN, exprs_, + K_(coll_schema_version)); private: pl::ObPLType type_; // PL_NESTED_TABLE_TYPE|PL_ASSOCIATIVE_ARRAY_TYPE|PL_VARRAY_TYPE pl::ObPLDataType elem_type_; // 记录复杂数据类型的元素类型 @@ -3480,6 +3504,8 @@ private: uint64_t udt_id_; // 记录复杂类型的ID // 用于打印构造函数的名字 common::ObSEArray access_names_; + int64_t database_id_; + int64_t coll_schema_version_; }; class ObObjectConstructRawExpr : public ObSysFunRawExpr @@ -3490,13 +3516,17 @@ public: rowsize_(0), udt_id_(OB_INVALID_ID), elem_types_(), - access_names_() {} + access_names_(), + database_id_(OB_INVALID_ID), + object_schema_version_(common::OB_INVALID_VERSION) {} ObObjectConstructRawExpr() : ObSysFunRawExpr(), rowsize_(0), udt_id_(OB_INVALID_ID), elem_types_(), - access_names_() {} + access_names_(), + database_id_(OB_INVALID_ID), + object_schema_version_(common::OB_INVALID_VERSION) {} virtual ~ObObjectConstructRawExpr() {} @@ -3526,6 +3556,25 @@ public: int assign(const ObRawExpr &other) override; int inner_deep_copy(ObIRawExprCopier &copier) override; + inline void set_database_id(int64_t database_id) + { + database_id_ = database_id; + } + + OB_INLINE uint64_t get_database_id() const { return database_id_; } + + inline void set_coll_schema_version(int64_t schema_version) + { + object_schema_version_ = schema_version; + } + + inline bool need_add_dependency() + { + return object_schema_version_ != common::OB_INVALID_VERSION; + } + + int get_schema_object_version(share::schema::ObSchemaObjVersion &obj_version); + virtual ObExprOperator *get_op() override; VIRTUAL_TO_STRING_KV_CHECK_STACK_OVERFLOW(N_ITEM_TYPE, type_, @@ -3533,7 +3582,9 @@ public: N_EXPR_INFO, info_, N_REL_ID, rel_ids_, N_FUNC, get_func_name(), - N_CHILDREN, exprs_); + N_CHILDREN, exprs_, + K_(database_id), + K_(object_schema_version)); private: int64_t rowsize_; uint64_t udt_id_; @@ -3541,6 +3592,8 @@ private: common::ObSEArray elem_types_; // 用于打印构造函数的名字 common::ObSEArray access_names_; + int64_t database_id_; + int64_t object_schema_version_; }; class ObUDFParamDesc