Commit 777b3996 authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-19903 Setup default partitions for system versioning

Implement syntax like:

create table t1 (x int) with system versioning partition by system_time;

which will create 1 history partition and 1 current partition.
Also it is possible to specify the number of history partitions:

create table t1 (x int) with system versioning partition by system_time partitions 5;

which will create 4 history partitions (and 1 current partition).

Tests:
partition.test cases are duplicated where it is appropriate for default partitions.
partition_rotation.test cases are replaced by default partitions where possible.
parent f60eeee9
...@@ -121,12 +121,10 @@ select x from t1; ...@@ -121,12 +121,10 @@ select x from t1;
x x
1 1
2 2
# Bug #260: incorrect IB partitioning warning # Bug tempesta-tech/mariadb#260: incorrect IB partitioning warning
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time limit 1 ( partition by system_time limit 1;
partition p0 history,
partition pn current);
alter table t1 change x big int; alter table t1 change x big int;
create or replace table t1 (i int) engine myisam partition by hash(i) partitions 2; create or replace table t1 (i int) engine myisam partition by hash(i) partitions 2;
alter table t1 add partition (partition px history); alter table t1 add partition (partition px history);
...@@ -134,9 +132,7 @@ ERROR HY000: Wrong partitioning type, expected type: `SYSTEM_TIME` ...@@ -134,9 +132,7 @@ ERROR HY000: Wrong partitioning type, expected type: `SYSTEM_TIME`
## INSERT, UPDATE, DELETE ## INSERT, UPDATE, DELETE
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time ( partition by system_time;
partition p0 history,
partition pn current);
set @now= now(6); set @now= now(6);
insert into t1 values (1); insert into t1 values (1);
set @str= concat('select x, row_start < @now as A, row_end > @now as B from t1 partition (p0)'); set @str= concat('select x, row_start < @now as A, row_end > @now as B from t1 partition (p0)');
...@@ -222,26 +218,18 @@ select @ts2 = @ts3; ...@@ -222,26 +218,18 @@ select @ts2 = @ts3;
## rotation by LIMIT ## rotation by LIMIT
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time limit 0 ( partition by system_time limit 0 partitions 3;
partition p0 history,
partition p1 history,
partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'LIMIT' ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'LIMIT'
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time limit 2 ( partition by system_time limit 2 partitions 3;
partition p0 history,
partition p1 history,
partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL `x` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME LIMIT 2 PARTITION BY SYSTEM_TIME LIMIT 2
(PARTITION `p0` HISTORY ENGINE = DEFAULT_ENGINE, PARTITIONS 3
PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
alter table t1 drop partition non_existent; alter table t1 drop partition non_existent;
ERROR HY000: Error in list of partitions to DROP ERROR HY000: Error in list of partitions to DROP
insert into t1 values (1), (2), (3), (4), (5), (6); insert into t1 values (1), (2), (3), (4), (5), (6);
...@@ -289,25 +277,17 @@ partition pn current); ...@@ -289,25 +277,17 @@ partition pn current);
## rotation by INTERVAL ## rotation by INTERVAL
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time interval 0 second ( partition by system_time interval 0 second partitions 3;
partition p0 history,
partition p1 history,
partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL' ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'
create table t1 (i int) with system versioning create table t1 (i int) with system versioning
partition by system_time interval 6 day limit 98 partition by system_time interval 6 day limit 98;
(partition p0 history, partition ver_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 'limit 98' at line 2
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 'limit 98
(partition p0 history, partition ver_pn current)' at line 2
## Subpartitions ## Subpartitions
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time limit 2 partition by system_time limit 2 partitions 3
subpartition by key (x) subpartition by key (x)
subpartitions 2 ( subpartitions 2;
partition p0 history,
partition p1 history,
partition pn current);
insert into t1 (x) values (1), (2), (3), (4), (5); insert into t1 (x) values (1), (2), (3), (4), (5);
select * from t1 partition (pnsp0); select * from t1 partition (pnsp0);
x x
...@@ -366,9 +346,7 @@ add system versioning; ...@@ -366,9 +346,7 @@ add system versioning;
insert into t1 values(); insert into t1 values();
# MDEV-14722 Assertion in ha_commit_trans for sub-statement # MDEV-14722 Assertion in ha_commit_trans for sub-statement
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day ( partition by system_time interval 1 day;
partition p1 history,
partition pc current);
create or replace table t2 (f int); create or replace table t2 (f int);
create or replace trigger tr before insert on t2 create or replace trigger tr before insert on t2
for each row select table_rows from information_schema.tables for each row select table_rows from information_schema.tables
...@@ -378,9 +356,7 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be ...@@ -378,9 +356,7 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be
insert into t2 values (1); insert into t2 values (1);
# MDEV-14740 Locking assertion for system_time partitioning # MDEV-14740 Locking assertion for system_time partitioning
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 week ( partition by system_time interval 1 week;
partition p1 history,
partition pn current);
create or replace table t2 (f int); create or replace table t2 (f int);
create or replace trigger tr before insert on t2 create or replace trigger tr before insert on t2
for each row select count(*) from t1 into @a; for each row select count(*) from t1 into @a;
...@@ -415,22 +391,17 @@ delete from t1 where x = 1; ...@@ -415,22 +391,17 @@ delete from t1 where x = 1;
delete from t1 where x = 2; delete from t1 where x = 2;
# MDEV-14923 Assertion upon INSERT into locked versioned partitioned table # MDEV-14923 Assertion upon INSERT into locked versioned partitioned table
create or replace table t1 (x int) with system versioning create or replace table t1 (x int) with system versioning
partition by system_time (partition p1 history, partition pn current); partition by system_time;
lock table t1 write; lock table t1 write;
alter table t1 add partition (partition p1 history); alter table t1 add partition (partition p0 history);
ERROR HY000: Duplicate partition name p1 ERROR HY000: Duplicate partition name p0
insert into t1 values (1); insert into t1 values (1);
unlock tables; unlock tables;
create or replace table t1 (pk int) with system versioning create or replace table t1 (pk int) with system versioning
partition by system_time interval 10 year ( partition by system_time interval 10 year partitions 3;
partition p1 history,
partition p2 history,
partition pn current
);
ERROR 22003: TIMESTAMP value is out of range in 'INTERVAL' ERROR 22003: TIMESTAMP value is out of range in 'INTERVAL'
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour ( partition by system_time interval 1 hour;
partition p0 history, partition pn current);
set @ts=(select partition_description from information_schema.partitions set @ts=(select partition_description from information_schema.partitions
where table_schema='test' and table_name='t1' and partition_name='p0'); where table_schema='test' and table_name='t1' and partition_name='p0');
alter table t1 add column b int; alter table t1 add column b int;
...@@ -470,7 +441,7 @@ Warning 1292 Incorrect time value: 'CURRENT' ...@@ -470,7 +441,7 @@ Warning 1292 Incorrect time value: 'CURRENT'
# MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW # MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW
# #
create or replace table t1 (pk int primary key, f int) with system versioning create or replace table t1 (pk int primary key, f int) with system versioning
partition by system_time limit 100 (partition p1 history, partition pn current); partition by system_time limit 100;
insert into t1 values (1,10), (2,20); insert into t1 values (1,10), (2,20);
create or replace view v1 as select * from t1; create or replace view v1 as select * from t1;
update v1 set f= 30; update v1 set f= 30;
...@@ -478,7 +449,7 @@ update v1 set f= 30; ...@@ -478,7 +449,7 @@ update v1 set f= 30;
# MDEV-15168 Unexpected ER_VERS_ENGINE_UNSUPPORTED upon dropping versioning on a partitioned table # MDEV-15168 Unexpected ER_VERS_ENGINE_UNSUPPORTED upon dropping versioning on a partitioned table
# #
create or replace table t (a int) with system versioning create or replace table t (a int) with system versioning
partition by system_time (partition p1 history, partition pn current); partition by system_time;
alter table t drop system versioning; alter table t drop system versioning;
ERROR HY000: Can not DROP SYSTEM VERSIONING for table `t` partitioned BY SYSTEM_TIME ERROR HY000: Can not DROP SYSTEM VERSIONING for table `t` partitioned BY SYSTEM_TIME
# MDEV-15191 Assertion `bit < (map)->n_bits' failed in bitmap_is_set upon INSERT # MDEV-15191 Assertion `bit < (map)->n_bits' failed in bitmap_is_set upon INSERT
...@@ -492,15 +463,13 @@ insert into t1 values (4); ...@@ -492,15 +463,13 @@ insert into t1 values (4);
unlock tables; unlock tables;
# MDEV-15036 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' in Diagnostics_area::set_ok_status or unexpected ER_RANGE_NOT_INCREASING_ERROR # MDEV-15036 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' in Diagnostics_area::set_ok_status or unexpected ER_RANGE_NOT_INCREASING_ERROR
create or replace table t1 (a int) with system versioning create or replace table t1 (a int) with system versioning
partition by system_time limit 2 ( partition by system_time limit 2 partitions 4;
partition p1 history, partition p2 history,
partition p3 history, partition pn current);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
update t1 set a = 4; update t1 set a = 4;
delete from t1; delete from t1;
delete from t1 where a is not null; delete from t1 where a is not null;
# MDEV-14823 Wrong error message upon selecting from a system_time partition # MDEV-14823 Wrong error message upon selecting from a system_time partition
create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current); create or replace table t1 (i int) with system versioning partition by system_time limit 10;
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0) for system_time all;
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
# MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
...@@ -525,9 +494,7 @@ delete from t1 where pk in (11, 12); ...@@ -525,9 +494,7 @@ delete from t1 where pk in (11, 12);
# MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_arguments # MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_arguments
# #
create or replace table t1 (pk int) with system versioning create or replace table t1 (pk int) with system versioning
partition by system_time interval 7 second ( partition by system_time interval 7 second;
partition ver_p1 history,
partition ver_pn current);
alter table t1 alter table t1
partition by system_time interval column_get(column_create(7,7), 7 as int) second ( partition by system_time interval column_get(column_create(7,7), 7 as int) second (
partition ver_p1 history, partition ver_p1 history,
...@@ -563,5 +530,39 @@ unlock tables; ...@@ -563,5 +530,39 @@ unlock tables;
create or replace table t1 (pk int primary key) with system versioning partition by system_time limit 100 (partition p1 history, partition pn current); create or replace table t1 (pk int primary key) with system versioning partition by system_time limit 100 (partition p1 history, partition pn current);
execute immediate 'select * from t1 for update'; execute immediate 'select * from t1 for update';
pk pk
#
# MDEV-19903 Setup default partitions for system versioning
#
create or replace table t1 (x int) with system versioning partition by system_time;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME
PARTITIONS 2
# 2 partitions are created: p0 and pn
select PARTITION_NAME, PARTITION_METHOD, PARTITION_DESCRIPTION from information_schema.partitions where table_name = 't1' order by PARTITION_NAME;
PARTITION_NAME PARTITION_METHOD PARTITION_DESCRIPTION
p0 SYSTEM_TIME NULL
pn SYSTEM_TIME CURRENT
create or replace table t1 (x int) with system versioning partition by system_time partitions 4;
Warnings:
Warning 4115 Maybe missing parameters: no rotation condition for multiple HISTORY partitions.
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME
PARTITIONS 4
# 4 partitions are created: p0, p1, p2 and pn
select PARTITION_NAME, PARTITION_METHOD, PARTITION_DESCRIPTION from information_schema.partitions where table_name = 't1' order by PARTITION_NAME;
PARTITION_NAME PARTITION_METHOD PARTITION_DESCRIPTION
p0 SYSTEM_TIME NULL
p1 SYSTEM_TIME NULL
p2 SYSTEM_TIME NULL
pn SYSTEM_TIME CURRENT
# Test cleanup
drop view v1; drop view v1;
drop tables t, t1, t2, t3, t4; drop tables t, t1, t2, t3, t4;
...@@ -59,157 +59,130 @@ id select_type table partitions type possible_keys key key_len ref rows Extra ...@@ -59,157 +59,130 @@ 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 # # 1 SIMPLE t1 p1_p1sp0,p1_p1sp1 # NULL NULL NULL NULL # #
## INTERVAL ... STARTS ## INTERVAL ... STARTS
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts 'a' partition by system_time interval 1 day starts 'a';
(partition p0 history, partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS' ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS'
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '00:00:00' partition by system_time interval 1 day starts '00:00:00';
(partition p0 history, partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS' ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS'
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-00-01 00:00:00' partition by system_time interval 1 day starts '2000-00-01 00:00:00';
(partition p0 history, partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS' ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS'
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts 946684800 partition by system_time interval 1 day starts 946684800;
(partition p0 history, partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS' ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS'
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-01 00:00:00' partition by system_time interval 1 day starts '2000-01-01 00:00:00';
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
# Test STARTS warning # Test STARTS warning
set timestamp= unix_timestamp('2000-01-01 00:00:00'); set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day partition by system_time interval 1 day;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-01 00:00:01' partition by system_time interval 1 day starts '2000-01-01 00:00:01';
(partition p0 history, partition pn current);
Warnings: Warnings:
Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value
# Test default STARTS rounding # Test default STARTS rounding
set timestamp= unix_timestamp('1999-12-15 13:33:33'); set timestamp= unix_timestamp('1999-12-15 13:33:33');
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 second partition by system_time interval 1 second;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 SECOND STARTS TIMESTAMP'1999-12-15 13:33:33' PARTITION BY SYSTEM_TIME INTERVAL 1 SECOND STARTS TIMESTAMP'1999-12-15 13:33:33'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 minute partition by system_time interval 1 minute;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 MINUTE STARTS TIMESTAMP'1999-12-15 13:33:00' PARTITION BY SYSTEM_TIME INTERVAL 1 MINUTE STARTS TIMESTAMP'1999-12-15 13:33:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour partition by system_time interval 1 hour;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'1999-12-15 13:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'1999-12-15 13:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day partition by system_time interval 1 day;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-15 00:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-15 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 month partition by system_time interval 1 month;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 MONTH STARTS TIMESTAMP'1999-12-15 00:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 MONTH STARTS TIMESTAMP'1999-12-15 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 year partition by system_time interval 1 year;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 YEAR STARTS TIMESTAMP'1999-12-15 00:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 YEAR STARTS TIMESTAMP'1999-12-15 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
# seconds equivalent of 1 day does not round: # seconds equivalent of 1 day does not round:
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 86400 second partition by system_time interval 86400 second;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 86400 SECOND STARTS TIMESTAMP'1999-12-15 13:33:33' PARTITION BY SYSTEM_TIME INTERVAL 86400 SECOND STARTS TIMESTAMP'1999-12-15 13:33:33'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
# STARTS value is in local time_zone: # STARTS value is in local time_zone:
set time_zone="+03:00"; set time_zone="+03:00";
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-01 00:00:00' partition by system_time interval 1 day starts '2000-01-01 00:00:00';
(partition p0 history, partition pn current);
Warnings: Warnings:
Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value
set timestamp= unix_timestamp('2000-01-01 00:00:00'); set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t2 (i int) with system versioning create or replace table t2 (i int) with system versioning
partition by system_time interval 1 day partition by system_time interval 1 day;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
show create table t2; show create table t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( t2 CREATE TABLE `t2` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
set time_zone="+00:00"; set time_zone="+00:00";
show create table t1; show create table t1;
Table Create Table Table Create Table
...@@ -217,22 +190,20 @@ t1 CREATE TABLE `t1` ( ...@@ -217,22 +190,20 @@ t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-31 21:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-31 21:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
show create table t2; show create table t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( t2 CREATE TABLE `t2` (
`i` int(11) DEFAULT NULL `i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-31 21:00:00' PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-31 21:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM, PARTITIONS 2
PARTITION `pn` CURRENT ENGINE = MyISAM)
# Test rotation # Test rotation
set timestamp= unix_timestamp('2001-01-01 00:00:00'); set timestamp= unix_timestamp('2001-01-01 00:00:00');
# it's ok to add partitions for past: # it's ok to add partitions for past:
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-01 00:00:00' partition by system_time interval 1 day starts '2000-01-01 00:00:00'
(partition p0 history, partition p1 history, partition pn current); partitions 3;
# we are warned when we push to present: # we are warned when we push to present:
insert into t1 values (0); insert into t1 values (0);
Warnings: Warnings:
...@@ -255,7 +226,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00'); ...@@ -255,7 +226,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00');
# now we "overflow" first partition a bit: # now we "overflow" first partition a bit:
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-03 00:00:00' partition by system_time interval 1 day starts '2000-01-03 00:00:00'
(partition p0 history, partition p1 history, partition pn current); partitions 3;
Warnings: Warnings:
Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value
insert into t1 values (0); insert into t1 values (0);
...@@ -279,7 +250,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00'); ...@@ -279,7 +250,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00');
# and this is how it usually goes: # and this is how it usually goes:
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day partition by system_time interval 1 day
(partition p0 history, partition p1 history, partition pn current); partitions 3;
insert into t1 values (0); insert into t1 values (0);
set timestamp= unix_timestamp('2000-01-01 00:00:01'); set timestamp= unix_timestamp('2000-01-01 00:00:01');
update t1 set i= i + 1; update t1 set i= i + 1;
......
...@@ -123,12 +123,10 @@ alter table t1 drop partition p0; ...@@ -123,12 +123,10 @@ alter table t1 drop partition p0;
select x from t1; select x from t1;
--echo # Bug #260: incorrect IB partitioning warning --echo # Bug tempesta-tech/mariadb#260: incorrect IB partitioning warning
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time limit 1 ( partition by system_time limit 1;
partition p0 history,
partition pn current);
alter table t1 change x big int; alter table t1 change x big int;
create or replace table t1 (i int) engine myisam partition by hash(i) partitions 2; create or replace table t1 (i int) engine myisam partition by hash(i) partitions 2;
...@@ -139,9 +137,7 @@ alter table t1 add partition (partition px history); ...@@ -139,9 +137,7 @@ alter table t1 add partition (partition px history);
--echo ## INSERT, UPDATE, DELETE --echo ## INSERT, UPDATE, DELETE
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time ( partition by system_time;
partition p0 history,
partition pn current);
set @now= now(6); set @now= now(6);
insert into t1 values (1); insert into t1 values (1);
...@@ -204,17 +200,11 @@ select @ts2 = @ts3; ...@@ -204,17 +200,11 @@ select @ts2 = @ts3;
--error ER_PART_WRONG_VALUE --error ER_PART_WRONG_VALUE
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time limit 0 ( partition by system_time limit 0 partitions 3;
partition p0 history,
partition p1 history,
partition pn current);
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time limit 2 ( partition by system_time limit 2 partitions 3;
partition p0 history,
partition p1 history,
partition pn current);
--replace_result $default_engine DEFAULT_ENGINE --replace_result $default_engine DEFAULT_ENGINE
show create table t1; show create table t1;
...@@ -246,25 +236,18 @@ alter table t1 partition by system_time limit 1 ( ...@@ -246,25 +236,18 @@ alter table t1 partition by system_time limit 1 (
--error ER_PART_WRONG_VALUE --error ER_PART_WRONG_VALUE
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time interval 0 second ( partition by system_time interval 0 second partitions 3;
partition p0 history,
partition p1 history,
partition pn current);
--error ER_PARSE_ERROR --error ER_PARSE_ERROR
create table t1 (i int) with system versioning create table t1 (i int) with system versioning
partition by system_time interval 6 day limit 98 partition by system_time interval 6 day limit 98;
(partition p0 history, partition ver_pn current);
--echo ## Subpartitions --echo ## Subpartitions
create or replace table t1 (x int) create or replace table t1 (x int)
with system versioning with system versioning
partition by system_time limit 2 partition by system_time limit 2 partitions 3
subpartition by key (x) subpartition by key (x)
subpartitions 2 ( subpartitions 2;
partition p0 history,
partition p1 history,
partition pn current);
insert into t1 (x) values (1), (2), (3), (4), (5); insert into t1 (x) values (1), (2), (3), (4), (5);
select * from t1 partition (pnsp0); select * from t1 partition (pnsp0);
...@@ -316,9 +299,7 @@ insert into t1 values(); ...@@ -316,9 +299,7 @@ insert into t1 values();
--echo # MDEV-14722 Assertion in ha_commit_trans for sub-statement --echo # MDEV-14722 Assertion in ha_commit_trans for sub-statement
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day ( partition by system_time interval 1 day;
partition p1 history,
partition pc current);
create or replace table t2 (f int); create or replace table t2 (f int);
create or replace trigger tr before insert on t2 create or replace trigger tr before insert on t2
for each row select table_rows from information_schema.tables for each row select table_rows from information_schema.tables
...@@ -327,9 +308,7 @@ insert into t2 values (1); ...@@ -327,9 +308,7 @@ insert into t2 values (1);
--echo # MDEV-14740 Locking assertion for system_time partitioning --echo # MDEV-14740 Locking assertion for system_time partitioning
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 week ( partition by system_time interval 1 week;
partition p1 history,
partition pn current);
create or replace table t2 (f int); create or replace table t2 (f int);
create or replace trigger tr before insert on t2 create or replace trigger tr before insert on t2
for each row select count(*) from t1 into @a; for each row select count(*) from t1 into @a;
...@@ -360,31 +339,25 @@ update t1 set x= x + 1; ...@@ -360,31 +339,25 @@ update t1 set x= x + 1;
alter table t1 partition by system_time limit 1 ( alter table t1 partition by system_time limit 1 (
partition p1 history, partition p1 history,
partition p2 history, partition p2 history,
partition pn current); partition pn current);delete from t1 where x = 1;
delete from t1 where x = 1;
delete from t1 where x = 2; delete from t1 where x = 2;
--echo # MDEV-14923 Assertion upon INSERT into locked versioned partitioned table --echo # MDEV-14923 Assertion upon INSERT into locked versioned partitioned table
create or replace table t1 (x int) with system versioning create or replace table t1 (x int) with system versioning
partition by system_time (partition p1 history, partition pn current); partition by system_time;
lock table t1 write; lock table t1 write;
--error ER_SAME_NAME_PARTITION --error ER_SAME_NAME_PARTITION
alter table t1 add partition (partition p1 history); alter table t1 add partition (partition p0 history);
insert into t1 values (1); insert into t1 values (1);
unlock tables; unlock tables;
--error ER_DATA_OUT_OF_RANGE --error ER_DATA_OUT_OF_RANGE
create or replace table t1 (pk int) with system versioning create or replace table t1 (pk int) with system versioning
partition by system_time interval 10 year ( partition by system_time interval 10 year partitions 3;
partition p1 history,
partition p2 history,
partition pn current
);
# INTERVAL and ALTER TABLE # INTERVAL and ALTER TABLE
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour ( partition by system_time interval 1 hour;
partition p0 history, partition pn current);
set @ts=(select partition_description from information_schema.partitions set @ts=(select partition_description from information_schema.partitions
where table_schema='test' and table_name='t1' and partition_name='p0'); where table_schema='test' and table_name='t1' and partition_name='p0');
...@@ -403,7 +376,7 @@ select partition_name,partition_ordinal_position,partition_method,timediff(parti ...@@ -403,7 +376,7 @@ select partition_name,partition_ordinal_position,partition_method,timediff(parti
--echo # MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW --echo # MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW
--echo # --echo #
create or replace table t1 (pk int primary key, f int) with system versioning create or replace table t1 (pk int primary key, f int) with system versioning
partition by system_time limit 100 (partition p1 history, partition pn current); partition by system_time limit 100;
insert into t1 values (1,10), (2,20); insert into t1 values (1,10), (2,20);
create or replace view v1 as select * from t1; create or replace view v1 as select * from t1;
update v1 set f= 30; update v1 set f= 30;
...@@ -412,7 +385,7 @@ update v1 set f= 30; ...@@ -412,7 +385,7 @@ update v1 set f= 30;
--echo # MDEV-15168 Unexpected ER_VERS_ENGINE_UNSUPPORTED upon dropping versioning on a partitioned table --echo # MDEV-15168 Unexpected ER_VERS_ENGINE_UNSUPPORTED upon dropping versioning on a partitioned table
--echo # --echo #
create or replace table t (a int) with system versioning create or replace table t (a int) with system versioning
partition by system_time (partition p1 history, partition pn current); partition by system_time;
--error ER_DROP_VERSIONING_SYSTEM_TIME_PARTITION --error ER_DROP_VERSIONING_SYSTEM_TIME_PARTITION
alter table t drop system versioning; alter table t drop system versioning;
...@@ -428,16 +401,14 @@ unlock tables; ...@@ -428,16 +401,14 @@ unlock tables;
--echo # MDEV-15036 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' in Diagnostics_area::set_ok_status or unexpected ER_RANGE_NOT_INCREASING_ERROR --echo # MDEV-15036 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' in Diagnostics_area::set_ok_status or unexpected ER_RANGE_NOT_INCREASING_ERROR
create or replace table t1 (a int) with system versioning create or replace table t1 (a int) with system versioning
partition by system_time limit 2 ( partition by system_time limit 2 partitions 4;
partition p1 history, partition p2 history,
partition p3 history, partition pn current);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
update t1 set a = 4; update t1 set a = 4;
delete from t1; delete from t1;
delete from t1 where a is not null; delete from t1 where a is not null;
--echo # MDEV-14823 Wrong error message upon selecting from a system_time partition --echo # MDEV-14823 Wrong error message upon selecting from a system_time partition
create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current); create or replace table t1 (i int) with system versioning partition by system_time limit 10;
--error ER_VERS_QUERY_IN_PARTITION --error ER_VERS_QUERY_IN_PARTITION
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0) for system_time all;
...@@ -464,9 +435,7 @@ delete from t1 where pk in (11, 12); ...@@ -464,9 +435,7 @@ delete from t1 where pk in (11, 12);
--echo # MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_arguments --echo # MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_arguments
--echo # --echo #
create or replace table t1 (pk int) with system versioning create or replace table t1 (pk int) with system versioning
partition by system_time interval 7 second ( partition by system_time interval 7 second;
partition ver_p1 history,
partition ver_pn current);
alter table t1 alter table t1
partition by system_time interval column_get(column_create(7,7), 7 as int) second ( partition by system_time interval column_get(column_create(7,7), 7 as int) second (
partition ver_p1 history, partition ver_p1 history,
...@@ -499,6 +468,22 @@ unlock tables; ...@@ -499,6 +468,22 @@ unlock tables;
create or replace table t1 (pk int primary key) with system versioning partition by system_time limit 100 (partition p1 history, partition pn current); create or replace table t1 (pk int primary key) with system versioning partition by system_time limit 100 (partition p1 history, partition pn current);
execute immediate 'select * from t1 for update'; execute immediate 'select * from t1 for update';
--echo #
--echo # MDEV-19903 Setup default partitions for system versioning
--echo #
create or replace table t1 (x int) with system versioning partition by system_time;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
--echo # 2 partitions are created: p0 and pn
select PARTITION_NAME, PARTITION_METHOD, PARTITION_DESCRIPTION from information_schema.partitions where table_name = 't1' order by PARTITION_NAME;
create or replace table t1 (x int) with system versioning partition by system_time partitions 4;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
--echo # 4 partitions are created: p0, p1, p2 and pn
select PARTITION_NAME, PARTITION_METHOD, PARTITION_DESCRIPTION from information_schema.partitions where table_name = 't1' order by PARTITION_NAME;
--echo # Test cleanup
drop view v1; drop view v1;
drop tables t, t1, t2, t3, t4; drop tables t, t1, t2, t3, t4;
......
...@@ -43,88 +43,72 @@ explain partitions select * from t1 for system_time all where row_end = @ts; ...@@ -43,88 +43,72 @@ explain partitions select * from t1 for system_time all where row_end = @ts;
--echo ## INTERVAL ... STARTS --echo ## INTERVAL ... STARTS
--error ER_PART_WRONG_VALUE --error ER_PART_WRONG_VALUE
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts 'a' partition by system_time interval 1 day starts 'a';
(partition p0 history, partition pn current);
--error ER_PART_WRONG_VALUE --error ER_PART_WRONG_VALUE
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '00:00:00' partition by system_time interval 1 day starts '00:00:00';
(partition p0 history, partition pn current);
--error ER_PART_WRONG_VALUE --error ER_PART_WRONG_VALUE
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-00-01 00:00:00' partition by system_time interval 1 day starts '2000-00-01 00:00:00';
(partition p0 history, partition pn current);
--error ER_PART_WRONG_VALUE --error ER_PART_WRONG_VALUE
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts 946684800 partition by system_time interval 1 day starts 946684800;
(partition p0 history, partition pn current);
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-01 00:00:00' partition by system_time interval 1 day starts '2000-01-01 00:00:00';
(partition p0 history, partition pn current);
show create table t1; show create table t1;
--echo # Test STARTS warning --echo # Test STARTS warning
set timestamp= unix_timestamp('2000-01-01 00:00:00'); set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day partition by system_time interval 1 day;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-01 00:00:01' partition by system_time interval 1 day starts '2000-01-01 00:00:01';
(partition p0 history, partition pn current);
--echo # Test default STARTS rounding --echo # Test default STARTS rounding
set timestamp= unix_timestamp('1999-12-15 13:33:33'); set timestamp= unix_timestamp('1999-12-15 13:33:33');
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 second partition by system_time interval 1 second;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 minute partition by system_time interval 1 minute;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour partition by system_time interval 1 hour;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day partition by system_time interval 1 day;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 month partition by system_time interval 1 month;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 year partition by system_time interval 1 year;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
--echo # seconds equivalent of 1 day does not round: --echo # seconds equivalent of 1 day does not round:
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 86400 second partition by system_time interval 86400 second;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
--echo # STARTS value is in local time_zone: --echo # STARTS value is in local time_zone:
set time_zone="+03:00"; set time_zone="+03:00";
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-01 00:00:00' partition by system_time interval 1 day starts '2000-01-01 00:00:00';
(partition p0 history, partition pn current);
set timestamp= unix_timestamp('2000-01-01 00:00:00'); set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t2 (i int) with system versioning create or replace table t2 (i int) with system versioning
partition by system_time interval 1 day partition by system_time interval 1 day;
(partition p0 history, partition pn current);
show create table t1; show create table t1;
show create table t2; show create table t2;
...@@ -137,7 +121,7 @@ set timestamp= unix_timestamp('2001-01-01 00:00:00'); ...@@ -137,7 +121,7 @@ set timestamp= unix_timestamp('2001-01-01 00:00:00');
--echo # it's ok to add partitions for past: --echo # it's ok to add partitions for past:
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-01 00:00:00' partition by system_time interval 1 day starts '2000-01-01 00:00:00'
(partition p0 history, partition p1 history, partition pn current); partitions 3;
--echo # we are warned when we push to present: --echo # we are warned when we push to present:
insert into t1 values (0); insert into t1 values (0);
...@@ -153,7 +137,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00'); ...@@ -153,7 +137,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00');
--echo # now we "overflow" first partition a bit: --echo # now we "overflow" first partition a bit:
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '2000-01-03 00:00:00' partition by system_time interval 1 day starts '2000-01-03 00:00:00'
(partition p0 history, partition p1 history, partition pn current); partitions 3;
insert into t1 values (0); insert into t1 values (0);
set timestamp= unix_timestamp('2000-01-01 00:00:01'); set timestamp= unix_timestamp('2000-01-01 00:00:01');
...@@ -172,7 +156,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00'); ...@@ -172,7 +156,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00');
--echo # and this is how it usually goes: --echo # and this is how it usually goes:
create or replace table t1 (i int) with system versioning create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day partition by system_time interval 1 day
(partition p0 history, partition p1 history, partition pn current); partitions 3;
insert into t1 values (0); insert into t1 values (0);
set timestamp= unix_timestamp('2000-01-01 00:00:01'); set timestamp= unix_timestamp('2000-01-01 00:00:01');
......
...@@ -446,7 +446,15 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file, ...@@ -446,7 +446,15 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file,
bool result= TRUE; bool result= TRUE;
DBUG_ENTER("partition_info::set_up_default_partitions"); DBUG_ENTER("partition_info::set_up_default_partitions");
if (part_type != HASH_PARTITION) if (part_type == VERSIONING_PARTITION)
{
if (use_default_num_partitions)
{
num_parts= 2;
use_default_num_partitions= false;
}
}
else if (part_type != HASH_PARTITION)
{ {
const char *error_string; const char *error_string;
if (part_type == RANGE_PARTITION) if (part_type == RANGE_PARTITION)
...@@ -482,7 +490,17 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file, ...@@ -482,7 +490,17 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file,
{ {
part_elem->engine_type= default_engine_type; part_elem->engine_type= default_engine_type;
part_elem->partition_name= default_name; part_elem->partition_name= default_name;
part_elem->id= i;
default_name+=MAX_PART_NAME_SIZE; default_name+=MAX_PART_NAME_SIZE;
if (part_type == VERSIONING_PARTITION)
{
if (i < num_parts - 1) {
part_elem->type= partition_element::HISTORY;
} else {
part_elem->type= partition_element::CURRENT;
part_elem->partition_name= "pn";
}
}
} }
else else
goto end; goto end;
...@@ -587,8 +605,9 @@ bool partition_info::set_up_defaults_for_partitioning(THD *thd, handler *file, ...@@ -587,8 +605,9 @@ bool partition_info::set_up_defaults_for_partitioning(THD *thd, handler *file,
if (!default_partitions_setup) if (!default_partitions_setup)
{ {
default_partitions_setup= TRUE; default_partitions_setup= TRUE;
if (use_default_partitions) if (use_default_partitions &&
DBUG_RETURN(set_up_default_partitions(thd, file, info, start_no)); set_up_default_partitions(thd, file, info, start_no))
DBUG_RETURN(TRUE);
if (is_sub_partitioned() && if (is_sub_partitioned() &&
use_default_subpartitions) use_default_subpartitions)
DBUG_RETURN(set_up_default_subpartitions(thd, file, info)); DBUG_RETURN(set_up_default_subpartitions(thd, file, info));
...@@ -1191,7 +1210,7 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type, ...@@ -1191,7 +1210,7 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
part_type == LIST_PARTITION || part_type == LIST_PARTITION ||
part_type == VERSIONING_PARTITION)))) part_type == VERSIONING_PARTITION))))
{ {
/* Only RANGE and LIST partitioning can be subpartitioned */ /* Only RANGE, LIST and SYSTEM_TIME partitioning can be subpartitioned */
my_error(ER_SUBPARTITION_ERROR, MYF(0)); my_error(ER_SUBPARTITION_ERROR, MYF(0));
goto end; goto end;
} }
...@@ -1255,7 +1274,7 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type, ...@@ -1255,7 +1274,7 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
if (part_type == VERSIONING_PARTITION) if (part_type == VERSIONING_PARTITION)
{ {
DBUG_ASSERT(vers_info); DBUG_ASSERT(vers_info);
if (num_parts < 2 || !vers_info->now_part) if (num_parts < 2 || !(use_default_partitions || vers_info->now_part))
{ {
DBUG_ASSERT(info); DBUG_ASSERT(info);
DBUG_ASSERT(info->alias.str); DBUG_ASSERT(info->alias.str);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment