From aa294d3a7a7be35e445ecf4d8f1867d782e7a602 Mon Sep 17 00:00:00 2001 From: Hongqin-Li Date: Wed, 1 Jan 2025 22:46:36 +0000 Subject: [PATCH] Fix drop other table's unique constraint --- src/rootserver/ob_ddl_service.cpp | 7 +++++++ src/rootserver/ob_index_builder.cpp | 15 ++++++++++++++- src/storage/ddl/ob_ddl_lock.cpp | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index e7a3fda8a..dac738f0e 100755 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -8367,6 +8367,7 @@ int ObDDLService::get_index_schema_by_name( ObArenaAllocator allocator(ObModIds::OB_SCHEMA); const ObString &index_name = drop_index_arg.index_name_; const bool is_mlog = (obrpc::ObIndexArg::DROP_MLOG == drop_index_arg.index_action_type_); + index_table_schema = nullptr; //build index name and get index schema if (is_mlog) { @@ -8390,6 +8391,12 @@ int ObDDLService::get_index_schema_by_name( LOG_USER_ERROR(OB_ERR_CANT_DROP_FIELD_OR_KEY, index_name.length(), index_name.ptr()); LOG_WARN("get index table schema failed", K(tenant_id), K(database_id), K(index_table_name), K(ret)); + } else if (is_index && data_table_id != index_table_schema->get_data_table_id()) { + ret = OB_ERR_CANT_DROP_FIELD_OR_KEY; + LOG_USER_ERROR(OB_ERR_CANT_DROP_FIELD_OR_KEY, index_name.length(), index_name.ptr()); + LOG_WARN("get index table schema failed", K(ret), K(tenant_id), + K(database_id), K(index_table_name), K(index_table_schema->get_table_id()), K(ret)); + index_table_schema = nullptr; } else if (index_table_schema->is_in_recyclebin()) { ret = OB_ERR_OPERATION_ON_RECYCLE_OBJECT; LOG_WARN("index table is in recyclebin", K(ret)); diff --git a/src/rootserver/ob_index_builder.cpp b/src/rootserver/ob_index_builder.cpp index 9e2def043..f37b6f323 100644 --- a/src/rootserver/ob_index_builder.cpp +++ b/src/rootserver/ob_index_builder.cpp @@ -443,8 +443,21 @@ int ObIndexBuilder::drop_index(const ObDropIndexArg &const_arg, obrpc::ObDropInd } if (OB_SUCC(ret) && !has_other_domain_index) { bool has_exist = false; + const ObTableSchema *data_table_schema = nullptr; const ObTableSchema &new_index_schema = new_index_schemas.at(new_index_schemas.count() - 1); - if (OB_FAIL(submit_drop_index_task(trans, *table_schema, new_index_schemas, arg, nullptr/*inc_data_tablet_ids*/, + if (is_mlog && table_schema->is_materialized_view() && table_schema->get_table_id() != new_index_schema.get_data_table_id()) { + // drop mlog on mview + if (OB_FAIL(schema_guard.get_table_schema(tenant_id, new_index_schema.get_data_table_id(), data_table_schema))) { + LOG_WARN("fail to get index table schema", K(ret), K(tenant_id), K(arg.index_table_id_)); + } else if (OB_ISNULL(data_table_schema)) { + ret = OB_TABLE_NOT_EXIST; + LOG_WARN("table not found", K(ret), K(arg)); + } + } else { + data_table_schema = table_schema; + } + if (OB_FAIL(ret)) { + } else if (OB_FAIL(submit_drop_index_task(trans, *data_table_schema, new_index_schemas, arg, nullptr/*inc_data_tablet_ids*/, nullptr/*del_data_tablet_ids*/, allocator, has_exist, task_record))) { LOG_WARN("submit drop index task failed", K(ret), K(task_record)); } else if (has_exist) { diff --git a/src/storage/ddl/ob_ddl_lock.cpp b/src/storage/ddl/ob_ddl_lock.cpp index 31f3e4ef8..01b1d0cd3 100644 --- a/src/storage/ddl/ob_ddl_lock.cpp +++ b/src/storage/ddl/ob_ddl_lock.cpp @@ -92,9 +92,9 @@ int ObDDLLock::lock_for_add_drop_index( const int64_t timeout_us = DEFAULT_TIMEOUT; ObSEArray data_tablet_ids; ObInnerSQLConnection *iconn = nullptr; - if (data_table_schema.is_user_hidden_table()) { + if (OB_UNLIKELY(data_table_schema.is_user_hidden_table() || data_table_id != index_schema.get_data_table_id())) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("lock for rebuild hidden table index", K(ret)); + LOG_WARN("lock for rebuild hidden table index", K(ret), K(tenant_id), K(data_table_id), K(index_table_id), K(index_schema.get_data_table_id())); } else if (!need_lock(data_table_schema)) { LOG_INFO("skip ddl lock", K(data_table_id)); } else {