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 77a150994ad14725c31a83e33d7faa6decc401dc..f151d89bb1ab000b360b76b6c3f15d87fff84e04 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -611,6 +611,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 @@ -622,6 +624,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; @@ -629,6 +633,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); } @@ -745,6 +750,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 76d8aa18f596c5b64b276dab23b493479df248ee..92cc22cc4b81e3f4c828c93ccadce6364dbc8305 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1208,6 +1208,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 a10a04ba9f971b031ca35b9e9023af5c78b44e9b..a2efae0fbae3ad14ccb8e1f888fa555cc768a2d5 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4996,8 +4996,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); } @@ -5015,8 +5014,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); } } @@ -5290,7 +5288,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; @@ -5544,6 +5542,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; @@ -5846,6 +5845,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") ||