diff options
author | Sergei Golubchik <serg@mariadb.org> | 2018-02-21 15:16:19 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-02-23 19:17:48 +0100 |
commit | e36c5ec0a50332840c7dcb8e6b08a369ec2a829c (patch) | |
tree | af84bd00042773cabddb4150748601c53d78b783 /mysql-test | |
parent | 7961bc4b890071f281da88845489cdddc54c289b (diff) | |
download | mariadb-git-e36c5ec0a50332840c7dcb8e6b08a369ec2a829c.tar.gz |
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
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/suite/versioning/r/partition.result | 150 | ||||
-rw-r--r-- | mysql-test/suite/versioning/r/truncate.result | 2 | ||||
-rw-r--r-- | mysql-test/suite/versioning/t/partition.test | 72 |
3 files changed, 186 insertions, 38 deletions
diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index eba177460ed..5c305a9005e 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -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 +5 select * from t1 partition (p0sp1); x +2 +4 select * from t1 partition (p1sp0); x -5 select * from t1 partition (p1sp1); x -2 -4 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; diff --git a/mysql-test/suite/versioning/r/truncate.result b/mysql-test/suite/versioning/r/truncate.result index 68f37aaf4ef..33f21d6245b 100644 --- a/mysql-test/suite/versioning/r/truncate.result +++ b/mysql-test/suite/versioning/r/truncate.result @@ -56,8 +56,6 @@ partition pn current); insert into t values (1); update t set a= 2; update t set a= 3; -Warnings: -Note 4114 Versioned table `test`.`t`: switching from partition `p0` to `p1` delete history from t; select * from t for system_time all; a diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index c2f98cb304f..67f95aa9c49 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -139,10 +139,6 @@ prepare select_pn from @str; execute select_p0; execute select_pn; ---echo ## pruning check ---replace_regex /\d/N/ /ALL/system/ /Using where// -explain partitions select * from t1; - set @str= concat('select row_start from t1 partition (pn) into @ts0'); prepare stmt from @str; execute stmt; drop prepare stmt; @@ -212,14 +208,14 @@ show create table t1; --error ER_DROP_PARTITION_NON_EXISTENT alter table t1 drop partition non_existent; -insert into t1 values (1), (2), (3); +insert into t1 values (1), (2), (3), (4), (5), (6); select * from t1 partition (pn); ---echo ### warn about partition switching +delete from t1 where x < 4; delete from t1; select * from t1 partition (p0); select * from t1 partition (p1); -insert into t1 values (4), (5); +insert into t1 values (7), (8); --echo ### warn about full partition delete from t1; select * from t1 partition (p1) order by x; @@ -241,6 +237,14 @@ partition by system_time interval 0 second ( partition p1 history, partition pn current); +--error ER_PARSE_ERROR +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); + --echo ### ha_partition::update_row() check create or replace table t1 (x int) with system versioning @@ -288,7 +292,9 @@ insert into t1 (x) values (1), (2), (3), (4), (5); select * from t1 partition (pnsp0); select * from t1 partition (pnsp1); ---echo ### warn about partition switching and about full partition +--echo ### warn about full partition +delete from t1 where x < 3; +delete from t1; delete from t1; select * from t1 partition (p0sp0); select * from t1 partition (p0sp1); @@ -384,6 +390,56 @@ alter table t1 add partition (partition p1 history); insert into t1 values (1); unlock tables; +--error ER_DATA_OUT_OF_RANGE +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 +); + +# INTERVAL and ALTER TABLE +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'; +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'; +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'; +--error ER_VERS_DROP_PARTITION_INTERVAL +alter table t1 drop partition p2; +select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1'; + +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; +sleep 1; +insert t1 values (2); delete from t1; +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'; + +--echo ## 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); +--sorted_result +select * from t1; +explain partitions select * from t1; +--replace_column 10 # +explain partitions select * from t1 for system_time as of from_unixtime(@ts); +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; +--replace_column 5 # 10 # 11 # +explain partitions select * from t1 for system_time all where row_end = @ts; + --echo # Test cleanup drop database test; create database test; |