1
0
mirror of https://github.com/MariaDB/server.git synced 2025-09-02 09:41:40 +03:00

PARTITION BY SYSTEM_TIME INTERVAL ...

Lots of changes:
* calculate the current history partition in ::external_lock(),
  not in ::write_row() or ::update_row()
* remove dynamically collected per-partition row_end stats
* no full table scan in open_table_from_share to calculate these
  stats, no manual MDL/thr_locks in open_table_from_share
* no shared stats in TABLE_SHARE = no mutexes or condition waits when
  calculating current history partition
* always compare timestamps, don't convert them to MYSQL_TIME
  (avoid DST ambiguity, and it's faster too)
* correct interval handling, 1 month = 1 month, not 30 * 24 * 3600 seconds
* save/restore first partition start time, and count intervals from there
* only allow to drop first partitions if INTERVAL
* when adding new history partitions, split the data in the last history
  parition, if it was overflowed
* show partition boundaries in INFORMATION_SCHEMA.PARTITIONS
This commit is contained in:
Sergei Golubchik
2018-02-21 15:16:19 +01:00
parent 7961bc4b89
commit e36c5ec0a5
16 changed files with 463 additions and 974 deletions

View File

@@ -137,10 +137,6 @@ x A B
execute select_pn;
x C D
1 1 1
## pruning check
explain partitions select * from tN;
id select_type table partitions type possible_keys key key_len ref rows Extra
N SIMPLE tN pN,pn system NULL NULL NULL NULL N
set @str= concat('select row_start from t1 partition (pn) into @ts0');
prepare stmt from @str;
execute stmt;
@@ -225,33 +221,41 @@ t1 CREATE TABLE `t1` (
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
alter table t1 drop partition non_existent;
ERROR HY000: Error in list of partitions to DROP
insert into t1 values (1), (2), (3);
insert into t1 values (1), (2), (3), (4), (5), (6);
select * from t1 partition (pn);
x
1
2
3
### warn about partition switching
4
5
6
delete from t1 where x < 4;
delete from t1;
Warnings:
Note 4114 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
select * from t1 partition (p0);
x
1
2
3
select * from t1 partition (p1);
x
3
insert into t1 values (4), (5);
4
5
6
insert into t1 values (7), (8);
Warnings:
Warning 4112 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
### warn about full partition
delete from t1;
Warnings:
Warning 4112 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
select * from t1 partition (p1) order by x;
x
3
4
5
6
7
8
### Assertion in ALTER on warning from partitioning LIMIT [#446]
create or replace table t1 (x int) with system versioning;
insert into t1 values (1), (2);
@@ -259,8 +263,6 @@ delete from t1;
alter table t1 partition by system_time limit 1 (
partition p1 history,
partition pn current);
Warnings:
Note 4112 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
## rotation by INTERVAL
create or replace table t1 (x int)
with system versioning
@@ -269,6 +271,16 @@ partition p0 history,
partition p1 history,
partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'
create or replace table t1 (x int)
with system versioning
partition by system_time interval 1 second starts 12345 (
partition p0 history,
partition p1 history,
partition pn current);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'starts 12345 (
partition p0 history,
partition p1 history,
partition pn current)' at line 3
### ha_partition::update_row() check
create or replace table t1 (x int)
with system versioning
@@ -286,7 +298,7 @@ x
delete from t1 where x < 3;
delete from t1;
Warnings:
Note 4114 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
Warning 4112 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
select * from t1 partition (p0) order by x;
x
1
@@ -306,7 +318,7 @@ insert into t1 values (1);
update t1 set x= 2;
update t1 set x= 3;
Warnings:
Note 4114 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
Warning 4112 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
select * from t1 partition (p0);
x
1
@@ -332,24 +344,23 @@ select * from t1 partition (pnsp1);
x
2
4
### warn about partition switching and about full partition
### warn about full partition
delete from t1 where x < 3;
delete from t1;
delete from t1;
Warnings:
Note 4114 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
Warning 4112 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
select * from t1 partition (p0sp0);
x
1
3
select * from t1 partition (p0sp1);
x
select * from t1 partition (p1sp0);
x
5
select * from t1 partition (p1sp1);
select * from t1 partition (p0sp1);
x
2
4
select * from t1 partition (p1sp0);
x
select * from t1 partition (p1sp1);
x
create or replace table t1 (a bigint)
with system versioning
partition by range (a)
@@ -419,14 +430,8 @@ alter table t1 partition by system_time limit 1 (
partition p1 history,
partition p2 history,
partition pn current);
Warnings:
Note 4114 Versioned table `test`.`t1`: switching from partition `p1` to `p2`
delete from t1 where x = 1;
Warnings:
Warning 4112 Versioned table `test`.`t1`: partition `p2` is full, add more HISTORY partitions
delete from t1 where x = 2;
Warnings:
Warning 4112 Versioned table `test`.`t1`: partition `p2` is full, add more HISTORY partitions
# MDEV-14923 Assertion upon INSERT into locked versioned partitioned table
create or replace table t1 (x int) with system versioning
partition by system_time (partition p1 history, partition pn current);
@@ -435,6 +440,95 @@ alter table t1 add partition (partition p1 history);
ERROR HY000: Duplicate partition name p1
insert into t1 values (1);
unlock tables;
create or replace table t1 (pk int) with system versioning
partition by system_time interval 10 year (
partition p1 history,
partition p2 history,
partition pn current
);
ERROR 22003: TIMESTAMP value is out of range in 'INTERVAL'
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour (
partition p0 history, partition pn current);
set @ts=(select partition_description from information_schema.partitions
where table_schema='test' and table_name='t1' and partition_name='p0');
alter table t1 add column b int;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p0 1 SYSTEM_TIME 00:00:00.000000
pn 2 SYSTEM_TIME NULL
Warnings:
Warning 1292 Truncated incorrect time value: 'CURRENT'
alter table t1 add partition (partition p1 history, partition p2 history);
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p0 1 SYSTEM_TIME 00:00:00.000000
p1 2 SYSTEM_TIME 01:00:00.000000
p2 3 SYSTEM_TIME 02:00:00.000000
pn 4 SYSTEM_TIME NULL
Warnings:
Warning 1292 Truncated incorrect time value: 'CURRENT'
alter table t1 drop partition p0;
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p1 1 SYSTEM_TIME 01:00:00.000000
p2 2 SYSTEM_TIME 02:00:00.000000
pn 3 SYSTEM_TIME NULL
Warnings:
Warning 1292 Truncated incorrect time value: 'CURRENT'
alter table t1 drop partition p2;
ERROR HY000: Can only drop oldest partitions when rotating by INTERVAL
select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
partition_name partition_ordinal_position partition_method timediff(partition_description, @ts)
p1 1 SYSTEM_TIME 01:00:00.000000
p2 2 SYSTEM_TIME 02:00:00.000000
pn 3 SYSTEM_TIME NULL
Warnings:
Warning 1292 Truncated incorrect time value: 'CURRENT'
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 second
subpartition by key (i) subpartitions 2
(partition p1 history, partition pn current);
insert t1 values (1);
delete from t1;
insert t1 values (2);
Warnings:
Warning 4112 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
delete from t1;
Warnings:
Warning 4112 Versioned table `test`.`t1`: partition `p1` is full, add more HISTORY partitions
alter table t1 add partition (partition p0 history, partition p2 history);
select subpartition_name,table_rows from information_schema.partitions where table_schema='test' and table_name='t1';
subpartition_name table_rows
p1sp0 1
p1sp1 0
p0sp0 0
p0sp1 1
p2sp0 0
p2sp1 0
pnsp0 0
pnsp1 0
## pruning check
set @ts=(select partition_description from information_schema.partitions
where table_schema='test' and table_name='t1' and partition_name='p0' limit 1);
insert into t1 values (4),(5);
select * from t1;
i
4
5
explain partitions select * from t1;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 for system_time as of from_unixtime(@ts);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1_p1sp0,p1_p1sp1,p0_p0sp0,p0_p0sp1,p2_p2sp0,p2_p2sp1,pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL # Using where
set @ts=(select row_end from t1 for system_time all where i=1);
select * from t1 for system_time all where row_end = @ts;
i
1
explain partitions select * from t1 for system_time all where row_end = @ts;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1_p1sp0,p1_p1sp1 # NULL NULL NULL NULL # #
# Test cleanup
drop database test;
create database test;