Commit 13911752 authored by Aleksey Midenkov's avatar Aleksey Midenkov

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.
parent 22811a1c
......@@ -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;
......@@ -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
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment