Skip to content

Commit

Permalink
MDEV-29841 Partition by system_time can be converted into table but n…
Browse files Browse the repository at this point in the history
…ot back

Wrong error code was returned because of prematurely tested condition
for wrong partition type. Now the condition for CONVERT IN is tested
first.
  • Loading branch information
midenok committed Oct 31, 2022
1 parent 6f8fb41 commit 2092881
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
9 changes: 9 additions & 0 deletions mysql-test/suite/versioning/r/partition.result
Expand Up @@ -2049,6 +2049,15 @@ t1 CREATE TABLE `t1` (
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = X)
drop tables t1, tp1;
#
# MDEV-29841 Partition by system_time can be converted into table but not back
#
create or replace table t (a int) with system versioning
partition by system_time limit 10 partitions 3;
alter table t convert partition p0 to table tp;
alter table t convert table tp to partition p0;
ERROR HY000: CONVERT TABLE TO PARTITION can only be used on RANGE/LIST partitions
drop tables t, tp;
#
# End of 10.7 tests
#
set global innodb_stats_persistent= @save_persistent;
10 changes: 10 additions & 0 deletions mysql-test/suite/versioning/t/partition.test
Expand Up @@ -1677,6 +1677,16 @@ show create table t1;
drop tables t1, tp1;
}

--echo #
--echo # MDEV-29841 Partition by system_time can be converted into table but not back
--echo #
create or replace table t (a int) with system versioning
partition by system_time limit 10 partitions 3;
alter table t convert partition p0 to table tp;
--error ER_ONLY_ON_RANGE_LIST_PARTITION
alter table t convert table tp to partition p0;
drop tables t, tp;

--echo #
--echo # End of 10.7 tests
--echo #
Expand Down
14 changes: 7 additions & 7 deletions sql/sql_partition.cc
Expand Up @@ -5057,6 +5057,13 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
if ((alter_info->partition_flags & ALTER_PARTITION_ADD) ||
(alter_info->partition_flags & ALTER_PARTITION_REORGANIZE))
{
if ((alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN) &&
!(tab_part_info->part_type == RANGE_PARTITION ||
tab_part_info->part_type == LIST_PARTITION))
{
my_error(ER_ONLY_ON_RANGE_LIST_PARTITION, MYF(0), "CONVERT TABLE TO");
goto err;
}
if (thd->work_part_info->part_type != tab_part_info->part_type)
{
if (thd->work_part_info->part_type == NOT_A_PARTITION)
Expand Down Expand Up @@ -5126,13 +5133,6 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
}
if (alter_info->partition_flags & ALTER_PARTITION_ADD)
{
if ((alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN) &&
!(tab_part_info->part_type == RANGE_PARTITION ||
tab_part_info->part_type == LIST_PARTITION))
{
my_error(ER_ONLY_ON_RANGE_LIST_PARTITION, MYF(0), "CONVERT TABLE TO");
goto err;
}
if (*fast_alter_table && thd->locked_tables_mode)
{
MEM_ROOT *old_root= thd->mem_root;
Expand Down

0 comments on commit 2092881

Please sign in to comment.