From 5b3ed2cad156205d98b31dfd69e9bab5898df046 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 7 Sep 2021 20:46:53 +0300 Subject: MDEV-22165 CONVERT TABLE: move in partition from existing table Syntax for CONVERT TABLE ALTER TABLE tbl_name [alter_option [, alter_option] ...] | [partition_options] partition_option: { ... | CONVERT TABLE tbl_name TO PARTITION partition_name partition_spec } Examples: ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 VALUES LESS THAN MAX_VALUE(); New ALTER_PARTITION_CONVERT_IN command for fast_alter_partition_table() is done in alter_partition_convert_in() function which basically does ha_rename_table(). Table structure and data check is basically the same as in EXCHANGE PARTITION command. And these are done by compare_table_with_partition() and check_table_data(). Atomic DDL is done by the scheme from MDEV-22166 (see the corresponding commit message). The only differnce is that it also has to drop source table frm and that is done by WFRM_DROP_CONVERTED_FROM. --- sql/sql_table.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index aff3fb13ff2..857e8f0d95d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -880,7 +880,6 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) #else /* !WITH_PARTITION_STORAGE_ENGINE */ DBUG_ASSERT(!(flags & WFRM_WRITE_EXTRACTED)); DBUG_ASSERT(!(flags & WFRM_BACKUP_ORIGINAL)); - DBUG_ASSERT(!(flags & WFRM_DROP_BACKUP)); #endif /* !WITH_PARTITION_STORAGE_ENGINE */ if (flags & WFRM_INSTALL_SHADOW) { @@ -9694,7 +9693,8 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, Table maybe does not exist, but we got an exclusive lock on the name, now we can safely try to find out for sure. */ - if (ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name)) + if (!(alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN) && + ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name)) { /* Table will be closed in do_command() */ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str); -- cgit v1.2.1