diff --git a/mysql-test/r/partition_alter.result b/mysql-test/r/partition_alter.result new file mode 100644 index 00000000000..cbd90b5ba7c --- /dev/null +++ b/mysql-test/r/partition_alter.result @@ -0,0 +1,53 @@ +CREATE TABLE `test_data` ( +`hid` bigint(20) unsigned NOT NULL, +`itid` bigint(20) unsigned NOT NULL, +`clocktime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +`values` double(16,4) NOT NULL, +PRIMARY KEY (`hid`,`itid`,`clocktime`) +) ; +INSERT INTO `test_data` (`hid`, `itid`, `clocktime`, `values`) VALUES +(1, 1, '2015-03-10 06:25:16', 0.0000), +(1, 1, '2015-03-10 06:26:24', 0.0000), +(1, 1, '2015-03-10 06:27:32', 0.0000), +(1, 1, '2015-03-10 06:28:40', 0.0000), +(1, 1, '2015-03-10 06:29:49', 0.0000), +(1, 1, '2015-03-10 06:30:57', 0.0000), +(1, 1, '2015-03-10 06:32:05', 0.0000), +(1, 1, '2015-03-10 06:33:14', 0.0000), +(1, 1, '2015-03-10 06:34:22', 0.0000), +(1, 1, '2015-03-10 06:35:30', 0.0000), +(1, 1, '2015-03-10 06:36:39', 0.0000), +(1, 1, '2015-03-10 06:37:47', 0.0000), +(1, 1, '2015-03-10 06:38:55', 0.0000), +(1, 1, '2015-03-10 06:40:03', 0.0000), +(1, 1, '2015-03-10 06:41:09', 0.0000), +(1, 1, '2015-03-10 06:42:21', 0.0000), +(1, 1, '2015-03-10 06:43:29', 0.0000), +(1, 1, '2015-03-10 06:44:37', 0.0000), +(1, 1, '2015-03-10 06:45:46', 0.0000), +(1, 1, '2015-03-10 06:47:05', 0.0000), +(1, 1, '2015-03-10 06:48:21', 0.0000), +(1, 1, '2015-03-10 06:49:41', 0.0000), +(1, 1, '2015-03-10 06:50:58', 0.0000), +(1, 1, '2015-03-10 06:52:08', 0.0000), +(1, 1, '2015-03-10 06:53:17', 0.0000), +(1, 1, '2015-03-10 06:54:25', 0.0000), +(563, 1, '2015-03-17 14:28:28', 0.3125), +(563, 1, '2015-03-17 14:29:39', 0.2775), +(563, 1, '2015-03-17 14:30:49', 0.2675); +CREATE PROCEDURE `create_part_max`() +alter table `test_data` + partition by range(unix_timestamp(clocktime)) ( +partition partMAX values less than MAXVALUE +); +call create_part_max(); +call create_part_max(); +drop procedure create_part_max; +prepare stmt from "alter table `test_data` + partition by range(unix_timestamp(clocktime)) ( + partition partMAX values less than MAXVALUE + )"; +execute stmt; +execute stmt; +deallocate prepare stmt; +drop table test_data; diff --git a/mysql-test/t/partition_alter.test b/mysql-test/t/partition_alter.test new file mode 100644 index 00000000000..592d8fdaeaa --- /dev/null +++ b/mysql-test/t/partition_alter.test @@ -0,0 +1,66 @@ +--source include/have_partition.inc + +CREATE TABLE `test_data` ( + `hid` bigint(20) unsigned NOT NULL, + `itid` bigint(20) unsigned NOT NULL, + `clocktime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `values` double(16,4) NOT NULL, + PRIMARY KEY (`hid`,`itid`,`clocktime`) + ) ; + +INSERT INTO `test_data` (`hid`, `itid`, `clocktime`, `values`) VALUES + (1, 1, '2015-03-10 06:25:16', 0.0000), + (1, 1, '2015-03-10 06:26:24', 0.0000), + (1, 1, '2015-03-10 06:27:32', 0.0000), + (1, 1, '2015-03-10 06:28:40', 0.0000), + (1, 1, '2015-03-10 06:29:49', 0.0000), + (1, 1, '2015-03-10 06:30:57', 0.0000), + (1, 1, '2015-03-10 06:32:05', 0.0000), + (1, 1, '2015-03-10 06:33:14', 0.0000), + (1, 1, '2015-03-10 06:34:22', 0.0000), + (1, 1, '2015-03-10 06:35:30', 0.0000), + (1, 1, '2015-03-10 06:36:39', 0.0000), + (1, 1, '2015-03-10 06:37:47', 0.0000), + (1, 1, '2015-03-10 06:38:55', 0.0000), + (1, 1, '2015-03-10 06:40:03', 0.0000), + (1, 1, '2015-03-10 06:41:09', 0.0000), + (1, 1, '2015-03-10 06:42:21', 0.0000), + (1, 1, '2015-03-10 06:43:29', 0.0000), + (1, 1, '2015-03-10 06:44:37', 0.0000), + (1, 1, '2015-03-10 06:45:46', 0.0000), + (1, 1, '2015-03-10 06:47:05', 0.0000), + (1, 1, '2015-03-10 06:48:21', 0.0000), + (1, 1, '2015-03-10 06:49:41', 0.0000), + (1, 1, '2015-03-10 06:50:58', 0.0000), + (1, 1, '2015-03-10 06:52:08', 0.0000), + (1, 1, '2015-03-10 06:53:17', 0.0000), + (1, 1, '2015-03-10 06:54:25', 0.0000), + (563, 1, '2015-03-17 14:28:28', 0.3125), + (563, 1, '2015-03-17 14:29:39', 0.2775), + (563, 1, '2015-03-17 14:30:49', 0.2675); + + +CREATE PROCEDURE `create_part_max`() + alter table `test_data` + partition by range(unix_timestamp(clocktime)) ( + partition partMAX values less than MAXVALUE + ); + +call create_part_max(); + +call create_part_max(); + +drop procedure create_part_max; + +prepare stmt from "alter table `test_data` + partition by range(unix_timestamp(clocktime)) ( + partition partMAX values less than MAXVALUE + )"; + +execute stmt; +execute stmt; + +deallocate prepare stmt; + +drop table test_data; + diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 73b88d64224..4a42d7965b8 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -77,6 +77,41 @@ partition_info *partition_info::get_clone() part_clone->subpartitions.push_back(subpart_clone); } clone->partitions.push_back(part_clone); + part_clone->list_val_list.empty(); + List_iterator list_val_it(part->list_val_list); + part_elem_value *new_val_arr= + (part_elem_value *)sql_alloc(sizeof(part_elem_value) * + part->list_val_list.elements); + if (!new_val_arr) + { + mem_alloc_error(sizeof(part_elem_value) * part->list_val_list.elements); + DBUG_RETURN(NULL); + } + p_column_list_val *new_colval_arr= + (p_column_list_val*)sql_alloc(sizeof(p_column_list_val) * + num_columns * + part->list_val_list.elements); + if (!new_colval_arr) + { + mem_alloc_error(sizeof(p_column_list_val) * num_columns * + part->list_val_list.elements); + DBUG_RETURN(NULL); + } + part_elem_value *val; + while ((val= list_val_it++)) + { + part_elem_value *new_val= new_val_arr++; + memcpy(new_val, val, sizeof(part_elem_value)); + if (!val->null_value) + { + p_column_list_val *new_colval= new_colval_arr; + new_colval_arr+= num_columns; + memcpy(new_colval, val->col_val_array, + sizeof(p_column_list_val) * num_columns); + new_val->col_val_array= new_colval; + } + part_clone->list_val_list.push_back(new_val); + } } DBUG_RETURN(clone); }