From 7da7fe8b1b4593f01a1897dfcc119ef0ed12769e Mon Sep 17 00:00:00 2001 From: Hongqin-Li Date: Mon, 3 Apr 2023 20:45:09 +0000 Subject: [PATCH] Fix unavailable hidden table index after ddl --- src/rootserver/ob_ddl_service.cpp | 64 ++++++++++++++++++------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index fca20cbf26..01bbc34254 100644 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -14313,33 +14313,43 @@ int ObDDLService::rebuild_hidden_table_index(obrpc::ObAlterTableArg &alter_table orig_table_schema, hidden_table_schema))) { LOG_WARN("failed to get orig and hidden table schema", K(ret)); - } else if (OB_FAIL(col_name_map.init(*orig_table_schema, alter_table_schema))) { - LOG_WARN("failed to init column name map", K(ret), K(alter_table_schema), KPC(orig_table_schema)); - } else if (OB_FAIL(get_all_dropped_column_ids(alter_table_arg, *orig_table_schema, drop_cols_id_arr))) { - LOG_WARN("fail to get drop cols id set", K(ret)); - } else if (OB_FAIL(reconstruct_index_schema(*orig_table_schema, - *hidden_table_schema, - schema_guard, - drop_cols_id_arr, - col_name_map, - *tz_info_wrap.get_time_zone_info(), - alter_table_arg.allocator_, - new_table_schemas, - index_ids))) { - LOG_WARN("failed to reconstruct index schema", K(ret)); - } else if (OB_FAIL(add_new_index_schema(alter_table_arg, - *orig_table_schema, - *hidden_table_schema, - schema_guard, - new_table_schemas, - index_ids))) { - LOG_WARN("failed to add new index schema", K(ret)); - } else if (OB_FAIL(rebuild_hidden_table_index_in_trans(alter_table_arg, - *hidden_table_schema, - schema_guard, - trans, - new_table_schemas))) { - LOG_WARN("failed to rebuild hidden table index in trans", K(ret)); + } else if (hidden_table_schema->get_simple_index_infos().count() > 0) { + // if there is any index in the hidden table, all indexes are already rebuilt because the rebuild is wrap in a transaction + const common::ObIArray &index_infos = hidden_table_schema->get_simple_index_infos(); + for (int64_t i = 0; OB_SUCC(ret) && i < index_infos.count(); ++i) { + if (OB_FAIL(index_ids.push_back(index_infos.at(i).table_id_))) { + LOG_WARN("push back index id failed", K(ret)); + } + } + } else { + if (OB_FAIL(col_name_map.init(*orig_table_schema, alter_table_schema))) { + LOG_WARN("failed to init column name map", K(ret), K(alter_table_schema), KPC(orig_table_schema)); + } else if (OB_FAIL(get_all_dropped_column_ids(alter_table_arg, *orig_table_schema, drop_cols_id_arr))) { + LOG_WARN("fail to get drop cols id set", K(ret)); + } else if (OB_FAIL(reconstruct_index_schema(*orig_table_schema, + *hidden_table_schema, + schema_guard, + drop_cols_id_arr, + col_name_map, + *tz_info_wrap.get_time_zone_info(), + alter_table_arg.allocator_, + new_table_schemas, + index_ids))) { + LOG_WARN("failed to reconstruct index schema", K(ret)); + } else if (OB_FAIL(add_new_index_schema(alter_table_arg, + *orig_table_schema, + *hidden_table_schema, + schema_guard, + new_table_schemas, + index_ids))) { + LOG_WARN("failed to add new index schema", K(ret)); + } else if (OB_FAIL(rebuild_hidden_table_index_in_trans(alter_table_arg, + *hidden_table_schema, + schema_guard, + trans, + new_table_schemas))) { + LOG_WARN("failed to rebuild hidden table index in trans", K(ret)); + } } } int tmp_ret = OB_SUCCESS;