From bc8d7698bf8a6f0173a8d846ef8bb04cfeb7c5a0 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 22 Aug 2023 10:08:04 +0200 Subject: [PATCH 1/2] This is an automated cherry-pick of #7945 Signed-off-by: ti-chi-bot --- dbms/src/TiDB/Schema/SchemaBuilder.cpp | 32 +++++++++++++++++++ tests/_env.sh | 2 +- .../ddl/alter_exchange_partition.test | 4 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/dbms/src/TiDB/Schema/SchemaBuilder.cpp b/dbms/src/TiDB/Schema/SchemaBuilder.cpp index ff33991ba61..b1522f24c55 100644 --- a/dbms/src/TiDB/Schema/SchemaBuilder.cpp +++ b/dbms/src/TiDB/Schema/SchemaBuilder.cpp @@ -99,12 +99,44 @@ inline void setAlterCommandColumn(const LoggerPtr & log, AlterCommand & command, AlterCommand newRenameColCommand(const String & old_col, const String & new_col, ColumnID new_col_id, const TableInfo & orig_table_info) { +<<<<<<< HEAD AlterCommand command; command.type = AlterCommand::RENAME_COLUMN; command.column_name = old_col; command.new_column_name = new_col; command.column_id = new_col_id; if (auto pk = orig_table_info.getPKHandleColumn()) +======= + if (diff.old_table_id == diff.table_id && diff.old_schema_id == diff.schema_id) + { + // Only internal changes in non-partitioned table, not affecting TiFlash + LOG_DEBUG( + log, + "Table is going to be exchanged, skipping for now. database_id={} table_id={}", + diff.schema_id, + diff.table_id); + return; + } + LOG_DEBUG( + log, + "Table and partition is exchanged. database_id={} table_id={}, part_db_id={}, part_table_id={} partition_id={}", + diff.old_schema_id, + diff.old_table_id, + diff.affected_opts[0].schema_id, + diff.affected_opts[0].table_id, + diff.table_id); + /// Table_id in diff is the partition id of which will be exchanged, + /// Schema_id in diff is the non-partition table's schema id + /// Old_table_id in diff is the non-partition table's table id + /// Table_id in diff.affected_opts[0] is the table id of the partition table + /// Schema_id in diff.affected_opts[0] is the schema id of the partition table + table_id_map.eraseTableIDOrLogError(diff.old_table_id); + table_id_map.emplaceTableID(diff.table_id, diff.schema_id); + table_id_map.erasePartitionTableIDOrLogError(diff.table_id); + table_id_map.emplacePartitionTableID(diff.old_table_id, diff.affected_opts[0].table_id); + + if (diff.schema_id != diff.affected_opts[0].schema_id) +>>>>>>> b1f1dbcf00 (Skip first state change of EXCHANGE Partition. (#7945)) { if (pk->get().name == old_col) { diff --git a/tests/_env.sh b/tests/_env.sh index fa726504e69..79e7da626e8 100644 --- a/tests/_env.sh +++ b/tests/_env.sh @@ -33,7 +33,7 @@ fi export storage_server="127.0.0.1" # Server port for connecting -export storage_port="9000" +export storage_port=${storage_port:-9000} # Default database for scripts export storage_db="system" diff --git a/tests/fullstack-test2/ddl/alter_exchange_partition.test b/tests/fullstack-test2/ddl/alter_exchange_partition.test index 50e950a797a..3846b6b8451 100644 --- a/tests/fullstack-test2/ddl/alter_exchange_partition.test +++ b/tests/fullstack-test2/ddl/alter_exchange_partition.test @@ -12,6 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +<<<<<<< HEAD +======= + +>>>>>>> b1f1dbcf00 (Skip first state change of EXCHANGE Partition. (#7945)) >> DBGInvoke __enable_schema_sync_service('true') mysql> drop table if exists test.e; mysql> drop table if exists test.e2; From 46fd4dde0897934d32ec04d6dc694ea98d2a22a6 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Fri, 15 Sep 2023 17:27:22 +0800 Subject: [PATCH 2/2] Resolve conflict --- dbms/src/TiDB/Schema/SchemaBuilder.cpp | 50 +++++++------------ .../ddl/alter_exchange_partition.test | 4 -- 2 files changed, 18 insertions(+), 36 deletions(-) diff --git a/dbms/src/TiDB/Schema/SchemaBuilder.cpp b/dbms/src/TiDB/Schema/SchemaBuilder.cpp index b1522f24c55..696f07d08d0 100644 --- a/dbms/src/TiDB/Schema/SchemaBuilder.cpp +++ b/dbms/src/TiDB/Schema/SchemaBuilder.cpp @@ -99,44 +99,12 @@ inline void setAlterCommandColumn(const LoggerPtr & log, AlterCommand & command, AlterCommand newRenameColCommand(const String & old_col, const String & new_col, ColumnID new_col_id, const TableInfo & orig_table_info) { -<<<<<<< HEAD AlterCommand command; command.type = AlterCommand::RENAME_COLUMN; command.column_name = old_col; command.new_column_name = new_col; command.column_id = new_col_id; if (auto pk = orig_table_info.getPKHandleColumn()) -======= - if (diff.old_table_id == diff.table_id && diff.old_schema_id == diff.schema_id) - { - // Only internal changes in non-partitioned table, not affecting TiFlash - LOG_DEBUG( - log, - "Table is going to be exchanged, skipping for now. database_id={} table_id={}", - diff.schema_id, - diff.table_id); - return; - } - LOG_DEBUG( - log, - "Table and partition is exchanged. database_id={} table_id={}, part_db_id={}, part_table_id={} partition_id={}", - diff.old_schema_id, - diff.old_table_id, - diff.affected_opts[0].schema_id, - diff.affected_opts[0].table_id, - diff.table_id); - /// Table_id in diff is the partition id of which will be exchanged, - /// Schema_id in diff is the non-partition table's schema id - /// Old_table_id in diff is the non-partition table's table id - /// Table_id in diff.affected_opts[0] is the table id of the partition table - /// Schema_id in diff.affected_opts[0] is the schema id of the partition table - table_id_map.eraseTableIDOrLogError(diff.old_table_id); - table_id_map.emplaceTableID(diff.table_id, diff.schema_id); - table_id_map.erasePartitionTableIDOrLogError(diff.table_id); - table_id_map.emplacePartitionTableID(diff.old_table_id, diff.affected_opts[0].table_id); - - if (diff.schema_id != diff.affected_opts[0].schema_id) ->>>>>>> b1f1dbcf00 (Skip first state change of EXCHANGE Partition. (#7945)) { if (pk->get().name == old_col) { @@ -796,6 +764,24 @@ void SchemaBuilder::applyRenamePhysicalTable( template void SchemaBuilder::applyExchangeTablePartition(const SchemaDiff & diff) { + if (diff.old_table_id == diff.table_id && diff.old_schema_id == diff.schema_id) + { + // Only internal changes in non-partitioned table, not affecting TiFlash + LOG_DEBUG( + log, + "Table is going to be exchanged, skipping for now. database_id={} table_id={}", + diff.schema_id, + diff.table_id); + return; + } + LOG_DEBUG( + log, + "Table and partition is exchanged. database_id={} table_id={}, part_db_id={}, part_table_id={} partition_id={}", + diff.old_schema_id, + diff.old_table_id, + diff.affected_opts[0].schema_id, + diff.affected_opts[0].table_id, + diff.table_id); /// Exchange table partition is used for ddl: /// alter table partition_table exchange partition partition_name with table non_partition_table /// It involves three table/partition: partition_table, partition_name and non_partition_table diff --git a/tests/fullstack-test2/ddl/alter_exchange_partition.test b/tests/fullstack-test2/ddl/alter_exchange_partition.test index 3846b6b8451..50e950a797a 100644 --- a/tests/fullstack-test2/ddl/alter_exchange_partition.test +++ b/tests/fullstack-test2/ddl/alter_exchange_partition.test @@ -12,10 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -<<<<<<< HEAD -======= - ->>>>>>> b1f1dbcf00 (Skip first state change of EXCHANGE Partition. (#7945)) >> DBGInvoke __enable_schema_sync_service('true') mysql> drop table if exists test.e; mysql> drop table if exists test.e2;