Skip to content

Commit abd31ca

Browse files
committed
MDEV-7990: ERROR 1526 when procedure executed for second time ALTER TABLE partition ... pMAX values less than MAXVALUE
Made dipper copy of the lists, so now one execution has no influence on the other.
1 parent 39e8dc9 commit abd31ca

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

mysql-test/r/partition_alter.result

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
CREATE TABLE `test_data` (
2+
`hid` bigint(20) unsigned NOT NULL,
3+
`itid` bigint(20) unsigned NOT NULL,
4+
`clocktime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
5+
`values` double(16,4) NOT NULL,
6+
PRIMARY KEY (`hid`,`itid`,`clocktime`)
7+
) ;
8+
INSERT INTO `test_data` (`hid`, `itid`, `clocktime`, `values`) VALUES
9+
(1, 1, '2015-03-10 06:25:16', 0.0000),
10+
(1, 1, '2015-03-10 06:26:24', 0.0000),
11+
(1, 1, '2015-03-10 06:27:32', 0.0000),
12+
(1, 1, '2015-03-10 06:28:40', 0.0000),
13+
(1, 1, '2015-03-10 06:29:49', 0.0000),
14+
(1, 1, '2015-03-10 06:30:57', 0.0000),
15+
(1, 1, '2015-03-10 06:32:05', 0.0000),
16+
(1, 1, '2015-03-10 06:33:14', 0.0000),
17+
(1, 1, '2015-03-10 06:34:22', 0.0000),
18+
(1, 1, '2015-03-10 06:35:30', 0.0000),
19+
(1, 1, '2015-03-10 06:36:39', 0.0000),
20+
(1, 1, '2015-03-10 06:37:47', 0.0000),
21+
(1, 1, '2015-03-10 06:38:55', 0.0000),
22+
(1, 1, '2015-03-10 06:40:03', 0.0000),
23+
(1, 1, '2015-03-10 06:41:09', 0.0000),
24+
(1, 1, '2015-03-10 06:42:21', 0.0000),
25+
(1, 1, '2015-03-10 06:43:29', 0.0000),
26+
(1, 1, '2015-03-10 06:44:37', 0.0000),
27+
(1, 1, '2015-03-10 06:45:46', 0.0000),
28+
(1, 1, '2015-03-10 06:47:05', 0.0000),
29+
(1, 1, '2015-03-10 06:48:21', 0.0000),
30+
(1, 1, '2015-03-10 06:49:41', 0.0000),
31+
(1, 1, '2015-03-10 06:50:58', 0.0000),
32+
(1, 1, '2015-03-10 06:52:08', 0.0000),
33+
(1, 1, '2015-03-10 06:53:17', 0.0000),
34+
(1, 1, '2015-03-10 06:54:25', 0.0000),
35+
(563, 1, '2015-03-17 14:28:28', 0.3125),
36+
(563, 1, '2015-03-17 14:29:39', 0.2775),
37+
(563, 1, '2015-03-17 14:30:49', 0.2675);
38+
CREATE PROCEDURE `create_part_max`()
39+
alter table `test_data`
40+
partition by range(unix_timestamp(clocktime)) (
41+
partition partMAX values less than MAXVALUE
42+
);
43+
call create_part_max();
44+
call create_part_max();
45+
drop procedure create_part_max;
46+
prepare stmt from "alter table `test_data`
47+
partition by range(unix_timestamp(clocktime)) (
48+
partition partMAX values less than MAXVALUE
49+
)";
50+
execute stmt;
51+
execute stmt;
52+
deallocate prepare stmt;
53+
drop table test_data;

mysql-test/t/partition_alter.test

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--source include/have_partition.inc
2+
3+
CREATE TABLE `test_data` (
4+
`hid` bigint(20) unsigned NOT NULL,
5+
`itid` bigint(20) unsigned NOT NULL,
6+
`clocktime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
7+
`values` double(16,4) NOT NULL,
8+
PRIMARY KEY (`hid`,`itid`,`clocktime`)
9+
) ;
10+
11+
INSERT INTO `test_data` (`hid`, `itid`, `clocktime`, `values`) VALUES
12+
(1, 1, '2015-03-10 06:25:16', 0.0000),
13+
(1, 1, '2015-03-10 06:26:24', 0.0000),
14+
(1, 1, '2015-03-10 06:27:32', 0.0000),
15+
(1, 1, '2015-03-10 06:28:40', 0.0000),
16+
(1, 1, '2015-03-10 06:29:49', 0.0000),
17+
(1, 1, '2015-03-10 06:30:57', 0.0000),
18+
(1, 1, '2015-03-10 06:32:05', 0.0000),
19+
(1, 1, '2015-03-10 06:33:14', 0.0000),
20+
(1, 1, '2015-03-10 06:34:22', 0.0000),
21+
(1, 1, '2015-03-10 06:35:30', 0.0000),
22+
(1, 1, '2015-03-10 06:36:39', 0.0000),
23+
(1, 1, '2015-03-10 06:37:47', 0.0000),
24+
(1, 1, '2015-03-10 06:38:55', 0.0000),
25+
(1, 1, '2015-03-10 06:40:03', 0.0000),
26+
(1, 1, '2015-03-10 06:41:09', 0.0000),
27+
(1, 1, '2015-03-10 06:42:21', 0.0000),
28+
(1, 1, '2015-03-10 06:43:29', 0.0000),
29+
(1, 1, '2015-03-10 06:44:37', 0.0000),
30+
(1, 1, '2015-03-10 06:45:46', 0.0000),
31+
(1, 1, '2015-03-10 06:47:05', 0.0000),
32+
(1, 1, '2015-03-10 06:48:21', 0.0000),
33+
(1, 1, '2015-03-10 06:49:41', 0.0000),
34+
(1, 1, '2015-03-10 06:50:58', 0.0000),
35+
(1, 1, '2015-03-10 06:52:08', 0.0000),
36+
(1, 1, '2015-03-10 06:53:17', 0.0000),
37+
(1, 1, '2015-03-10 06:54:25', 0.0000),
38+
(563, 1, '2015-03-17 14:28:28', 0.3125),
39+
(563, 1, '2015-03-17 14:29:39', 0.2775),
40+
(563, 1, '2015-03-17 14:30:49', 0.2675);
41+
42+
43+
CREATE PROCEDURE `create_part_max`()
44+
alter table `test_data`
45+
partition by range(unix_timestamp(clocktime)) (
46+
partition partMAX values less than MAXVALUE
47+
);
48+
49+
call create_part_max();
50+
51+
call create_part_max();
52+
53+
drop procedure create_part_max;
54+
55+
prepare stmt from "alter table `test_data`
56+
partition by range(unix_timestamp(clocktime)) (
57+
partition partMAX values less than MAXVALUE
58+
)";
59+
60+
execute stmt;
61+
execute stmt;
62+
63+
deallocate prepare stmt;
64+
65+
drop table test_data;
66+

sql/partition_info.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,41 @@ partition_info *partition_info::get_clone()
7777
part_clone->subpartitions.push_back(subpart_clone);
7878
}
7979
clone->partitions.push_back(part_clone);
80+
part_clone->list_val_list.empty();
81+
List_iterator<part_elem_value> list_val_it(part->list_val_list);
82+
part_elem_value *new_val_arr=
83+
(part_elem_value *)sql_alloc(sizeof(part_elem_value) *
84+
part->list_val_list.elements);
85+
if (!new_val_arr)
86+
{
87+
mem_alloc_error(sizeof(part_elem_value) * part->list_val_list.elements);
88+
DBUG_RETURN(NULL);
89+
}
90+
p_column_list_val *new_colval_arr=
91+
(p_column_list_val*)sql_alloc(sizeof(p_column_list_val) *
92+
num_columns *
93+
part->list_val_list.elements);
94+
if (!new_colval_arr)
95+
{
96+
mem_alloc_error(sizeof(p_column_list_val) * num_columns *
97+
part->list_val_list.elements);
98+
DBUG_RETURN(NULL);
99+
}
100+
part_elem_value *val;
101+
while ((val= list_val_it++))
102+
{
103+
part_elem_value *new_val= new_val_arr++;
104+
memcpy(new_val, val, sizeof(part_elem_value));
105+
if (!val->null_value)
106+
{
107+
p_column_list_val *new_colval= new_colval_arr;
108+
new_colval_arr+= num_columns;
109+
memcpy(new_colval, val->col_val_array,
110+
sizeof(p_column_list_val) * num_columns);
111+
new_val->col_val_array= new_colval;
112+
}
113+
part_clone->list_val_list.push_back(new_val);
114+
}
80115
}
81116
DBUG_RETURN(clone);
82117
}

0 commit comments

Comments
 (0)