mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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>
This commit is contained in:
committed by
Sergei Golubchik
parent
7da721be31
commit
69724805bc
@ -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 */
|
||||
|
Reference in New Issue
Block a user