diff --git a/mysql-test/r/partition_mgm.result b/mysql-test/r/partition_mgm.result new file mode 100644 index 0000000000000000000000000000000000000000..7b7b57291124ba87dcc39394aaf75e369281507e --- /dev/null +++ b/mysql-test/r/partition_mgm.result @@ -0,0 +1,26 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (f_date DATE, f_varchar VARCHAR(30)) +PARTITION BY HASH(CAST(YEAR(f_date) AS SIGNED INTEGER)) PARTITIONS 2; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f_date` date DEFAULT NULL, + `f_varchar` varchar(30) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY HASH (CAST(YEAR(f_date) AS SIGNED INTEGER)) PARTITIONS 2 +/home/pappa/bug19305/mysql-test/var/master-data/test/t1#P#p0.MYD +/home/pappa/bug19305/mysql-test/var/master-data/test/t1#P#p0.MYI +/home/pappa/bug19305/mysql-test/var/master-data/test/t1#P#p1.MYD +/home/pappa/bug19305/mysql-test/var/master-data/test/t1#P#p1.MYI +/home/pappa/bug19305/mysql-test/var/master-data/test/t1.frm +/home/pappa/bug19305/mysql-test/var/master-data/test/t1.par +ALTER TABLE t1 COALESCE PARTITION 1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f_date` date DEFAULT NULL, + `f_varchar` varchar(30) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY HASH (CAST(YEAR(f_date) AS SIGNED INTEGER)) PARTITIONS 1 +/home/pappa/bug19305/mysql-test/var/master-data/test/t1#P#p0.MYD +/home/pappa/bug19305/mysql-test/var/master-data/test/t1#P#p0.MYI +/home/pappa/bug19305/mysql-test/var/master-data/test/t1.frm +/home/pappa/bug19305/mysql-test/var/master-data/test/t1.par diff --git a/mysql-test/t/partition_mgm.test b/mysql-test/t/partition_mgm.test new file mode 100644 index 0000000000000000000000000000000000000000..aa9a6459a1a79a139e4b3914d184a36001de2e87 --- /dev/null +++ b/mysql-test/t/partition_mgm.test @@ -0,0 +1,15 @@ +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +CREATE TABLE t1 (f_date DATE, f_varchar VARCHAR(30)) +PARTITION BY HASH(CAST(YEAR(f_date) AS SIGNED INTEGER)) PARTITIONS 2; +SHOW CREATE TABLE t1; + +--exec ls $MYSQLTEST_VARDIR/master-data/test/t1* +ALTER TABLE t1 COALESCE PARTITION 1; +SHOW CREATE TABLE t1; +--exec ls $MYSQLTEST_VARDIR/master-data/test/t1* + + + + diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index b1a5a447b6f5a5b44b3e1729d5d571cd8d076104..c0a5647b697fc1db68eaac949ec3ffc1f6699d31 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -634,6 +634,8 @@ int ha_partition::drop_partitions(const char *path) DBUG_PRINT("info", ("Drop subpartition %s", part_name_buff)); if ((ret_error= file->delete_table((const char *) part_name_buff))) error= ret_error; + if (deactivate_ddl_log_entry(sub_elem->log_entry->entry_pos)) + error= 1; } while (++j < no_subparts); } else @@ -645,6 +647,8 @@ int ha_partition::drop_partitions(const char *path) DBUG_PRINT("info", ("Drop partition %s", part_name_buff)); if ((ret_error= file->delete_table((const char *) part_name_buff))) error= ret_error; + if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) + error= 1; } if (part_elem->part_state == PART_IS_CHANGED) part_elem->part_state= PART_NORMAL; @@ -652,6 +656,7 @@ int ha_partition::drop_partitions(const char *path) part_elem->part_state= PART_IS_DROPPED; } } while (++i < no_parts); + VOID(sync_ddl_log()); DBUG_RETURN(error); } @@ -768,6 +773,7 @@ int ha_partition::rename_partitions(const char *path) */ part_elem= part_it++; if (part_elem->part_state == PART_IS_CHANGED || + part_elem->part_state == PART_TO_BE_DROPPED || (part_elem->part_state == PART_IS_ADDED && temp_partitions)) { if (m_is_sub_partitioned) diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 127aa6c5acd7bc44f61d2a7c309f8571ed25732f..b473abd87c750ac4a0e792a8487906bf12f636f7 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1203,6 +1203,7 @@ typedef struct st_lock_param_type ulonglong deleted; THD *thd; HA_CREATE_INFO *create_info; + ALTER_INFO *alter_info; List<create_field> *create_list; List<create_field> new_create_list; List<Key> *key_list; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 71b8e9b1d95beb0f7b7e33974d285e04d4d8c155..5f594bbfd87b1fda25ac3b214ec3a7c0941300ff 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4968,8 +4968,7 @@ static bool write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, DBUG_RETURN(TRUE); } *next_entry= log_entry->entry_pos; - if (temp_list) - sub_elem->log_entry= log_entry; + sub_elem->log_entry= log_entry; insert_part_info_log_entry_list(part_info, log_entry); } while (++j < no_subparts); } @@ -4987,8 +4986,7 @@ static bool write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, DBUG_RETURN(TRUE); } *next_entry= log_entry->entry_pos; - if (temp_list) - part_elem->log_entry= log_entry; + part_elem->log_entry= log_entry; insert_part_info_log_entry_list(part_info, log_entry); } } @@ -5262,7 +5260,7 @@ static bool write_log_final_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) lpt->table_name, "#"); pthread_mutex_lock(&LOCK_gdl); if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path, - TRUE)) + lpt->alter_info->flags & ALTER_REORGANIZE_PARTITION)) goto error; if (write_log_changed_partitions(lpt, &next_entry, (const char*)path)) goto error; @@ -5516,6 +5514,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table, lpt->thd= thd; lpt->part_info= part_info; + lpt->alter_info= alter_info; lpt->create_info= create_info; lpt->create_list= create_list; lpt->key_list= key_list; @@ -5818,6 +5817,8 @@ uint fast_alter_partition_table(THD *thd, TABLE *table, ERROR_INJECT_CRASH("crash_change_partition_5") || (table->file->extra(HA_EXTRA_PREPARE_FOR_DELETE), FALSE) || ERROR_INJECT_CRASH("crash_change_partition_6") || + mysql_drop_partitions(lpt) || + ERROR_INJECT_CRASH("crash_change_partition_61") || mysql_rename_partitions(lpt) || ((frm_install= TRUE), FALSE) || ERROR_INJECT_CRASH("crash_change_partition_7") ||