1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

MDEV-27328 Change of SYSTEM_TIME partitioning options is not possible without data copy

When we need to add/remove or change LIMIT, INTERVAL, AUTO we have to
recreate partitioning from scratch (via data copy). Such operations
should be done fast. To remove options like LIMIT or INTERVAL one
should write:

  alter table t1 partition by system_time;

The command checks whether it is new or existing SYSTEM_TIME
partitioning. And in the case of new it behaves as CREATE would do:
adds default number of partitions (2). If SYSTEM_TIME partitioning
already existed it just changes its options: removes unspecified ones
and adds/changes those specified explicitly. In case when partitions
list was supplied it behaves as usual: does full repartitioning.

Examples:

  create or replace table t1 (x int) with system versioning
  partition by system_time limit 100 partitions 4;

  # Change LIMIT
  alter table t1 partition by system_time limit 33;

  # Remove LIMIT
  alter table t1 partition by system_time;

  # This does full repartitioning
  alter table t1 partition by system_time limit 33 partitions 4;

  # This does data copy as pruning will require records in correct partitions
  alter table t1 partition by system_time interval 1 hour
  starts '2000-01-01 00:00:00';

  # But this works fast, LIMIT will apply to DML commands
  alter table t1 partition by system_time limit 33;

To sum up, ALTER for SYSTEM_TIME partitioning does full repartitioning
when:

  - INTERVAL was added or changed;
  - partition list or partition number was specified;

Otherwise it does fast alter table.

Cleaned up dead condition in set_up_default_partitions().

Reviewed by:

  Oleksandr Byelkin <sanja@mariadb.com>
  Nikita Malyavin <nikitamalyavin@gmail.com>
This commit is contained in:
Aleksey Midenkov
2022-05-06 10:45:17 +03:00
parent 93e64d1f58
commit 75ede427e4
5 changed files with 230 additions and 4 deletions

View File

@@ -5058,6 +5058,10 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
my_error(ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
"LIST", "IN");
}
/*
Adding history partitions to non-history partitioning or
non-history parittions to history partitioning is prohibited.
*/
else if (thd->work_part_info->part_type == VERSIONING_PARTITION ||
tab_part_info->part_type == VERSIONING_PARTITION)
{
@@ -5340,6 +5344,7 @@ that are reorganised.
{
if (el->type == partition_element::CURRENT)
{
/* now_part is always last partition, we add it to the end of partitions list. */
it.remove();
now_part= el;
}
@@ -5967,11 +5972,35 @@ the generated partition syntax in a correct manner.
{
partition_info *part_info= thd->work_part_info;
bool is_native_partitioned= FALSE;
if (tab_part_info && tab_part_info->part_type == VERSIONING_PARTITION &&
tab_part_info != part_info && part_info->part_type == VERSIONING_PARTITION &&
part_info->num_parts == 0)
{
if (part_info->vers_info->interval.is_set() &&
/* TODO: equivalent intervals like 1 hour and 60 mins should be considered equal */
memcmp(&part_info->vers_info->interval,
&tab_part_info->vers_info->interval,
sizeof(Vers_part_info::interval)))
{
/* If interval is changed we can not do fast alter */
tab_part_info= tab_part_info->get_clone(thd);
}
else
{
/* NOTE: fast_alter_partition_table() works on existing TABLE data. */
*fast_alter_table= true;
table->mark_table_for_reopen();
}
*tab_part_info->vers_info= *part_info->vers_info;
thd->work_part_info= part_info= tab_part_info;
*partition_changed= true;
}
/*
Need to cater for engine types that can handle partition without
using the partition handler.
*/
if (part_info != tab_part_info)
else if (part_info != tab_part_info)
{
if (part_info->fix_parser_data(thd))
{