summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2020-04-06 06:26:46 +0300
committerAleksey Midenkov <midenok@gmail.com>2020-04-06 06:26:46 +0300
commit139117528affc89b6e174231b86048ec2b03f686 (patch)
tree86f1ebea1f7615871fda346739669f3e15ecbe09
parent22811a1c60e6d11ff636e5ec065f08754ac36929 (diff)
downloadmariadb-git-139117528affc89b6e174231b86048ec2b03f686.tar.gz
MDEV-22153 ALTER add default history partitions makes table inaccessible
ADD default history partitions generates wrong partition name, f.ex. p2 instead of p1. Gap in sequence of partition names leads to ha_partition::open_read_partitions() fail on inexistent name. Manual fixing such broken table requires: 1. create empty table by any name (t_empty) with correct number of partitions; 2. stop the server; 3. rename data files (.myd, .myi or .ibd) of broken table to t_empty fixing the partition sequence (#p2 to #p1, #p3 to #p2); 4. start the server; 5. drop the broken table; 6. rename t_empty to correct table name.
-rw-r--r--mysql-test/suite/versioning/r/partition.result35
-rw-r--r--mysql-test/suite/versioning/t/partition.test15
-rw-r--r--sql/partition_info.cc12
3 files changed, 58 insertions, 4 deletions
diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result
index 038051055e7..a7047cbd11b 100644
--- a/mysql-test/suite/versioning/r/partition.result
+++ b/mysql-test/suite/versioning/r/partition.result
@@ -1009,3 +1009,38 @@ create table t2 (b int);
insert into t2 values (1),(2);
update t1, t2 set a = 1;
drop table t1, t2;
+#
+# MDEV-22153 ALTER add default history partitions breaks table
+#
+create or replace table t1 (x int) with system versioning partition by system_time;
+alter table t1 add partition partitions 1;
+Warnings:
+Warning 4115 Maybe missing parameters: no rotation condition for multiple HISTORY partitions.
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `x` int(11) DEFAULT NULL
+) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
+ PARTITION BY SYSTEM_TIME
+PARTITIONS 3
+alter table t1 add partition partitions 2;
+Warnings:
+Warning 4115 Maybe missing parameters: no rotation condition for multiple HISTORY partitions.
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `x` int(11) DEFAULT NULL
+) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
+ PARTITION BY SYSTEM_TIME
+PARTITIONS 5
+alter table t1 add partition partitions 3;
+Warnings:
+Warning 4115 Maybe missing parameters: no rotation condition for multiple HISTORY partitions.
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `x` int(11) DEFAULT NULL
+) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
+ PARTITION BY SYSTEM_TIME
+PARTITIONS 8
+drop tables t1;
diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test
index f55b43f56da..d49fdf530dd 100644
--- a/mysql-test/suite/versioning/t/partition.test
+++ b/mysql-test/suite/versioning/t/partition.test
@@ -837,4 +837,19 @@ update t1, t2 set a = 1;
# cleanup
drop table t1, t2;
+--echo #
+--echo # MDEV-22153 ALTER add default history partitions breaks table
+--echo #
+create or replace table t1 (x int) with system versioning partition by system_time;
+alter table t1 add partition partitions 1;
+--replace_result $default_engine DEFAULT_ENGINE
+show create table t1;
+alter table t1 add partition partitions 2;
+--replace_result $default_engine DEFAULT_ENGINE
+show create table t1;
+alter table t1 add partition partitions 3;
+--replace_result $default_engine DEFAULT_ENGINE
+show create table t1;
+drop tables t1;
+
--source suite/versioning/common_finish.inc
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index 5e3c19850de..f4b7260f8b0 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -401,15 +401,19 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file,
uint i;
char *default_name;
bool result= TRUE;
+ bool alter= false;
DBUG_ENTER("partition_info::set_up_default_partitions");
if (part_type == VERSIONING_PARTITION)
{
- if (use_default_num_partitions)
+ if (start_no > 0)
{
- num_parts= 2;
- use_default_num_partitions= false;
+ start_no--;
+ alter= true;
}
+ else if (use_default_num_partitions)
+ num_parts= 2;
+ use_default_num_partitions= false;
}
else if (part_type != HASH_PARTITION)
{
@@ -451,7 +455,7 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file,
default_name+=MAX_PART_NAME_SIZE;
if (part_type == VERSIONING_PARTITION)
{
- if (i < num_parts - 1) {
+ if (alter || i < num_parts - 1) {
part_elem->type= partition_element::HISTORY;
} else {
part_elem->type= partition_element::CURRENT;