From 65ef9461b4456c3db9e6751cde8f29f3a87b5be4 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 8e1866daddb..244f67b76bc 100644 --- a/dbms/src/TiDB/Schema/SchemaBuilder.cpp +++ b/dbms/src/TiDB/Schema/SchemaBuilder.cpp @@ -98,12 +98,44 @@ inline void setAlterCommandColumn(Poco::Logger * log, AlterCommand & command, co 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 0accf9c50c6..d038115cf72 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="default" 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 0cf6ef4fd72d8627de4ecaf966150b0151b2dbc3 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Fri, 15 Sep 2023 15:09:41 +0800 Subject: [PATCH 2/2] Resolve conflict --- dbms/src/TiDB/Schema/SchemaBuilder.cpp | 51 +++++++------------ .../ddl/alter_exchange_partition.test | 4 -- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/dbms/src/TiDB/Schema/SchemaBuilder.cpp b/dbms/src/TiDB/Schema/SchemaBuilder.cpp index 244f67b76bc..f19b2bcbc06 100644 --- a/dbms/src/TiDB/Schema/SchemaBuilder.cpp +++ b/dbms/src/TiDB/Schema/SchemaBuilder.cpp @@ -98,44 +98,12 @@ inline void setAlterCommandColumn(Poco::Logger * log, AlterCommand & command, co 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) { @@ -789,6 +757,25 @@ 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;