1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +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

@@ -1157,6 +1157,76 @@ drop tables t1;
--disable_prepare_warnings
--echo #
--echo # MDEV-27328 Change of SYSTEM_TIME partitioning options is not possible without data copy
--echo #
create or replace table t1 (f int) with system versioning
partition by hash(f);
alter table t1 partition by system_time;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
create or replace table t1 (f int) with system versioning
partition by system_time;
alter table t1 partition by hash(f);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
create or replace table t1 (x int) with system versioning;
alter table t1 partition by system_time;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
create or replace table t1 (x int) with system versioning
partition by system_time limit 100 partitions 4;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
alter table t1 add partition partitions 2;
alter table t1 partition by system_time;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
alter table t1 partition by system_time limit 33;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
set timestamp= unix_timestamp('2000-01-01 00:00:00');
insert t1 values (0);
set timestamp= unix_timestamp('2000-01-01 00:10:00');
update t1 set x= x + 1;
set timestamp= unix_timestamp('2000-01-01 01:00:00');
update t1 set x= x + 1;
set timestamp= unix_timestamp('2000-01-01 01:30:00');
update t1 set x= x + 1;
set timestamp= unix_timestamp('2000-01-01 02:00:00');
update t1 set x= x + 1;
# When we switch to INTERVAL we must reorganize partitions.
# Otherwise pruning won't work correctly.
alter table t1 partition by system_time interval 1 hour
starts '2000-01-01 00:00:00';
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
select * from t1 partition (p0);
select * from t1 partition (p1);
select * from t1 partition (p2);
select * from t1 partition (pn);
set timestamp= default;
# When we switch to LIMIT we probably don't want to reorganize old partitions.
# Note: reorganize for LIMIT is broken, it pushes all history into first partition.
# TODO: MDEV-27337
alter table t1 partition by system_time limit 1;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
update t1 set x= x + 1;
update t1 set x= x + 1;
select * from t1 partition (p0);
select * from t1 partition (p1);
select * from t1 partition (p2);
select * from t1 partition (p3);
select * from t1 partition (p4);
select * from t1 partition (pn);
drop table t1;
--echo #
--echo # End of 10.5 tests
--echo #