From 543a6309afb2dffebdecdda0eec6d7bd8d592f17 Mon Sep 17 00:00:00 2001 From: Azipro <532789173@qq.com> Date: Sat, 15 Mar 2025 13:16:10 +0000 Subject: [PATCH] fix ref cst id of foreign key when rebuild hidden table --- src/rootserver/ob_ddl_service.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index ab096990ea..111f3b107f 100755 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -22312,7 +22312,8 @@ int ObDDLService::rebuild_hidden_table_foreign_key( LOG_WARN("failed to fetch new foreign key id", K(ret), K(tenant_id)); } else if (original_fk_info.parent_table_id_ == orig_table_schema.get_table_id()) { // update referenced constraint id - if (FK_REF_TYPE_PRIMARY_KEY == foreign_key_info.fk_ref_type_) { + if (FK_REF_TYPE_PRIMARY_KEY == foreign_key_info.fk_ref_type_ || + (FK_REF_TYPE_NON_UNIQUE_KEY == foreign_key_info.fk_ref_type_ && !orig_table_schema.is_index_table())) { if (is_oracle_mode) { const ObConstraint *pk_cst = hidden_table_schema.get_pk_constraint(); if (OB_ISNULL(pk_cst)) { @@ -22322,7 +22323,11 @@ int ObDDLService::rebuild_hidden_table_foreign_key( foreign_key_info.ref_cst_id_ = pk_cst->get_constraint_id(); } } else { - foreign_key_info.ref_cst_id_ = common::OB_INVALID_ID; + if (FK_REF_TYPE_PRIMARY_KEY == foreign_key_info.fk_ref_type_) { + foreign_key_info.ref_cst_id_ = common::OB_INVALID_ID; + } else if (FK_REF_TYPE_NON_UNIQUE_KEY == foreign_key_info.fk_ref_type_) { + foreign_key_info.ref_cst_id_ = hidden_table_schema.get_table_id(); + } } } else { const ObSimpleTableSchemaV2 *orig_index_table_schema = NULL;