summaryrefslogtreecommitdiff
path: root/sql/sql_partition_admin.cc
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2021-09-28 12:40:06 +0300
committerSergei Golubchik <serg@mariadb.org>2021-10-26 17:07:46 +0200
commit69724805bc4b61cdf8460d4a7ec0acf71f579396 (patch)
treeb76f09b1618f0b0104752ba731c16017cd95eba5 /sql/sql_partition_admin.cc
parent7da721be314c7355a549681dc93a782f89c99981 (diff)
downloadmariadb-git-69724805bc4b61cdf8460d4a7ec0acf71f579396.tar.gz
MDEV-22165 CONVERT TABLE: move in partition from existing table
Syntax for CONVERT TABLE ALTER TABLE tbl_name 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. Initial patch was done by Dmitry Shulga <dmitry.shulga@mariadb.com>
Diffstat (limited to 'sql/sql_partition_admin.cc')
-rw-r--r--sql/sql_partition_admin.cc57
1 files changed, 52 insertions, 5 deletions
diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc
index 1056998ef08..fb1ae0d5fc7 100644
--- a/sql/sql_partition_admin.cc
+++ b/sql/sql_partition_admin.cc
@@ -192,10 +192,8 @@ static bool check_exchange_partition(TABLE *table, TABLE *part_table)
@param part_table Partitioned table.
@param part_elem Partition element to use for partition specific compare.
*/
-static bool compare_table_with_partition(THD *thd, TABLE *table,
- TABLE *part_table,
- partition_element *part_elem,
- uint part_id)
+bool compare_table_with_partition(THD *thd, TABLE *table, TABLE *part_table,
+ partition_element *part_elem, uint part_id)
{
HA_CREATE_INFO table_create_info, part_create_info;
Alter_info part_alter_info;
@@ -292,7 +290,7 @@ static bool compare_table_with_partition(THD *thd, TABLE *table,
The workaround is to use REORGANIZE PARTITION to rewrite
the frm file and then use EXCHANGE PARTITION when they are the same.
*/
- if (compare_partition_options(&table_create_info, part_elem))
+ if (part_elem && compare_partition_options(&table_create_info, part_elem))
DBUG_RETURN(TRUE);
DBUG_RETURN(FALSE);
@@ -988,4 +986,53 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
DBUG_RETURN(error);
}
+
+/**
+ Move a table specified in the CONVERT TABLE <table_name> TO PARTITION ...
+ to the new partition.
+
+ @param lpt A structure containing parameters regarding to the statement
+ ALTER TABLE ... TO PARTITION ...
+ @param part_file_name a file name of the partition being added
+
+ @return false on success, true on error
+*/
+
+bool alter_partition_convert_in(ALTER_PARTITION_PARAM_TYPE *lpt)
+{
+ char part_file_name[2*FN_REFLEN+1];
+ THD *thd= lpt->thd;
+ const char *path= lpt->table_list->table->s->path.str;
+ TABLE_LIST *table_from= lpt->table_list->next_local;
+
+ const char *partition_name=
+ thd->lex->part_info->curr_part_elem->partition_name;
+
+ if (create_partition_name(part_file_name, sizeof(part_file_name), path,
+ partition_name, NORMAL_PART_NAME, false))
+ return true;
+
+ char from_file_name[FN_REFLEN+1];
+
+ build_table_filename(from_file_name, sizeof(from_file_name),
+ table_from->db.str, table_from->table_name.str, "", 0);
+
+ handler *file= get_new_handler(nullptr, thd->mem_root,
+ table_from->table->file->ht);
+ if (unlikely(!file))
+ return true;
+
+ close_all_tables_for_name(thd, table_from->table->s,
+ HA_EXTRA_PREPARE_FOR_RENAME, nullptr);
+
+ bool res= file->ha_rename_table(from_file_name, part_file_name);
+
+ if (res)
+ my_error(ER_ERROR_ON_RENAME, MYF(0), from_file_name,
+ part_file_name, my_errno);
+
+ delete file;
+ return res;
+}
+
#endif /* WITH_PARTITION_STORAGE_ENGINE */