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;
x
1
2
# Bug #260: incorrect IB partitioning warning
# Bug tempesta-tech/mariadb#260: incorrect IB partitioning warning
create or replace table t1 (x int)
with system versioning
partition by system_time limit 1 (
partition p0 history,
partition pn current);
partition by system_time limit 1;
alter table t1 change x big int;
create or replace table t1 (i int) engine myisam partition by hash(i) partitions 2;
alter table t1 add partition (partition px history);
......@@ -134,9 +132,7 @@ ERROR HY000: Wrong partitioning type, expected type: `SYSTEM_TIME`
## INSERT, UPDATE, DELETE
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 history,
partition pn current);
partition by system_time;
set @now= now(6);
insert into t1 values (1);
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;
## rotation by LIMIT
create or replace table t1 (x int)
with system versioning
partition by system_time limit 0 (
partition p0 history,
partition p1 history,
partition pn current);
partition by system_time limit 0 partitions 3;
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'LIMIT'
create or replace table t1 (x int)
with system versioning
partition by system_time limit 2 (
partition p0 history,
partition p1 history,
partition pn current);
partition by system_time limit 2 partitions 3;
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 LIMIT 2
(PARTITION `p0` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
PARTITIONS 3
alter table t1 drop partition non_existent;
ERROR HY000: Error in list of partitions to DROP
insert into t1 values (1), (2), (3), (4), (5), (6);
......@@ -289,25 +277,17 @@ partition pn current);
## rotation by INTERVAL
create or replace table t1 (x int)
with system versioning
partition by system_time interval 0 second (
partition p0 history,
partition p1 history,
partition pn current);
partition by system_time interval 0 second partitions 3;
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'
create table t1 (i int) with system versioning
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
(partition p0 history, partition ver_pn current)' at line 2
partition by system_time interval 6 day limit 98;
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
## Subpartitions
create or replace table t1 (x int)
with system versioning
partition by system_time limit 2
partition by system_time limit 2 partitions 3
subpartition by key (x)
subpartitions 2 (
partition p0 history,
partition p1 history,
partition pn current);
subpartitions 2;
insert into t1 (x) values (1), (2), (3), (4), (5);
select * from t1 partition (pnsp0);
x
......@@ -366,9 +346,7 @@ add system versioning;
insert into t1 values();
# MDEV-14722 Assertion in ha_commit_trans for sub-statement
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day (
partition p1 history,
partition pc current);
partition by system_time interval 1 day;
create or replace table t2 (f int);
create or replace trigger tr before insert on t2
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
insert into t2 values (1);
# MDEV-14740 Locking assertion for system_time partitioning
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 week (
partition p1 history,
partition pn current);
partition by system_time interval 1 week;
create or replace table t2 (f int);
create or replace trigger tr before insert on t2
for each row select count(*) from t1 into @a;
......@@ -415,22 +391,17 @@ delete from t1 where x = 1;
delete from t1 where x = 2;
# 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);
partition by system_time;
lock table t1 write;
alter table t1 add partition (partition p1 history);
ERROR HY000: Duplicate partition name p1
alter table t1 add partition (partition p0 history);
ERROR HY000: Duplicate partition name p0
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
);
partition by system_time interval 10 year partitions 3;
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);
partition by system_time interval 1 hour;
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;
......@@ -470,7 +441,7 @@ Warning 1292 Incorrect time value: 'CURRENT'
# 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
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);
create or replace view v1 as select * from t1;
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
#
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;
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
......@@ -492,15 +463,13 @@ insert into t1 values (4);
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
create or replace table t1 (a int) with system versioning
partition by system_time limit 2 (
partition p1 history, partition p2 history,
partition p3 history, partition pn current);
partition by system_time limit 2 partitions 4;
insert into t1 values (1),(2),(3);
update t1 set a = 4;
delete from t1;
delete from t1 where a is not null;
# 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;
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
......@@ -525,9 +494,7 @@ delete from t1 where pk in (11, 12);
# MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_arguments
#
create or replace table t1 (pk int) with system versioning
partition by system_time interval 7 second (
partition ver_p1 history,
partition ver_pn current);
partition by system_time interval 7 second;
alter table t1
partition by system_time interval column_get(column_create(7,7), 7 as int) second (
partition ver_p1 history,
......@@ -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);
execute immediate 'select * from t1 for update';
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 tables t, t1, t2, t3, t4;
......@@ -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 # #
## INTERVAL ... STARTS
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts 'a'
(partition p0 history, partition pn current);
partition by system_time interval 1 day starts 'a';
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS'
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '00:00:00'
(partition p0 history, partition pn current);
partition by system_time interval 1 day starts '00:00:00';
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS'
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 p0 history, partition pn current);
partition by system_time interval 1 day starts '2000-00-01 00:00:00';
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS'
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts 946684800
(partition p0 history, partition pn current);
partition by system_time interval 1 day starts 946684800;
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'STARTS'
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 p0 history, partition pn current);
partition by system_time interval 1 day starts '2000-01-01 00:00:00';
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
# Test STARTS warning
set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day
(partition p0 history, partition pn current);
partition by system_time interval 1 day;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
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 p0 history, partition pn current);
partition by system_time interval 1 day starts '2000-01-01 00:00:01';
Warnings:
Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value
# Test default STARTS rounding
set timestamp= unix_timestamp('1999-12-15 13:33:33');
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 second
(partition p0 history, partition pn current);
partition by system_time interval 1 second;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 SECOND STARTS TIMESTAMP'1999-12-15 13:33:33'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 minute
(partition p0 history, partition pn current);
partition by system_time interval 1 minute;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 MINUTE STARTS TIMESTAMP'1999-12-15 13:33:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour
(partition p0 history, partition pn current);
partition by system_time interval 1 hour;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'1999-12-15 13:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day
(partition p0 history, partition pn current);
partition by system_time interval 1 day;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-15 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 month
(partition p0 history, partition pn current);
partition by system_time interval 1 month;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 MONTH STARTS TIMESTAMP'1999-12-15 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 year
(partition p0 history, partition pn current);
partition by system_time interval 1 year;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 YEAR STARTS TIMESTAMP'1999-12-15 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
# seconds equivalent of 1 day does not round:
create or replace table t1 (i int) with system versioning
partition by system_time interval 86400 second
(partition p0 history, partition pn current);
partition by system_time interval 86400 second;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 86400 SECOND STARTS TIMESTAMP'1999-12-15 13:33:33'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
# STARTS value is in local time_zone:
set time_zone="+03:00";
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 p0 history, partition pn current);
partition by system_time interval 1 day starts '2000-01-01 00:00:00';
Warnings:
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');
create or replace table t2 (i int) with system versioning
partition by system_time interval 1 day
(partition p0 history, partition pn current);
partition by system_time interval 1 day;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
set time_zone="+00:00";
show create table t1;
Table Create Table
......@@ -217,22 +190,20 @@ t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-31 21:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-31 21:00:00'
(PARTITION `p0` HISTORY ENGINE = MyISAM,
PARTITION `pn` CURRENT ENGINE = MyISAM)
PARTITIONS 2
# Test rotation
set timestamp= unix_timestamp('2001-01-01 00:00:00');
# it's ok to add partitions for past:
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 p0 history, partition p1 history, partition pn current);
partitions 3;
# we are warned when we push to present:
insert into t1 values (0);
Warnings:
......@@ -255,7 +226,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00');
# now we "overflow" first partition a bit:
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 p0 history, partition p1 history, partition pn current);
partitions 3;
Warnings:
Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value
insert into t1 values (0);
......@@ -279,7 +250,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00');
# and this is how it usually goes:
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day
(partition p0 history, partition p1 history, partition pn current);
partitions 3;
insert into t1 values (0);
set timestamp= unix_timestamp('2000-01-01 00:00:01');
update t1 set i= i + 1;
......
......@@ -123,12 +123,10 @@ alter table t1 drop partition p0;
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)
with system versioning
partition by system_time limit 1 (
partition p0 history,
partition pn current);
partition by system_time limit 1;
alter table t1 change x big int;
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);
--echo ## INSERT, UPDATE, DELETE
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 history,
partition pn current);
partition by system_time;
set @now= now(6);
insert into t1 values (1);
......@@ -204,17 +200,11 @@ select @ts2 = @ts3;
--error ER_PART_WRONG_VALUE
create or replace table t1 (x int)
with system versioning
partition by system_time limit 0 (
partition p0 history,
partition p1 history,
partition pn current);
partition by system_time limit 0 partitions 3;
create or replace table t1 (x int)
with system versioning
partition by system_time limit 2 (
partition p0 history,
partition p1 history,
partition pn current);
partition by system_time limit 2 partitions 3;
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
......@@ -246,25 +236,18 @@ alter table t1 partition by system_time limit 1 (
--error ER_PART_WRONG_VALUE
create or replace table t1 (x int)
with system versioning
partition by system_time interval 0 second (
partition p0 history,
partition p1 history,
partition pn current);
partition by system_time interval 0 second partitions 3;
--error ER_PARSE_ERROR
create table t1 (i int) with system versioning
partition by system_time interval 6 day limit 98
(partition p0 history, partition ver_pn current);
partition by system_time interval 6 day limit 98;
--echo ## Subpartitions
create or replace table t1 (x int)
with system versioning
partition by system_time limit 2
partition by system_time limit 2 partitions 3
subpartition by key (x)
subpartitions 2 (
partition p0 history,
partition p1 history,
partition pn current);
subpartitions 2;
insert into t1 (x) values (1), (2), (3), (4), (5);
select * from t1 partition (pnsp0);
......@@ -316,9 +299,7 @@ insert into t1 values();
--echo # MDEV-14722 Assertion in ha_commit_trans for sub-statement
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day (
partition p1 history,
partition pc current);
partition by system_time interval 1 day;
create or replace table t2 (f int);
create or replace trigger tr before insert on t2
for each row select table_rows from information_schema.tables
......@@ -327,9 +308,7 @@ insert into t2 values (1);
--echo # MDEV-14740 Locking assertion for system_time partitioning
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 week (
partition p1 history,
partition pn current);
partition by system_time interval 1 week;
create or replace table t2 (f int);
create or replace trigger tr before insert on t2
for each row select count(*) from t1 into @a;
......@@ -360,31 +339,25 @@ update t1 set x= x + 1;
alter table t1 partition by system_time limit 1 (
partition p1 history,
partition p2 history,
partition pn current);
delete from t1 where x = 1;
partition pn current);delete from t1 where x = 1;
delete from t1 where x = 2;
--echo # 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);
partition by system_time;
lock table t1 write;
--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);
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
);
partition by system_time interval 10 year partitions 3;
# 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);
partition by system_time interval 1 hour;
set @ts=(select partition_description from information_schema.partitions
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
--echo # MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW
--echo #
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);
create or replace view v1 as select * from t1;
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 #
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
alter table t drop system versioning;
......@@ -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
create or replace table t1 (a int) with system versioning
partition by system_time limit 2 (
partition p1 history, partition p2 history,
partition p3 history, partition pn current);
partition by system_time limit 2 partitions 4;
insert into t1 values (1),(2),(3);
update t1 set a = 4;
delete from t1;
delete from t1 where a is not null;
--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
select * from t1 partition (p0) for system_time all;
......@@ -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 #
create or replace table t1 (pk int) with system versioning
partition by system_time interval 7 second (
partition ver_p1 history,
partition ver_pn current);
partition by system_time interval 7 second;
alter table t1
partition by system_time interval column_get(column_create(7,7), 7 as int) second (
partition ver_p1 history,
......@@ -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);
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 tables t, t1, t2, t3, t4;
......
......@@ -43,88 +43,72 @@ explain partitions select * from t1 for system_time all where row_end = @ts;
--echo ## INTERVAL ... STARTS
--error ER_PART_WRONG_VALUE
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts 'a'
(partition p0 history, partition pn current);
partition by system_time interval 1 day starts 'a';
--error ER_PART_WRONG_VALUE
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts '00:00:00'
(partition p0 history, partition pn current);
partition by system_time interval 1 day starts '00:00:00';
--error ER_PART_WRONG_VALUE
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 p0 history, partition pn current);
partition by system_time interval 1 day starts '2000-00-01 00:00:00';
--error ER_PART_WRONG_VALUE
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day starts 946684800
(partition p0 history, partition pn current);
partition by system_time interval 1 day starts 946684800;
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 p0 history, partition pn current);
partition by system_time interval 1 day starts '2000-01-01 00:00:00';
show create table t1;
--echo # Test STARTS warning
set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day
(partition p0 history, partition pn current);
partition by system_time interval 1 day;
show create table t1;
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 p0 history, partition pn current);
partition by system_time interval 1 day starts '2000-01-01 00:00:01';
--echo # Test default STARTS rounding
set timestamp= unix_timestamp('1999-12-15 13:33:33');
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 second
(partition p0 history, partition pn current);
partition by system_time interval 1 second;
show create table t1;
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 minute
(partition p0 history, partition pn current);
partition by system_time interval 1 minute;
show create table t1;
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 hour
(partition p0 history, partition pn current);
partition by system_time interval 1 hour;
show create table t1;
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day
(partition p0 history, partition pn current);
partition by system_time interval 1 day;
show create table t1;
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 month
(partition p0 history, partition pn current);
partition by system_time interval 1 month;
show create table t1;
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 year
(partition p0 history, partition pn current);
partition by system_time interval 1 year;
show create table t1;
--echo # seconds equivalent of 1 day does not round:
create or replace table t1 (i int) with system versioning
partition by system_time interval 86400 second
(partition p0 history, partition pn current);
partition by system_time interval 86400 second;
show create table t1;
--echo # STARTS value is in local time_zone:
set time_zone="+03:00";
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 p0 history, partition pn current);
partition by system_time interval 1 day starts '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
partition by system_time interval 1 day
(partition p0 history, partition pn current);
partition by system_time interval 1 day;
show create table t1;
show create table t2;
......@@ -137,7 +121,7 @@ set timestamp= unix_timestamp('2001-01-01 00:00:00');
--echo # it's ok to add partitions for past:
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 p0 history, partition p1 history, partition pn current);
partitions 3;
--echo # we are warned when we push to present:
insert into t1 values (0);
......@@ -153,7 +137,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00');
--echo # now we "overflow" first partition a bit:
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 p0 history, partition p1 history, partition pn current);
partitions 3;
insert into t1 values (0);
set timestamp= unix_timestamp('2000-01-01 00:00:01');
......@@ -172,7 +156,7 @@ set timestamp= unix_timestamp('2000-01-01 00:00:00');
--echo # and this is how it usually goes:
create or replace table t1 (i int) with system versioning
partition by system_time interval 1 day
(partition p0 history, partition p1 history, partition pn current);
partitions 3;
insert into t1 values (0);
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,
bool result= TRUE;
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;
if (part_type == RANGE_PARTITION)
......@@ -482,7 +490,17 @@ bool partition_info::set_up_default_partitions(THD *thd, handler *file,
{
part_elem->engine_type= default_engine_type;
part_elem->partition_name= default_name;
part_elem->id= i;
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
goto end;
......@@ -587,8 +605,9 @@ bool partition_info::set_up_defaults_for_partitioning(THD *thd, handler *file,
if (!default_partitions_setup)
{
default_partitions_setup= TRUE;
if (use_default_partitions)
DBUG_RETURN(set_up_default_partitions(thd, file, info, start_no));
if (use_default_partitions &&
set_up_default_partitions(thd, file, info, start_no))
DBUG_RETURN(TRUE);
if (is_sub_partitioned() &&
use_default_subpartitions)
DBUG_RETURN(set_up_default_subpartitions(thd, file, info));
......@@ -1191,7 +1210,7 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
part_type == LIST_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));
goto end;
}
......@@ -1255,7 +1274,7 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
if (part_type == VERSIONING_PARTITION)
{
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->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