set @save_persistent=@@global.innodb_stats_persistent; set global innodb_stats_persistent= 0; call mtr.add_suppression("need more HISTORY partitions"); set system_versioning_alter_history=keep; # Check conventional partitioning on temporal tables create or replace table t1 ( x int, row_start SYS_DATATYPE as row start invisible, row_end SYS_DATATYPE as row end invisible, period for system_time(row_start, row_end)) with system versioning partition by range columns (x) ( partition p0 values less than (100), partition p1 values less than (1000)); insert into t1 values (3), (300); select * from t1; x 3 300 select * from t1 partition (p0); x 3 select * from t1 partition (p1); x 300 delete from t1; select * from t1; x select * from t1 partition (p0); x select * from t1 partition (p1); x select * from t1 for system_time all; x 3 300 select * from t1 partition (p0) for system_time all; x 3 select * from t1 partition (p1) for system_time all; x 300 # Engine change native <-> non-native versioning prohibited create or replace table t1 ( i int, row_start SYS_DATATYPE as row start invisible, row_end SYS_DATATYPE as row end invisible, period for system_time(row_start, row_end)) engine=DEFAULT_ENGINE with system versioning partition by hash(i); alter table t1 engine=NON_DEFAULT_ENGINE; ERROR HY000: Not allowed for system-versioned `test`.`t1`. Change to/from native system versioning engine is not supported. ## CREATE TABLE create or replace table t1 (x int) partition by system_time ( partition p0 history, partition pn current); ERROR HY000: Table `t1` is not system-versioned create or replace table t1 (x int); alter table t1 partition by system_time ( partition p0 history, partition pn current); ERROR HY000: Table `t1` is not system-versioned create or replace table t1 (x int) with system versioning partition by system_time ( partition p0 current); ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT create or replace table t1 (x int) with system versioning partition by system_time ( partition p0 current, partition p1 current); ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT create or replace table t1 (x int) with system versioning partition by system_time ( partition p0 history, partition p1 history); ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT create or replace table t1 (x int) with system versioning partition by system_time ( partition pn current, partition p0 history); ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT create or replace table t1 (x int) with system versioning partition by system_time ( partition p0, partition pn current); ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT create or replace table t1 (x int) with system versioning partition by system_time ( partition p0 history, partition pn current); create or replace table t1 (a int) partition by range (a) ( partition p0 history, partition p1 current); ERROR HY000: Wrong partition type `SYSTEM_TIME` for partitioning by `RANGE` create or replace table t1 (b int) partition by range (a) ( partition p0 current, partition p1 history); ERROR HY000: Wrong partition type `SYSTEM_TIME` for partitioning by `RANGE` ## ALTER TABLE alter table t1 add partition ( partition p1 current); ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT alter table t1 add partition ( partition p1 history); 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 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME (PARTITION `p0` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) insert into t1 values (1), (2); alter table t1 drop partition pn; ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT alter table t1 drop partition p1; alter table t1 drop partition p0; ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT select x from t1; x 1 2 # rename works create or replace table t1 (x int) with system versioning partition by system_time; alter table t1 reorganize partition p0 into (partition custom_name history); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME (PARTITION `custom_name` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) # merge and split doesn't (MDEV-19938) create or replace table t1 (x int) with system versioning partition by system_time limit 10 partitions 3; alter table t1 reorganize partition p0, p1 into (partition p00 history); ERROR HY000: REORGANIZE PARTITION can only be used to reorganize partitions not to change their numbers alter table t1 reorganize partition p1 into (partition p1 history, partition p2 history); ERROR HY000: REORGANIZE PARTITION can only be used to reorganize partitions not to change their numbers # 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; 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); ERROR HY000: Wrong partition type `SYSTEM_TIME` for partitioning by `HASH` ## INSERT, UPDATE, DELETE create or replace table t1 (x int) with system versioning 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)'); prepare select_p0 from @str; set @str= concat('select x, row_start > @now as C, row_end = timestamp\'2038-01-19 03:14:07.999999\' as D from t1 partition (pn)'); prepare select_pn from @str; execute select_p0; x A B execute select_pn; x C D 1 1 1 set @str= concat('select row_start from t1 partition (pn) into @ts0'); prepare stmt from @str; Warnings: Warning 1287 ' INTO FROM...' instead execute stmt; drop prepare stmt; set @now= now(6); delete from t1; execute select_p0; x A B 1 1 1 execute select_pn; x C D set @str= concat('select row_start from t1 partition (p0) into @ts1'); prepare stmt from @str; Warnings: Warning 1287 ' INTO FROM...' instead execute stmt; drop prepare stmt; select @ts0 = @ts1; @ts0 = @ts1 1 set @now= now(6); insert into t1 values (2); execute select_p0; x A B 1 1 0 execute select_pn; x C D 2 1 1 set @str= concat('select row_start from t1 partition (pn) into @ts0'); prepare stmt from @str; Warnings: Warning 1287 ' INTO FROM...' instead execute stmt; drop prepare stmt; set @now= now(6); update t1 set x = x + 1; execute select_p0; x A B 1 1 0 2 1 1 execute select_pn; x C D 3 1 1 drop prepare select_p0; drop prepare select_pn; set @str= concat('select row_start from t1 partition (p0) where x = 2 into @ts1'); prepare stmt from @str; Warnings: Warning 1287 ' INTO FROM...' instead execute stmt; drop prepare stmt; set @str= concat('select row_end from t1 partition (p0) where x = 2 into @ts2'); prepare stmt from @str; Warnings: Warning 1287 ' INTO FROM...' instead execute stmt; drop prepare stmt; set @str= concat('select row_start from t1 partition (pn) into @ts3'); prepare stmt from @str; Warnings: Warning 1287 ' INTO FROM...' instead execute stmt; drop prepare stmt; select @ts0 = @ts1; @ts0 = @ts1 1 select @ts2 = @ts3; @ts2 = @ts3 1 # # Rotation by LIMIT # create or replace table t1 (x int) with system versioning 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 partitions 3; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 2 PARTITIONS 3 alter table t1 drop partition non_existent; ERROR HY000: Wrong partition name or partition list insert into t1 values (1), (2), (3), (4), (5), (6); select * from t1 partition (pn); x 1 2 3 4 5 6 delete from t1 where x < 4; delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select * from t1 partition (p0); x 1 2 3 select * from t1 partition (p1); x 4 5 6 insert into t1 values (7), (8); ### warn about full partition delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select * from t1 partition (p1) order by x; x 4 5 6 7 8 # # Rotation by INTERVAL # create or replace table t1 (x int) with system versioning 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; 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 create or replace table t1 (pk int) with system versioning partition by system_time interval 10 year partitions 3; ERROR 22003: TIMESTAMP value is out of range in 'INTERVAL' # INTERVAL and ALTER TABLE create or replace table t1 (i int) with system versioning 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; 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 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 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 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 Incorrect time value: 'CURRENT' set timestamp=unix_timestamp('2001-02-03 10:20:30'); create or replace table t1 (i int) with system versioning partition by system_time interval 1 day subpartition by key (i) subpartitions 2 (partition p1 history, partition pn current); set timestamp=unix_timestamp('2001-02-03 10:20:40'); insert t1 values (1); delete from t1; set timestamp=unix_timestamp('2001-02-04 10:20:50'); insert t1 values (2); delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of INTERVAL, need more HISTORY partitions select subpartition_name, partition_description, table_rows from information_schema.partitions where table_schema='test' and table_name='t1'; subpartition_name partition_description table_rows p1sp0 2001-02-04 00:00:00 1 p1sp1 2001-02-04 00:00:00 1 pnsp0 CURRENT 0 pnsp1 CURRENT 0 select * from t1 partition (p1); i 1 2 set timestamp=unix_timestamp('2001-02-04 10:20:55'); alter table t1 add partition (partition p0 history, partition p2 history); set timestamp=unix_timestamp('2001-02-04 10:30:00'); insert t1 values (4),(5); set timestamp=unix_timestamp('2001-02-04 10:30:10'); update t1 set i=6 where i=5; select subpartition_name, partition_description, table_rows from information_schema.partitions where table_schema='test' and table_name='t1'; subpartition_name partition_description table_rows p1sp0 2001-02-04 00:00:00 1 p1sp1 2001-02-04 00:00:00 0 p0sp0 2001-02-05 00:00:00 1 p0sp1 2001-02-05 00:00:00 1 p2sp0 2001-02-06 00:00:00 0 p2sp1 2001-02-06 00:00:00 0 pnsp0 CURRENT 0 pnsp1 CURRENT 2 select * from t1 partition (p1); i 1 select * from t1 partition (p0); i 5 2 select * from t1 partition (p2); i alter table t1 rebuild partition p0, p1, p2; select * from t1 partition (p1); i 1 select * from t1 partition (p0); i 5 2 select * from t1 partition (p2); i ## 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); select * from t1; i 4 6 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 # Using where explain partitions select * from t1 for system_time as of '2001-02-04 10:20:30'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 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 # # # # MDEV-16023 Unfortunate error message WARN_VERS_PART_FULL # set timestamp= unix_timestamp('2020-07-29 10:30:10'); create or replace table t1 (a int) with system versioning partition by system_time interval 1 second ( partition p0 history, partition p1 history, partition pc current ); set timestamp= unix_timestamp('2020-07-29 10:30:14'); insert into t1 values (1),(2),(3); show warnings; Level Code Message # Cleanup set timestamp= default; ## INTERVAL ... STARTS create or replace table t1 (i int) with system versioning 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'; 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'; 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; 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'; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00' 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; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00' 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'; 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; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 SECOND STARTS TIMESTAMP'1999-12-15 13:33:33' PARTITIONS 2 create or replace table t1 (i int) with system versioning partition by system_time interval 1 minute; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 MINUTE STARTS TIMESTAMP'1999-12-15 13:33:00' PARTITIONS 2 create or replace table t1 (i int) with system versioning partition by system_time interval 1 hour; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'1999-12-15 13:00:00' PARTITIONS 2 create or replace table t1 (i int) with system versioning partition by system_time interval 1 day; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-15 00:00:00' PARTITIONS 2 create or replace table t1 (i int) with system versioning partition by system_time interval 1 month; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 MONTH STARTS TIMESTAMP'1999-12-15 00:00:00' PARTITIONS 2 create or replace table t1 (i int) with system versioning partition by system_time interval 1 year; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 YEAR STARTS TIMESTAMP'1999-12-15 00:00:00' 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; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 86400 SECOND STARTS TIMESTAMP'1999-12-15 13:33:33' 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'; 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; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00' PARTITIONS 2 show create table t2; Table Create Table t2 CREATE TABLE `t2` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'2000-01-01 00:00:00' PARTITIONS 2 set time_zone="+00:00"; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-31 21:00:00' PARTITIONS 2 show create table t2; Table Create Table t2 CREATE TABLE `t2` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 DAY STARTS TIMESTAMP'1999-12-31 21:00:00' 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' partitions 3; insert into t1 values (0); set timestamp= unix_timestamp('2001-01-01 00:00:01'); update t1 set i= i + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of INTERVAL, need more HISTORY partitions set timestamp= unix_timestamp('2001-01-01 00:00:02'); update t1 set i= i + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of INTERVAL, need more HISTORY partitions select *, row_end from t1 partition (p0); i row_end select *, row_end from t1 partition (p1); i row_end 0 2001-01-01 00:00:01.000000 1 2001-01-01 00:00:02.000000 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' partitions 3; Warnings: Warning 4164 `t1`: STARTS is later than query time, first history partition may exceed INTERVAL value insert into t1 values (0); set timestamp= unix_timestamp('2000-01-01 00:00:01'); update t1 set i= i + 1; set timestamp= unix_timestamp('2000-01-02 00:00:01'); update t1 set i= i + 1; set timestamp= unix_timestamp('2000-01-03 00:00:01'); update t1 set i= i + 1; set timestamp= unix_timestamp('2000-01-04 00:00:01'); update t1 set i= i + 1; select *, row_end from t1 partition (p0); i row_end 0 2000-01-01 00:00:01.000000 1 2000-01-02 00:00:01.000000 2 2000-01-03 00:00:01.000000 select *, row_end from t1 partition (p1); i row_end 3 2000-01-04 00:00:01.000000 # and this is how it usually goes: 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 partitions 3; insert into t1 values (0); set timestamp= unix_timestamp('2000-01-01 00:00:01'); update t1 set i= i + 1; set timestamp= unix_timestamp('2000-01-02 00:00:01'); update t1 set i= i + 1; set timestamp= unix_timestamp('2000-01-03 00:00:01'); update t1 set i= i + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of INTERVAL, need more HISTORY partitions set timestamp= unix_timestamp('2000-01-04 00:00:01'); update t1 set i= i + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of INTERVAL, need more HISTORY partitions alter table t1 add partition (partition p2 history, partition p3 history); select *, row_end from t1 partition (p0); i row_end 0 2000-01-01 00:00:01.000000 select *, row_end from t1 partition (p1); i row_end 1 2000-01-02 00:00:01.000000 select *, row_end from t1 partition (p2); i row_end 2 2000-01-03 00:00:01.000000 select *, row_end from t1 partition (p3); i row_end 3 2000-01-04 00:00:01.000000 drop tables t1, t2; ## Subpartitions create or replace table t1 (x int) with system versioning partition by system_time limit 2 partitions 3 subpartition by key (x) subpartitions 2; insert into t1 (x) values (1), (2), (3), (4), (5); select * from t1 partition (pnsp0); x 1 3 5 select * from t1 partition (pnsp1); x 2 4 delete from t1 where x < 3; delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ (no matter if nothing was deleted) select * from t1 partition (p0sp0); x 1 select * from t1 partition (p0sp1); x 2 select * from t1 partition (p1sp0); x 3 5 select * from t1 partition (p1sp1); x 4 # check implicit sys fields for implicit engine of partitioned table create or replace table t1 (a bigint) with system versioning partition by range (a) (partition p0 values less than (20) engine innodb, partition p1 values less than maxvalue engine innodb); insert into t1 values (1); select * from t1 partition (p0); a 1 # check for partition engine create or replace table t1 ( f_int1 integer default 0 ) with system versioning partition by range(f_int1) subpartition by hash(f_int1) ( partition part1 values less than (1000) (subpartition subpart11 storage engine = 'innodb', subpartition subpart12 storage engine = 'innodb')); insert into t1 values (1); select * from t1 partition (part1); f_int1 1 # # TRX_ID versioning (moved from partition_innodb.test) # # MDEV-15951 system versioning by trx id doesn't work with partitioning # currently trx_id does not support partitioning by system_time create or replace table t1( i int, row_start bigint unsigned generated always as row start, row_end bigint unsigned generated always as row end, period for system_time(row_start, row_end) ) engine=InnoDB with system versioning partition by system_time ( partition p0 history, partition pn current ); ERROR HY000: `row_start` must be of type TIMESTAMP(6) for system-versioned table `t1` create or replace table t1( i int, row_start bigint unsigned generated always as row start, row_end bigint unsigned generated always as row end, period for system_time(row_start, row_end) ) engine=InnoDB with system versioning; alter table t1 partition by system_time ( partition p0 history, partition pn current ); ERROR HY000: `row_start` must be of type TIMESTAMP(6) for system-versioned table `t1` drop table t1; create or replace table t ( a int primary key, row_start bigint unsigned as row start invisible, row_end bigint unsigned as row end invisible, period for system_time(row_start, row_end) ) engine=innodb with system versioning partition by key() ( partition p1, partition p2 ); ERROR HY000: Transaction-precise system-versioned tables do not support partitioning by ROW START or ROW END create or replace table t ( a int primary key, row_start bigint unsigned as row start invisible, row_end bigint unsigned as row end invisible, period for system_time(row_start, row_end) ) engine=innodb with system versioning partition by key(a, row_start) ( partition p1, partition p2 ); ERROR HY000: Transaction-precise system-versioned tables do not support partitioning by ROW START or ROW END create or replace table t ( a int primary key, row_start bigint unsigned as row start invisible, row_end bigint unsigned as row end invisible, period for system_time(row_start, row_end) ) engine=innodb with system versioning partition by hash(a + row_end * 2) ( partition p1, partition p2 ); ERROR HY000: Transaction-precise system-versioned tables do not support partitioning by ROW START or ROW END create or replace table t ( a int primary key, row_start bigint unsigned as row start invisible, row_end bigint unsigned as row end invisible, period for system_time(row_start, row_end) ) engine=innodb with system versioning partition by range columns (a, row_start) ( partition p1 values less than (100, 100) ); ERROR HY000: Transaction-precise system-versioned tables do not support partitioning by ROW START or ROW END # # 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); delete from t1; alter table t1 partition by system_time limit 1 ( partition p1 history, partition pn current); # # MDEV-14649 Assertion `t->mysql_col_len == 8' failed in row_insert_for_mysql # create or replace table t1 (i int) engine=innodb partition by key(i); alter table t1 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; 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 where table_name = 't1' into @a; Warnings: Warning 1287 ' INTO FROM...' instead 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; 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; Warnings: Warning 1287 ' INTO FROM...' instead insert into t2 values (1); # # MDEV-14747 ALTER PARTITION BY SYSTEM_TIME after LOCK TABLES # create or replace table t1 (x int) with system versioning; lock table t1 write; alter table t1 partition by system_time interval 1 week ( partition p1 history, partition pn current); unlock tables; # # MDEV-14748 Assertion in ha_myisammrg::attach_children() # create or replace table t1 (x int) engine=myisam with system versioning partition by system_time interval 1 month (partition p1 history, partition pn current); create or replace table t2 (x int) engine=myisam; create or replace table t3 (x int) engine=merge union=(t2); create or replace table t4 (x int) engine=myisam; create or replace trigger tr after insert on t4 for each row insert into t2 ( select x from t3 ) union ( select x from t1 ); insert into t4 values (1); # # MDEV-14821 Assertion failure # create or replace table t1 (x int) with system versioning; insert into t1 values (0), (1); 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; # You see warning above ^ delete from t1 where x = 2; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p2`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ # # MDEV-14923 Assertion upon INSERT into locked versioned partitioned table # create or replace table t1 (x int) with system versioning partition by system_time; lock table t1 write; alter table t1 add partition (partition p0 history); ERROR HY000: Duplicate partition name p0 insert into t1 values (1); unlock tables; # # 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; insert into t1 values (1,10), (2,20); create or replace view v1 as select * from t1; 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; 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 # create or replace table t1 (i int) with system versioning; insert into t1 values (1), (2); update t1 set i= 3; alter table t1 partition by system_time interval 1 month (partition p1 history, partition pn current); lock table t1 write; alter table t1 add partition (partition p2 history); 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 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; select * from t1 partition (p0) for system_time all; ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query # MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED create or replace procedure sp() select * from t1 partition (p0) for system_time all; call sp; ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query call sp; ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query drop procedure sp; # # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE # create or replace table t1 (pk int primary key) engine=myisam with system versioning partition by key() partitions 3; set timestamp=1523466002.799571; insert into t1 values (11),(12); set timestamp=1523466004.169435; delete from t1 where pk in (11, 12); Same test but for Aria storage engine create or replace table t1 (pk int primary key) engine=aria with system versioning partition by key() partitions 3; set timestamp=1523466002.799571; insert into t1 values (11),(12); set timestamp=1523466004.169435; 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; alter table t1 partition by system_time interval column_get(column_create(7,7), 7 as int) second ( partition ver_p1 history, partition ver_pn current); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `pk` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 7 SECOND STARTS TIMESTAMP'2018-04-11 17:00:04' (PARTITION `ver_p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `ver_pn` CURRENT ENGINE = DEFAULT_ENGINE) set timestamp= default; # # MDEV-18794 Assertion `!m_innodb' failed in ha_partition::cmp_ref upon SELECT from partitioned table # create or replace table t1 (pk int auto_increment, i int, c char(1), primary key (pk), key(i)) engine=innodb with system versioning partition by key() partitions 2; insert into t1 (i, c) values (1, 'a'), (2, 'b'), (null, 'c'), (null, 'b'); alter table t1 drop system versioning; replace into t1 select * from t1; select * from t1 where i > 0 or pk = 1000 limit 1; pk i c 1 1 a drop table t1; # # MDEV-19175 Server crashes in ha_partition::vers_can_native upon INSERT DELAYED into versioned partitioned table # create or replace table t1 (f int) with system versioning partition by hash(f); insert delayed into t1 values (1); # # MDEV-20068 History partition rotation is not done under LOCK TABLES # create or replace table t1 (x int) with system versioning partition by system_time limit 1 (partition p1 history, partition pn current); lock tables t1 write; insert into t1 values (0), (1), (2), (3); delete from t1 where x < 3; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ unlock tables; # # MDEV-20336 Assertion bitmap_is_set(read_partitions) upon SELECT FOR UPDATE from versioned table # 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 COLLATE=latin1_swedish_ci 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 limit 10 partitions 4; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 10 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; # # MDEV-18957 UPDATE with LIMIT clause is wrong for versioned partitioned tables # create or replace table t1 ( x int, a varchar(255) ) with system versioning partition by system_time (partition p1 history, partition pn current); insert into t1 (x) values (1), (2), (3), (4); update t1 set a= 'foo' limit 3; update t1 set a= 'bar' limit 4; select * from t1; x a 1 bar 2 bar 3 bar 4 bar drop table t1; # # MDEV-21011 Table corruption reported for versioned partitioned table after DELETE: "Found a misplaced row" # create table t1 (a int) with system versioning partition by system_time limit 3 (partition p1 history, partition p2 history, partition pn current); insert into t1 values (1),(2),(3),(4); delete from t1; delete from t1; check table t1; Table Op Msg_type Msg_text test.t1 check status OK drop table t1; # # MDEV-21233 Assertion `m_extra_cache' failed in ha_partition::late_extra_cache # create table t1 (id int, a varchar(8)) with system versioning partition by key (id) partitions 2; insert into t1 values (1,'foo'),(2,'bar'); create table t2 (b int); insert into t2 values (1),(2); update t1, t2 set a = 1; drop table t1, t2; # # MDEV-20515 multi-update tries to position updated table by null reference # create or replace table t1 (a int); insert into t1 values (0), (1); create or replace table t2 (b int) with system versioning partition by system_time (partition p1 history, partition pn current); insert into t2 values (0), (2); update t1 left join t2 on a > b set b= 2 order by b; drop table t1, t2; # # MDEV-17091 Assertion `old_part_id == m_last_part' failed in # ha_partition::update_row or `part_id == m_last_part' in # ha_partition::delete_row upon UPDATE/DELETE after dropping versioning # create or replace table t1 (pk int primary key, f int) engine=innodb with system versioning partition by key() partitions 2; insert into t1 values (1,10),(2,20); # expected to hit same partition select * from t1 partition (p0); pk f 1 10 2 20 alter table t1 drop system versioning; # 1 and 2 are expected to be in different partitions select * from t1 partition(p0); pk f 1 10 select * from t1 partition(p1); pk f 2 20 update t1 set f=pk; delete from t1; drop table t1; # # MDEV-22413 Server hangs upon UPDATE/DELETE on a view reading from versioned partitioned table # create or replace table t1 (f char(6)) engine innodb with system versioning; insert into t1 values (null); update t1 set f= 'foo'; update t1 set f= 'bar'; # You see warning above ^ create or replace view v1 as select * from t1 for system_time all; update v1 set f = ''; ERROR HY000: Table 't1' was locked with a READ lock and can't be updated create or replace table t1 (f char(6)) engine innodb with system versioning partition by system_time limit 1 (partition p1 history, partition p2 history, partition pn current); insert into t1 values (null); update t1 set f= 'foo'; update t1 set f= 'bar'; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p2`) is out of LIMIT, need more HISTORY partitions create or replace view v1 as select * from t1 for system_time all; update v1 set f= ''; ERROR HY000: Table 't1' was locked with a READ lock and can't be updated delete from v1; ERROR HY000: Table 't1' was locked with a READ lock and can't be updated drop view v1; drop table t1; # # MDEV-22112 Assertion `tab_part_info->part_type == RANGE_PARTITION || tab_part_info->part_type == LIST_PARTITION' failed in prep_alter_part_table # create table t1 (a int) with system versioning partition by system_time; drop table t1; create table t1 (a int) with system versioning partition by system_time (partition p1 history, partition pn current); alter table t1 add partition (partition p2); ERROR HY000: Wrong partition type `HASH` for partitioning by `SYSTEM_TIME` # MDEV-17891 Assertion failures in select_insert::abort_result_set and # mysql_load upon attempt to replace into a full table set @@max_heap_table_size= 1024*1024; create or replace table t1 ( pk integer auto_increment, primary key (pk), f varchar(45000) ) with system versioning engine=memory partition by system_time interval 1 year (partition p1 history, partition pn current); # fill the table until full insert into t1 () values (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(); insert into t1 (f) select f from t1; ERROR HY000: The table 't1' is full # leave space for exactly one record in current partition delete from t1 where pk = 1; # copy all data into history partition replace into t1 select * from t1; replace into t1 select * from t1; ERROR HY000: The table 't1' is full create or replace table t1 ( pk integer auto_increment, primary key (pk), f varchar(45000) ) with system versioning engine=memory partition by system_time interval 1 year (partition p1 history, partition pn current); insert into t1 () values (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(); select * into outfile 'MDEV-17891.data' from t1; load data infile 'MDEV-17891.data' replace into table t1; load data infile 'MDEV-17891.data' replace into table t1; ERROR HY000: The table 't1' is full load data infile 'MDEV-17891.data' replace into table t1; ERROR HY000: The table 't1' is full set @@max_heap_table_size= 1048576; drop table t1; # # MDEV-22178 Assertion `info->alias.str' failed in partition_info::check_partition_info instead of ER_VERS_WRONG_PARTS # create or replace table t1 (a int) with system versioning; alter table t1 partition by system_time (partition pn current); ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT drop table t1; # # MDEV-22247 History partition overflow leads to wrong SELECT result # set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour (partition p0 history, partition p1 history, partition pn current); insert into t1 values (0); update t1 set x= x + 1; set timestamp= unix_timestamp('2000-01-01 02:00:01'); update t1 set x= x + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of INTERVAL, need more HISTORY partitions select *, row_start, row_end from t1 for system_time as of '2000-01-01 02:00:00'; x row_start row_end 1 2000-01-01 00:00:00.000000 2000-01-01 02:00:01.000000 explain partitions select * from t1 for system_time as of '2000-01-01 02:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1,pn ALL NULL NULL NULL NULL # Using where explain partitions select * from t1; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 pn # NULL NULL NULL NULL # # drop table t1; # # MDEV-27244 Table corruption upon adding serial data type # create table t1 (f int, key(f)) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current); alter table t1 add x serial; alter table t1 add partition (partition p1 history); alter table t1 add partition (partition p2 history); drop table t1; # # MDEV-27217 DELETE partition selection doesn't work for history partitions # create table t1 (f char) with system versioning partition by system_time limit 10 ( partition p0 history, partition p1 history, partition p2 history, partition pn current); delete from t1 partition (p1); ERROR HY000: Not allowed for system-versioned table `test`.`t1` delete from t1 partition (p0, pn); ERROR HY000: Not allowed for system-versioned table `test`.`t1` delete from t1 partition (p0, p1); ERROR HY000: Not allowed for system-versioned table `test`.`t1` delete from t1 partition (p0, p1, pn); ERROR HY000: Not allowed for system-versioned table `test`.`t1` drop table t1; 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 p1 history, partition pn current); set timestamp=unix_timestamp('2000-01-02 00:00:00'); insert t1 values (1); delete from t1 partition (p0, pn); ERROR HY000: Not allowed for system-versioned table `test`.`t1` delete from t1 partition (p0, p1, pn); ERROR HY000: Not allowed for system-versioned table `test`.`t1` lock tables t1 write; delete from t1 partition (p0, pn); ERROR HY000: Not allowed for system-versioned table `test`.`t1` delete from t1; unlock tables; drop table t1; set timestamp= default; # # MDEV-25546 LIMIT partitioning does not respect ROLLBACK # create or replace table t1 (pk int primary key) with system versioning engine innodb partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); insert into t1 select seq from seq_1_to_90; start transaction; replace into t1 select seq from seq_1_to_80; replace into t1 select seq from seq_1_to_70; replace into t1 select seq from seq_1_to_60; select partition_name, table_rows from information_schema.partitions where table_name = 't1'; partition_name table_rows p0 150 p1 60 pn 90 rollback; select partition_name, table_rows from information_schema.partitions where table_name = 't1'; partition_name table_rows p0 0 p1 0 pn 90 replace into t1 select seq from seq_1_to_10; select partition_name, table_rows from information_schema.partitions where table_name = 't1'; partition_name table_rows p0 10 p1 0 pn 90 drop table t1; # # MDEV-28271 Assertion on TRUNCATE PARTITION for PARTITION BY SYSTEM_TIME # create table t1 (x int) with system versioning partition by system_time limit 1 ( partition p0 history, partition p1 history, partition p2 history, # p2 just disables warning about p1 partition full partition pn current); insert into t1 values (0); update t1 set x= x + 1; update t1 set x= x + 1; select * from t1 partition (p0); x 0 select * from t1 partition (p1); x 1 select * from t1 partition (pn); x 2 delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p2`) is out of LIMIT, need more HISTORY partitions delete history from t1; select * from t1 partition (p0); x select * from t1 partition (p1); x select * from t1 partition (pn); x insert into t1 values (0); update t1 set x= x + 1; update t1 set x= x + 1; # TRUNCATE PARTITION ALL does the same alter table t1 truncate partition all; select * from t1 partition (p0); x select * from t1 partition (p1); x select * from t1 partition (pn); x insert into t1 values (0); update t1 set x= x + 1; update t1 set x= x + 1; # TRUNCATE PARTITION deletes data from HISTORY partition alter table t1 truncate partition p1; select * from t1 partition (p0); x 0 select * from t1 partition (p1); x select * from t1 partition (pn); x 2 # or from CURRENT partition alter table t1 truncate partition pn; select * from t1 partition (p0); x 0 select * from t1 partition (p1); x select * from t1 partition (pn); x drop table t1; # # MDEV-20077 Warning on full history partition is delayed until next DML statement # # DELETE create table t1 (x int) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); insert into t1 select seq from seq_0_to_200; # p0 is filled with 100 records (no warnings): delete from t1 where x <= 99; # p1 is filled with 1 + 100 records (warning is printed): delete from t1 where x <= 100; delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 101 drop table t1; # DELETE under LOCK TABLES create table t1 (x int) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); insert into t1 select seq from seq_0_to_200; lock tables t1 write; # (LOCK TABLES) p0 is filled with 100 records (no warnings): delete from t1 where x <= 99; # (LOCK TABLES) p1 is filled with 1 + 100 records (warning is printed): delete from t1 where x <= 100; delete from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ unlock tables; select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 101 drop table t1; # DELETE multitable create table t1 (x int) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); create table t2 (y int); insert into t1 select seq from seq_0_to_200; insert into t2 select seq from seq_0_to_3; delete t1, t2 from t1 join t2 where x < 50 and y = 0; delete t1, t2 from t1 join t2 where x < 100 and y = 1; delete t1, t2 from t1 join t2 where x < 150 and y = 2; delete t1, t2 from t1 join t2; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 101 drop table t1; # UDPATE create table t1 (x int) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); insert into t1 select seq from seq_0_to_49; update t1 set x= x + 1; update t1 set x= x + 1; update t1 set x= x + 1; update t1 set x= x + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 100 drop tables t1, t2; # UPDATE multitable create table t1 (x int) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); create table t2 (y int); insert into t1 select seq from seq_0_to_49; insert into t2 values (5); update t1, t2 set x= x + 1; update t1, t2 set x= x + 1; update t1, t2 set x= x + 1; update t1, t2 set x= x + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 100 drop tables t1, t2; # INSERT .. ON DUPLICATE KEY UPDATE (ODKU) create table t1 (x int primary key) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); insert into t1 select seq from seq_0_to_100; delete from t1 where x <= 99; insert into t1 values (100) on duplicate key update x= 400; select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 1 drop table t1; # INSERT .. SELECT .. ON DUPLICATE KEY UPDATE (ODKU) create table t1 (x int primary key) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); create table t2 (y int); insert into t2 values (100); insert into t1 select seq from seq_0_to_100; delete from t1 where x <= 99; insert into t1 select * from t2 on duplicate key update x= 500; select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 1 drop tables t1, t2; # REPLACE create table t1 (x int primary key) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); insert into t1 select seq from seq_0_to_100; delete from t1 where x < 99; replace t1 values (100); replace t1 values (100); select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 1 drop table t1; # LOAD DATA .. REPLACE create table t1 (x int primary key) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); insert into t1 select seq from seq_0_to_49; select x into outfile 'MDEV-20077.data' from t1; load data infile 'MDEV-20077.data' replace into table t1 (x); load data infile 'MDEV-20077.data' replace into table t1 (x); load data infile 'MDEV-20077.data' replace into table t1 (x); load data infile 'MDEV-20077.data' replace into table t1 (x); Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 100 drop table t1; # REPLACE .. SELECT create table t1 (x int primary key) with system versioning partition by system_time limit 100 ( partition p0 history, partition p1 history, partition pn current); insert into t1 select seq from seq_0_to_49; replace t1 select * from t1; replace t1 select * from t1; replace t1 select * from t1; replace t1 select * from t1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p1`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select count(*) from t1 partition (p0); count(*) 100 select count(*) from t1 partition (p1); count(*) 100 drop table t1; # # MDEV-28552 Assertion `inited==RND' failed in handler::ha_rnd_end # create table tcount (c int unsigned); insert into tcount values (0); create table t (f int) with system versioning partition by system_time limit 1000 (partition p1 history, partition pn current); insert into t values (1),(2); create trigger tr before insert on t for each row update tcount set c = c + 1; insert into t select * from t; drop table tcount, t; # # MDEV-19569 Assertion `table_list->table' failed in find_field_in_table_ref and Assertion `table_ref->table || table_ref->view' in Field_iterator_table_ref::set_field_iterator # set timestamp=unix_timestamp('2000-01-01 00:00:00'); create table t1 (i int); create table t2 (i int); alter table t1 partition by system_time interval (select i from t2) day (partition p1 history, partition pn current); ERROR 42000: INTERVAL does not support subqueries or stored functions drop table t1; create table t1 (id int) with system versioning partition by system_time interval (select i from t2) day (partition p1 history, partition pn current); ERROR 42000: INTERVAL does not support subqueries or stored functions create table t1 (id int) with system versioning partition by system_time interval "hello" day (partition p1 history, partition pn current); ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL' create table t1 (id int) with system versioning partition by system_time interval 3.893 day (partition p1 history, partition pn current); drop table t1, t2; create table t1 (id int) with system versioning partition by system_time interval "3-11" year_month (partition p1 history, partition pn current); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL '3-11' YEAR_MONTH STARTS TIMESTAMP'2000-01-01 00:00:00' (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop table t1; create table t1 (id int) with system versioning partition by system_time interval "3 11" day_hour (partition p1 history, partition pn current); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL '3 11' DAY_HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop table t1; create table t1 (id int) with system versioning partition by system_time interval "3 11:12" day_minute (partition p1 history, partition pn current); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL '3 11:12' DAY_MINUTE STARTS TIMESTAMP'2000-01-01 00:00:00' (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop table t1; create table t1 (id int) with system versioning partition by system_time interval "3 11:12:13" day_second (partition p1 history, partition pn current); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL '3 11:12:13' DAY_SECOND STARTS TIMESTAMP'2000-01-01 00:00:00' (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop table t1; create table t1 (id int) with system versioning partition by system_time interval "11:12" hour_minute (partition p1 history, partition pn current); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL '11:12' HOUR_MINUTE STARTS TIMESTAMP'2000-01-01 00:00:00' (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop table t1; create table t1 (id int) with system versioning partition by system_time interval "11:12:13" hour_second (partition p1 history, partition pn current); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL '11:12:13' HOUR_SECOND STARTS TIMESTAMP'2000-01-01 00:00:00' (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop table t1; create table t1 (id int) with system versioning partition by system_time interval "12:13" minute_second (partition p1 history, partition pn current); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL '12:13' MINUTE_SECOND STARTS TIMESTAMP'2000-01-01 00:00:00' (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop table t1; create table t1 (id int) with system versioning partition by system_time interval "12:13.123" minute_microsecond (partition p1 history, partition pn current); ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL' # # End of 10.3 tests # # # MDEV-22283 Server crashes in key_copy or unexpected error 156: The table already existed in the storage engine # create table t1 (a int primary key) engine=aria page_checksum=0 with system versioning partition by system_time (partition p1 history, partition pn current); alter table t1 add partition (partition p2 history); Warnings: Warning 4115 Maybe missing parameters: no rotation condition for multiple HISTORY partitions. show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary t1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Got error 174 "Fatal error during initialization of handler" from storage engine Aria NULL NULL Warnings: Warning 1030 Got error 174 "Fatal error during initialization of handler" from storage engine Aria drop table t1; create table t1 (b int) engine=aria row_format=dynamic with system versioning partition by system_time (partition p1 history, partition pn current); insert into t1 values (1); replace into t1 values (1); drop table t1; # # MDEV-18794 Assertion `!m_innodb' failed in ha_partition::cmp_ref upon SELECT from partitioned table # create or replace table t1 (pk int auto_increment, i int, c char(1), primary key (pk), key(i)) engine=innodb with system versioning partition by key() partitions 2; insert into t1 (i, c) values (1, 'a'), (2, 'b'), (null, 'c'), (null, 'b'); alter table t1 drop system versioning; replace into t1 select * from t1; select * from t1 where i > 0 or pk = 1000 limit 1; pk i c 1 1 a drop table t1; # # End of 10.4 tests # # # MDEV-22153 ALTER add default history partitions makes table inaccessible # create or replace table t1 (x int) with system versioning partition by system_time; alter table t1 add partition partitions 1; 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 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME PARTITIONS 3 alter table t1 add partition partitions 2; 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 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME PARTITIONS 5 alter table t1 add partition partitions 3; 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 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME PARTITIONS 8 drop tables t1; # # MDEV-22207 Drop default history partitions renders table inaccessible # create or replace table t1 (i int) with system versioning partition by system_time limit 1 partitions 5; alter table t1 drop partition p0, p2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) alter table t1 add partition partitions 1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `i` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop tables t1; # # MDEV-22155 ALTER add default history partitions name clash on non-default partitions # set timestamp= default; create or replace table t1 (x int) with system versioning partition by system_time limit 1 (partition p2 history, partition p8 history, partition pn current); alter table t1 add partition partitions 1; alter table t1 add partition partitions 2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 (PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p8` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p4` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p5` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) alter table t1 add partition partitions 8; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 (PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p8` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p4` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p5` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p9` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p10` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p11` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p12` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p13` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p14` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p15` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p16` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) drop tables t1; # # MDEV-27328 Change of SYSTEM_TIME partitioning options is not possible without data copy # create or replace table t1 (f int) with system versioning partition by hash(f); alter table t1 partition by system_time; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `f` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME PARTITIONS 2 create or replace table t1 (f int) with system versioning partition by system_time; alter table t1 partition by hash(f); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `f` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY HASH (`f`) create or replace table t1 (x int) with system versioning; alter table t1 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 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME PARTITIONS 2 create or replace table t1 (x int) with system versioning partition by system_time limit 100 partitions 4; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 100 PARTITIONS 4 alter table t1 add partition partitions 2; alter table t1 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 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME PARTITIONS 6 alter table t1 partition by system_time limit 33; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 33 PARTITIONS 6 set timestamp= unix_timestamp('2000-01-01 00:00:00'); insert t1 values (0); set timestamp= unix_timestamp('2000-01-01 00:10:00'); update t1 set x= x + 1; set timestamp= unix_timestamp('2000-01-01 01:00:00'); update t1 set x= x + 1; set timestamp= unix_timestamp('2000-01-01 01:30:00'); update t1 set x= x + 1; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 1; alter table t1 partition by system_time interval 1 hour starts '2000-01-01 00:00:00'; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' PARTITIONS 6 select * from t1 partition (p0); x 0 select * from t1 partition (p1); x 1 2 select * from t1 partition (p2); x 3 select * from t1 partition (pn); x 4 set timestamp= default; alter table t1 partition by system_time limit 1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 PARTITIONS 6 update t1 set x= x + 1; update t1 set x= x + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p4`) is out of LIMIT, need more HISTORY partitions # You see warning above ^ select * from t1 partition (p0); x 0 select * from t1 partition (p1); x 1 2 select * from t1 partition (p2); x 3 select * from t1 partition (p3); x 4 select * from t1 partition (p4); x 5 select * from t1 partition (pn); x 6 drop table t1; # End of 10.6 tests # # MDEV-22166 MIGRATE PARTITION: move out partition into a table # create or replace table t1 (x int) with system versioning partition by range(x) ( partition p1 values less than (10), partition p2 values less than (20), partition p3 values less than (30), partition p4 values less than (40), partition p5 values less than (50), partition pn values less than maxvalue); insert into t1 values (2), (12), (22), (32), (42), (52); update t1 set x= x + 1; alter table t1 convert partition p2 to table tp2; show create table tp2; Table Create Table tp2 CREATE TABLE `tp2` ( `x` int(11) DEFAULT NULL ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING select * from tp2; x 13 select * from tp2 for system_time all order by x; x 12 13 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY RANGE (`x`) (PARTITION `p1` VALUES LESS THAN (10) ENGINE = X, PARTITION `p3` VALUES LESS THAN (30) ENGINE = X, PARTITION `p4` VALUES LESS THAN (40) ENGINE = X, PARTITION `p5` VALUES LESS THAN (50) ENGINE = X, PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = X) select * from t1 order by x; x 3 23 33 43 53 select * from t1 for system_time all order by x; x 2 3 22 23 32 33 42 43 52 53 # SP create or replace procedure sp() alter table t1 convert partition p3 to table tp3; call sp; show create table tp3; Table Create Table tp3 CREATE TABLE `tp3` ( `x` int(11) DEFAULT NULL ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING select * from tp3; x 23 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY RANGE (`x`) (PARTITION `p1` VALUES LESS THAN (10) ENGINE = X, PARTITION `p4` VALUES LESS THAN (40) ENGINE = X, PARTITION `p5` VALUES LESS THAN (50) ENGINE = X, PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = X) select * from t1 order by x; x 3 33 43 53 drop table tp3; call sp; ERROR HY000: Wrong partition name or partition list call sp; ERROR HY000: Wrong partition name or partition list drop procedure sp; # LOCK TABLES, PS, SP create or replace procedure sp() alter table t1 convert partition p4 to table tp4; lock tables t1 write; prepare stmt from 'call sp'; execute stmt; unlock tables; show create table tp4; Table Create Table tp4 CREATE TABLE `tp4` ( `x` int(11) DEFAULT NULL ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING select * from tp4; x 33 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY RANGE (`x`) (PARTITION `p1` VALUES LESS THAN (10) ENGINE = X, PARTITION `p5` VALUES LESS THAN (50) ENGINE = X, PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = X) select * from t1 order by x; x 3 43 53 drop table tp4; lock tables t1 write; execute stmt; ERROR HY000: Wrong partition name or partition list call sp; ERROR HY000: Wrong partition name or partition list drop prepare stmt; unlock tables; drop procedure sp; unlock tables; drop tables t1, tp2; # System-versioned tables (SYSTEM_TIME LIMIT) create or replace table t1 ( x int, row_start timestamp(6) as row start invisible, row_end timestamp(6) as row end invisible, period for system_time(row_start, row_end) ) with system versioning partition by system_time limit 1 partitions 4; insert into t1 values (2), (12), (22); update t1 set x= x + 1 where x = 2; update t1 set x= x + 1 where x = 12; update t1 set x= x + 1 where x = 22; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p2`) is out of LIMIT, need more HISTORY partitions select * from t1 partition (p1); x 12 alter table t1 convert partition pn to table tp1; ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT alter table t1 convert partition p1 to table tp1; show create table tp1; Table Create Table tp1 CREATE TABLE `tp1` ( `x` int(11) DEFAULT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`) ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING select * from tp1; x select * from tp1 for system_time all; x 12 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`) ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 (PARTITION `p0` HISTORY ENGINE = X, PARTITION `p2` HISTORY ENGINE = X, PARTITION `pn` CURRENT ENGINE = X) select * from t1 order by x; x 3 13 23 select * from t1 for system_time all order by x; x 2 3 13 22 23 drop tables t1, tp1; # System-versioned tables (SYSTEM_TIME INTERVAL) set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 ( x int, row_start timestamp(6) as row start invisible, row_end timestamp(6) as row end invisible, period for system_time(row_start, row_end) ) with system versioning partition by system_time interval 1 hour partitions 4; insert into t1 values (2), (12), (22); set timestamp= unix_timestamp('2000-01-01 00:00:01'); update t1 set x= x + 1 where x = 2; set timestamp= unix_timestamp('2000-01-01 01:00:00'); update t1 set x= x + 1 where x = 12; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 1 where x = 22; select * from t1 partition (p0); x 2 select * from t1 partition (p1); x 12 select * from t1 partition (p2); x 22 alter table t1 convert partition p1 to table tp1; ERROR HY000: Can only drop oldest partitions when rotating by INTERVAL alter table t1 convert partition p0 to table tp0; alter table t1 convert partition p1 to table tp1; alter table t1 convert partition p2 to table tp2; ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT show create table tp0; Table Create Table tp0 CREATE TABLE `tp0` ( `x` int(11) DEFAULT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`) ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING show create table tp1; Table Create Table tp1 CREATE TABLE `tp1` ( `x` int(11) DEFAULT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`) ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING select * from tp0; x select * from tp1; x select * from tp0 for system_time all; x 2 select * from tp1 for system_time all; x 12 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL, `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE, `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`) ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 02:00:00' (PARTITION `p2` HISTORY ENGINE = X, PARTITION `pn` CURRENT ENGINE = X) select * from t1; x 3 13 23 select * from t1 for system_time all order by x; x 3 13 22 23 drop tables t1, tp0, tp1; # System-versioned tables (implicit) create or replace table t1(x int) with system versioning partition by system_time limit 1 partitions 3; alter table t1 convert partition p1 to table tp1; show create table tp1; Table Create Table tp1 CREATE TABLE `tp1` ( `x` int(11) DEFAULT NULL ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=X DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 (PARTITION `p0` HISTORY ENGINE = X, PARTITION `pn` CURRENT ENGINE = X) drop tables t1, tp1; # Complex table create or replace table t1 ( x int primary key auto_increment, t timestamp(6) default '2001-11-11 11:11:11', b blob(4096) compressed null, c varchar(1033) character set utf8 not null, u int, unique key (x, u), m enum('a', 'b', 'c') not null default 'a' comment 'absolute', i1 tinyint, i2 smallint, i3 bigint, index three(i1, i2, i3), v1 timestamp(6) generated always as (t + interval 1 day), v2 timestamp(6) generated always as (t + interval 1 month) stored, s timestamp(6) as row start, e timestamp(6) as row end, period for system_time (s, e), ps date, pe date, period for app_time (ps, pe), constraint check_constr check (u > -1)) with system versioning default charset=ucs2 partition by range(x) ( partition p0 values less than (10), partition p1 values less than (20), partition pn values less than maxvalue); alter table t1 convert partition p1 to table tp1; show create table tp1; Table Create Table tp1 CREATE TABLE `tp1` ( `x` int(11) NOT NULL AUTO_INCREMENT, `t` timestamp(6) NULL DEFAULT '2001-11-11 11:11:11.000000', `b` blob /*!100301 COMPRESSED*/ DEFAULT NULL, `c` varchar(1033) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `u` int(11) DEFAULT NULL, `m` enum('a','b','c') NOT NULL DEFAULT 'a' COMMENT 'absolute', `i1` tinyint(4) DEFAULT NULL, `i2` smallint(6) DEFAULT NULL, `i3` bigint(20) DEFAULT NULL, `v1` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 day) VIRTUAL, `v2` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 month) STORED, `s` timestamp(6) GENERATED ALWAYS AS ROW START, `e` timestamp(6) GENERATED ALWAYS AS ROW END, `ps` date NOT NULL, `pe` date NOT NULL, PERIOD FOR `app_time` (`ps`, `pe`), PRIMARY KEY (`x`,`e`), UNIQUE KEY `x` (`x`,`u`,`e`), KEY `three` (`i1`,`i2`,`i3`), PERIOD FOR SYSTEM_TIME (`s`, `e`), CONSTRAINT `check_constr` CHECK (`u` > -1) ) ENGINE=X DEFAULT CHARSET=ucs2 COLLATE=ucs2_general_ci WITH SYSTEM VERSIONING show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) NOT NULL AUTO_INCREMENT, `t` timestamp(6) NULL DEFAULT '2001-11-11 11:11:11.000000', `b` blob /*!100301 COMPRESSED*/ DEFAULT NULL, `c` varchar(1033) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `u` int(11) DEFAULT NULL, `m` enum('a','b','c') NOT NULL DEFAULT 'a' COMMENT 'absolute', `i1` tinyint(4) DEFAULT NULL, `i2` smallint(6) DEFAULT NULL, `i3` bigint(20) DEFAULT NULL, `v1` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 day) VIRTUAL, `v2` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 month) STORED, `s` timestamp(6) GENERATED ALWAYS AS ROW START, `e` timestamp(6) GENERATED ALWAYS AS ROW END, `ps` date NOT NULL, `pe` date NOT NULL, PERIOD FOR `app_time` (`ps`, `pe`), PRIMARY KEY (`x`,`e`), UNIQUE KEY `x` (`x`,`u`,`e`), KEY `three` (`i1`,`i2`,`i3`), PERIOD FOR SYSTEM_TIME (`s`, `e`), CONSTRAINT `check_constr` CHECK (`u` > -1) ) ENGINE=X DEFAULT CHARSET=ucs2 COLLATE=ucs2_general_ci WITH SYSTEM VERSIONING PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = X, PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = X) drop tables t1, tp1; # # MDEV-29841 Partition by system_time can be converted into table but not back # create or replace table t (a int) with system versioning partition by system_time limit 10 partitions 3; alter table t convert partition p0 to table tp; alter table t convert table tp to partition p0; ERROR HY000: CONVERT TABLE TO PARTITION can only be used on RANGE/LIST partitions drop tables t, tp; # # End of 10.7 tests # # # MDEV-17554 Auto-create new partition for system versioned tables # with history partitioned by INTERVAL/LIMIT # create or replace table t1 (x int) with system versioning partition by system_time limit 1 auto; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 AUTO PARTITIONS 2 # Turn off AUTO alter table t1 partition by system_time limit 1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 PARTITIONS 2 # Get AUTO back alter table t1 partition by system_time limit 1 auto; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 AUTO PARTITIONS 2 insert into t1 values (1); create or replace table t2 (y int); insert into t2 values (2); insert into t1 select * from t2; insert into t2 select * from t1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 AUTO PARTITIONS 2 # Too many partitions error set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour auto; set timestamp= unix_timestamp('2001-01-01 00:01:00'); update t1 set x= x + 1; ERROR HY000: Versioned table `test`.`t1`: adding HISTORY partition(s) failed show warnings; Level Code Message Warning 1499 Too many partitions (including subpartitions) were defined Error 4189 Versioned table `test`.`t1`: adding HISTORY partition(s) failed # Auto-create failed error set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int) with system versioning engine innodb partition by system_time interval 1 hour auto; insert into t1 values (1); call mtr.add_suppression("rror number .*(File exists|file operation)"); call mtr.add_suppression("InnoDB: Cannot create file"); set timestamp= unix_timestamp('2000-01-01 01:00:00'); update t1 set x= x + 2; ERROR HY000: Got error 184 "Tablespace already exists" from storage engine InnoDB show warnings; Level Code Message Error 1030 Got error 184 "Tablespace already exists" from storage engine InnoDB Warning 4189 Versioned table `test`.`t1`: adding HISTORY partition(s) failed # Partition overflow error and manual fix set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour; insert into t1 values (440); set timestamp= unix_timestamp('2000-01-01 00:10:00'); update t1 set x= x + 1; # Check how pruning boundaries work explain partitions select * from t1 for system_time as of '2000-01-01 00:59:58'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0,pn # NULL NULL NULL NULL # # explain partitions select * from t1 for system_time as of '2000-01-01 00:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0,pn # NULL NULL NULL NULL # # explain partitions select * from t1 for system_time as of '2000-01-01 01:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0,pn # NULL NULL NULL NULL # # select * from t1 for system_time as of '2000-01-01 00:09:59'; x 440 set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 1; Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p0`) is out of INTERVAL, need more HISTORY partitions select * from t1 for system_time as of '2000-01-01 01:00:00'; x 441 select * from t1 partition (p0) order by x; x 440 441 # Here is how manual fix works: just add new partitions there alter table t1 add partition partitions 3; select * from t1 for system_time as of '2000-01-01 01:00:00'; x 441 select * from t1 partition (p0) order by x; x 440 # Check pruning after ALTER explain partitions select * from t1 for system_time as of '2000-01-01 00:59:58'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p0,p1,p2,p3,pn # NULL NULL NULL NULL # # explain partitions select * from t1 for system_time as of '2000-01-01 00:59:59'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1,p2,p3,pn # NULL NULL NULL NULL # # explain partitions select * from t1 for system_time as of '2000-01-01 01:00:00'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1,p2,p3,pn # NULL NULL NULL NULL # # drop table t1; create or replace table t1 (x int) with system versioning partition by system_time interval 3600 second starts '2000-01-01 00:00:00' auto partitions 3; affected rows: 0 insert into t1 values (1); affected rows: 1 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 3600 SECOND STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 affected rows: 1 set timestamp= unix_timestamp('2000-01-01 02:00:00'); affected rows: 0 update t1 set x= x + 1; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 3600 SECOND STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 4 affected rows: 1 set timestamp= unix_timestamp('2000-01-01 03:00:00'); affected rows: 0 update t1 set x= x + 2; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 3600 SECOND STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 5 affected rows: 1 set timestamp= unix_timestamp('2000-01-01 00:00:00'); affected rows: 0 create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour auto ( partition p1 history, partition p3 history, partition pn current); affected rows: 0 insert into t1 values (1); affected rows: 1 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) affected rows: 1 set timestamp= unix_timestamp('2000-01-01 02:00:00'); affected rows: 0 update t1 set x= x + 3; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) affected rows: 1 set timestamp= unix_timestamp('2000-01-01 03:00:00'); affected rows: 0 update t1 set x= x + 4; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p4` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) affected rows: 1 set timestamp= unix_timestamp('2000-01-01 04:00:00'); affected rows: 0 lock tables t1 write; affected rows: 0 update t1 set x= x + 5; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO (PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p4` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p5` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) affected rows: 1 unlock tables; affected rows: 0 set timestamp= default; affected rows: 0 # Couple of more LOCK TABLES cases create or replace table t1 (x int) with system versioning partition by system_time limit 1 auto; affected rows: 0 lock tables t1 write; affected rows: 0 insert into t1 values (1); affected rows: 1 update t1 set x= x + 1; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 update t1 set x= x + 2; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 update t1 set x= x + 3; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 AUTO PARTITIONS 4 affected rows: 1 unlock tables; affected rows: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 1 AUTO PARTITIONS 4 affected rows: 1 # Overflow prevention under LOCK TABLES create or replace table t1 (x int) with system versioning partition by system_time limit 10 auto; affected rows: 0 insert into t1 values (1), (2), (3), (4), (5), (6), (7), (8), (9); affected rows: 9 info: Records: 9 Duplicates: 0 Warnings: 0 update t1 set x= x + 10; affected rows: 9 info: Rows matched: 9 Changed: 9 Inserted: 9 Warnings: 0 lock tables t1 write; affected rows: 0 update t1 set x= 1 where x = 11; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 update t1 set x= 2 where x = 12; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 update t1 set x= 3 where x = 13; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 unlock tables; affected rows: 0 select count(x) from t1 partition (p0); count(x) 10 affected rows: 1 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME LIMIT 10 AUTO PARTITIONS 3 affected rows: 1 drop tables t1; affected rows: 0 # Test VIEW, LOCK TABLES set timestamp= unix_timestamp('2000-01-01 00:00:00'); affected rows: 0 create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour auto; affected rows: 0 create or replace view v1 as select * from t1; affected rows: 0 insert into t1 values (1); affected rows: 1 set timestamp= unix_timestamp('2000-01-01 01:00:00'); affected rows: 0 update v1 set x= x + 2; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 affected rows: 1 set timestamp= unix_timestamp('2000-01-01 02:00:00'); affected rows: 0 lock tables v1 write; affected rows: 0 update v1 set x= x + 3; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 4 affected rows: 1 unlock tables; affected rows: 0 drop view v1; affected rows: 0 drop tables t1; affected rows: 0 set timestamp= unix_timestamp('2000-01-01 00:00:00'); affected rows: 0 create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour auto partitions 3; affected rows: 0 create or replace table t2 (y int) with system versioning partition by system_time interval 1 hour auto; affected rows: 0 insert into t1 values (1); affected rows: 1 insert into t2 values (2); affected rows: 1 set timestamp= unix_timestamp('2000-01-01 01:00:00'); affected rows: 0 update t1, t2 set x= x + 1, y= y + 1; affected rows: 2 info: Rows matched: 2 Changed: 2 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 affected rows: 1 show create table t2; Table Create Table t2 CREATE TABLE `t2` ( `y` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 affected rows: 1 set timestamp= unix_timestamp('2000-01-01 02:00:00'); affected rows: 0 update t1, t2 set x= x + 1, y= y + 1; affected rows: 2 info: Rows matched: 2 Changed: 2 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 4 affected rows: 1 show create table t2; Table Create Table t2 CREATE TABLE `t2` ( `y` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 4 affected rows: 1 set timestamp= unix_timestamp('2000-01-01 03:00:00'); affected rows: 0 update t1, t2 set t1.x= 0 where t1.x< t2.y; affected rows: 1 info: Rows matched: 1 Changed: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 5 affected rows: 1 show create table t2; Table Create Table t2 CREATE TABLE `t2` ( `y` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS ok affected rows: 1 drop tables t1, t2; affected rows: 0 # PS, SP, LOCK TABLES set timestamp= unix_timestamp('2000-01-01 00:00:00'); affected rows: 0 create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour auto; affected rows: 0 insert into t1 values (1); affected rows: 1 set timestamp= unix_timestamp('2000-01-01 01:00:00'); affected rows: 0 execute immediate 'update t1 set x= x + 5'; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 affected rows: 1 prepare s from 'update t1 set x= x + 6'; affected rows: 0 info: Statement prepared set timestamp= unix_timestamp('2000-01-01 02:00:00'); affected rows: 0 execute s; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 execute s; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 4 affected rows: 1 set timestamp= unix_timestamp('2000-01-01 03:00:00'); affected rows: 0 lock tables t1 write; affected rows: 0 execute s; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 execute s; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 5 affected rows: 1 unlock tables; affected rows: 0 drop prepare s; affected rows: 0 create procedure sp() update t1 set x= x + 7; affected rows: 0 set timestamp= unix_timestamp('2000-01-01 04:00:00'); affected rows: 0 call sp; affected rows: 1 call sp; affected rows: 1 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 6 affected rows: 1 set timestamp= unix_timestamp('2000-01-01 05:00:00'); affected rows: 0 lock tables t1 write; affected rows: 0 call sp; affected rows: 1 call sp; affected rows: 1 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 7 affected rows: 1 unlock tables; affected rows: 0 drop procedure sp; affected rows: 0 set timestamp= unix_timestamp('2001-01-01 00:00:00'); affected rows: 0 create or replace table t1 (i int) with system versioning partition by system_time interval 1 day starts '2001-01-01 00:00:00'; affected rows: 0 insert into t1 values (0); affected rows: 1 set timestamp= unix_timestamp('2001-01-01 00:00:01'); affected rows: 0 prepare s from 'update t1 set i= i + 1'; affected rows: 0 info: Statement prepared execute s; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 set timestamp= unix_timestamp('2001-01-02 00:00:01'); affected rows: 0 execute s; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 1 Warnings: Warning 4114 Versioned table `test`.`t1`: last HISTORY partition (`p0`) is out of INTERVAL, need more HISTORY partitions drop prepare s; affected rows: 0 # Complex table set timestamp= unix_timestamp('2000-01-01 00:00:00'); affected rows: 0 create or replace table t1 ( x int primary key auto_increment, t timestamp(6) default '2001-11-11 11:11:11', b blob(4096) compressed null, c varchar(1033) character set utf8 not null, u int unique, m enum('a', 'b', 'c') not null default 'a' comment 'absolute', i1 tinyint, i2 smallint, i3 bigint, index three(i1, i2, i3), v1 timestamp(6) generated always as (t + interval 1 day), v2 timestamp(6) generated always as (t + interval 1 month) stored, s timestamp(6) as row start, e timestamp(6) as row end, period for system_time (s, e), ps date, pe date, period for app_time (ps, pe), constraint check_constr check (u > -1)) with system versioning default charset=ucs2 partition by system_time interval 1 hour auto ( partition p2 history, partition pn current); affected rows: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) NOT NULL AUTO_INCREMENT, `t` timestamp(6) NULL DEFAULT '2001-11-11 11:11:11.000000', `b` blob /*!100301 COMPRESSED*/ DEFAULT NULL, `c` varchar(1033) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `u` int(11) DEFAULT NULL, `m` enum('a','b','c') NOT NULL DEFAULT 'a' COMMENT 'absolute', `i1` tinyint(4) DEFAULT NULL, `i2` smallint(6) DEFAULT NULL, `i3` bigint(20) DEFAULT NULL, `v1` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 day) VIRTUAL, `v2` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 month) STORED, `s` timestamp(6) GENERATED ALWAYS AS ROW START, `e` timestamp(6) GENERATED ALWAYS AS ROW END, `ps` date NOT NULL, `pe` date NOT NULL, PERIOD FOR `app_time` (`ps`, `pe`), PRIMARY KEY (`x`,`e`), UNIQUE KEY `u` (`u`,`e`), KEY `three` (`i1`,`i2`,`i3`), PERIOD FOR SYSTEM_TIME (`s`, `e`), CONSTRAINT `check_constr` CHECK (`u` > -1) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=ucs2 COLLATE=ucs2_general_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO (PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) affected rows: 1 insert into t1 (x, c, u, i1, i2, i3, ps, pe) values (1, 'cc', 0, 1, 2, 3, '1999-01-01', '2000-01-01'); affected rows: 1 set timestamp= unix_timestamp('2000-01-01 01:00:00'); affected rows: 0 update t1 set x= x + 8; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) NOT NULL AUTO_INCREMENT, `t` timestamp(6) NULL DEFAULT '2001-11-11 11:11:11.000000', `b` blob /*!100301 COMPRESSED*/ DEFAULT NULL, `c` varchar(1033) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `u` int(11) DEFAULT NULL, `m` enum('a','b','c') NOT NULL DEFAULT 'a' COMMENT 'absolute', `i1` tinyint(4) DEFAULT NULL, `i2` smallint(6) DEFAULT NULL, `i3` bigint(20) DEFAULT NULL, `v1` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 day) VIRTUAL, `v2` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 month) STORED, `s` timestamp(6) GENERATED ALWAYS AS ROW START, `e` timestamp(6) GENERATED ALWAYS AS ROW END, `ps` date NOT NULL, `pe` date NOT NULL, PERIOD FOR `app_time` (`ps`, `pe`), PRIMARY KEY (`x`,`e`), UNIQUE KEY `u` (`u`,`e`), KEY `three` (`i1`,`i2`,`i3`), PERIOD FOR SYSTEM_TIME (`s`, `e`), CONSTRAINT `check_constr` CHECK (`u` > -1) ) ENGINE=DEFAULT_ENGINE AUTO_INCREMENT=10 DEFAULT CHARSET=ucs2 COLLATE=ucs2_general_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO (PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) affected rows: 1 set timestamp= unix_timestamp('2000-01-01 02:00:00'); affected rows: 0 update t1 set x= x - 8; affected rows: 1 info: Rows matched: 1 Changed: 1 Inserted: 1 Warnings: 0 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) NOT NULL AUTO_INCREMENT, `t` timestamp(6) NULL DEFAULT '2001-11-11 11:11:11.000000', `b` blob /*!100301 COMPRESSED*/ DEFAULT NULL, `c` varchar(1033) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `u` int(11) DEFAULT NULL, `m` enum('a','b','c') NOT NULL DEFAULT 'a' COMMENT 'absolute', `i1` tinyint(4) DEFAULT NULL, `i2` smallint(6) DEFAULT NULL, `i3` bigint(20) DEFAULT NULL, `v1` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 day) VIRTUAL, `v2` timestamp(6) GENERATED ALWAYS AS (`t` + interval 1 month) STORED, `s` timestamp(6) GENERATED ALWAYS AS ROW START, `e` timestamp(6) GENERATED ALWAYS AS ROW END, `ps` date NOT NULL, `pe` date NOT NULL, PERIOD FOR `app_time` (`ps`, `pe`), PRIMARY KEY (`x`,`e`), UNIQUE KEY `u` (`u`,`e`), KEY `three` (`i1`,`i2`,`i3`), PERIOD FOR SYSTEM_TIME (`s`, `e`), CONSTRAINT `check_constr` CHECK (`u` > -1) ) ENGINE=DEFAULT_ENGINE AUTO_INCREMENT=10 DEFAULT CHARSET=ucs2 COLLATE=ucs2_general_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO (PARTITION `p2` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `p3` HISTORY ENGINE = DEFAULT_ENGINE, PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE) affected rows: 1 # INSERT .. ON DUPLICATE KEY UPDATE (ODKU) set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int primary key) with system versioning partition by system_time interval 1 hour auto; insert into t1 values (1); set timestamp= unix_timestamp('2000-01-01 01:00:00'); insert into t1 values (1) on duplicate key update x= x + 1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) NOT NULL, PRIMARY KEY (`x`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 # LOAD DATA .. REPLACE set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int primary key) with system versioning partition by system_time interval 1 hour auto; insert t1 values (1), (2), (3); select x into outfile 'MDEV-17554.data' from t1; set timestamp= unix_timestamp('2000-01-01 01:00:00'); load data infile 'MDEV-17554.data' replace into table t1 (x); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) NOT NULL, PRIMARY KEY (`x`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 # Concurrent DML set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour auto partitions 3; insert into t1 values (1); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 connect con8, localhost, root; connect con7, localhost, root; connect con6, localhost, root; connect con5, localhost, root; connect con4, localhost, root; connect con3, localhost, root; connect con2, localhost, root; connect con1, localhost, root; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 10; connection con2; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 20; connection con3; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 30; connection con4; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 40; connection con5; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 50; connection con6; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 60; connection con7; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 70; connection con8; set timestamp= unix_timestamp('2000-01-01 02:00:00'); update t1 set x= x + 80; connection con1; disconnect con1; connection con2; disconnect con2; connection con3; disconnect con3; connection con4; disconnect con4; connection con5; disconnect con5; connection con6; disconnect con6; connection con7; disconnect con7; disconnect con8; connection default; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 4 drop tables t1; set timestamp= default; # Concurrent DML (LIMIT) create or replace table t1 (x int) with system versioning engine heap partition by system_time limit 1 auto partitions 3; insert into t1 values (1); update t1 set x= x + N; # (running multithreaded for 3 times) drop tables t1; # Transaction set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int) with system versioning engine innodb partition by system_time interval 1 hour auto; insert into t1 values (1); set timestamp= unix_timestamp('2000-01-01 01:00:00'); start transaction; update t1 set x= 0; connect con1, localhost, root; select * from t1; x 1 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 connection default; commit; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 set timestamp= unix_timestamp('2000-01-01 02:00:00'); start transaction; update t1 set x= 1; connection con1; select * from t1; x 0 connection default; rollback; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 4 disconnect con1; connection default; drop table t1; # # MDEV-25479 Auto-create: 2nd and further executions of PS or SP fail to create partition # create table t (a int) with system versioning partition by system_time interval 1 hour auto; insert into t values (1), (2); prepare stmt from "update t set a= a + 1"; set @@timestamp= @@timestamp + 3601; execute stmt; set @@timestamp= @@timestamp + 3601; execute stmt; drop prepare stmt; show create table t; Table Create Table t CREATE TABLE `t` ( `a` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 02:00:00' AUTO PARTITIONS 4 create procedure sp() update t set a= a + 1; set @@timestamp= @@timestamp + 3601; call sp(); set @@timestamp= @@timestamp + 3601; call sp(); drop procedure sp; show create table t; Table Create Table t CREATE TABLE `t` ( `a` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 02:00:00' AUTO PARTITIONS 6 drop table t; # # MDEV-23639 Auto-create does not work under LOCK TABLES or inside triggers # set timestamp= unix_timestamp('2000-01-01 00:00:00'); create or replace table t1 (x int) with system versioning partition by system_time interval 1 hour auto partitions 3; create table t2 (x int); create table t3 (x int); insert into t3 values (3); create trigger tr after insert on t2 for each row update t1 set x= x + 11; create or replace procedure sp() update t1 set x= x + 5; create or replace procedure sp2() insert into t2 values (5); prepare ps from 'update t1 set x= x + 6'; prepare ps2 from 'insert into t2 values (6)'; insert into t1 values (1); set timestamp= unix_timestamp('2000-01-01 02:00:00'); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 3 insert into t2 values (2); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 4 set timestamp= unix_timestamp('2000-01-01 03:00:00'); call sp; call sp; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 5 set timestamp= unix_timestamp('2000-01-01 04:00:00'); call sp2; call sp2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 6 set timestamp= unix_timestamp('2000-01-01 05:00:00'); execute ps; execute ps; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 7 set timestamp= unix_timestamp('2000-01-01 06:00:00'); execute ps2; execute ps2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 8 set timestamp= unix_timestamp('2000-01-01 08:00:00'); lock tables t1 write, t2 write; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 10 set timestamp= unix_timestamp('2000-01-01 09:00:00'); update t1 set x= x + 1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 11 set timestamp= unix_timestamp('2000-01-01 10:00:00'); update t1 set x= x + 2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 12 update t2 set x= x + 1; set timestamp= unix_timestamp('2000-01-01 11:00:00'); insert into t2 values (4); show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 13 update t3 set x= x + 1; ERROR HY000: Table 't3' was not locked with LOCK TABLES set timestamp= unix_timestamp('2000-01-01 12:00:00'); call sp; call sp; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 14 set timestamp= unix_timestamp('2000-01-01 13:00:00'); call sp2; call sp2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 15 set timestamp= unix_timestamp('2000-01-01 14:00:00'); execute ps; execute ps; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 16 set timestamp= unix_timestamp('2000-01-01 15:00:00'); execute ps2; execute ps2; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 17 unlock tables; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `x` int(11) DEFAULT NULL ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO PARTITIONS 17 drop tables t1, t2, t3; drop procedure sp; drop procedure sp2; drop prepare ps; drop prepare ps2; # # MDEV-27456 Assertion `!thd->is_error()' fails in vers_create_partitions upon DML with ER_UNKNOWN_PARTITION # create table t (a int) with system versioning partition by system_time interval 1 minute auto; set @@timestamp= @@timestamp + 61; select * from t; a delete from t partition (px); ERROR HY000: Unknown partition 'px' in table 't' lock tables t write; delete from t partition (px); ERROR HY000: Unknown partition 'px' in table 't' unlock tables; drop table t; set timestamp= default; # # MDEV-28978 Assertion failure in THD::binlog_query or unexpected # ER_ERROR_ON_WRITE with auto-partitioning # create table t (a int) with system versioning partition by system_time limit 6 auto; insert into t () values (),(),(),(),(),(); update t set a = 1; update t set a = 2 limit 0; drop table t; # # MDEV-31244 Assertion "not SELECT" in vers_set_hist_part() # create table t (a int) with system versioning partition by system_time; create function f() returns int begin update t set a = 1; return 1; end $ create procedure p() select f(); call p(); f() 1 call p(); f() 1 drop procedure p; drop function f; drop table t; # # MDEV-29873 MSAN uninitialized value errors in bcmp / # prep_alter_part_table upon re-partitioning by system time # create table t (a int) with system versioning partition by system_time interval 5 week; alter table t partition by system_time interval 10 week; drop table t; # # MDEV-16546 System versioning setting to allow history modification # create table t1 (a varchar(100)) with system versioning partition by system_time interval 1 day starts '2021-09-30 00:00:00' partitions 3; set system_versioning_insert_history=1; insert into t1 (a,row_start,row_end) values ('p0', '2021-09-30', '2021-09-30 10:00:00'), ('p1', '2021-09-30', '2021-10-01 10:00:00'), ('overflows, so also p1','2021-09-30', '2021-10-10 10:00:00'), ('pn, current', '2021-09-30', '2038-01-19 03:14:07.999999'); select table_name,partition_name,partition_ordinal_position,partition_method,partition_description,table_rows from information_schema.partitions where table_schema='test'; table_name partition_name partition_ordinal_position partition_method partition_description table_rows t1 p0 1 SYSTEM_TIME 2021-10-01 00:00:00 1 t1 p1 2 SYSTEM_TIME 2021-10-02 00:00:00 2 t1 pn 3 SYSTEM_TIME CURRENT 1 drop table t1; set system_versioning_insert_history=0; # # MDEV-29727 ALTER and CREATE with default partitioning # differently react to SQL_MODE => unusable SHOW CREATE # create table t (a int) with system versioning; alter table t partition by system_time partitions 3; ERROR HY000: Maybe missing parameters: no rotation condition for multiple HISTORY partitions. drop table t; create table t (a int) with system versioning partition by system_time partitions 3; ERROR HY000: Maybe missing parameters: no rotation condition for multiple HISTORY partitions. # # End of 10.5 tests # # # MDEV-31903 Server crashes in _ma_reset_history upon UNLOCK table with auto-create history partitions # set timestamp= unix_timestamp('2000-01-01 00:00:00'); create table t1 (x int) engine=aria with system versioning partition by system_time interval 1 hour auto partitions 3; insert into t1 values (1); create table t2 (x int) engine=aria; create trigger tr after insert on t2 for each row update t1 set x= x + 11; lock tables t1 write, t2 write; update t1 set x= x + 1; set timestamp= unix_timestamp('2000-01-01 13:00:00'); insert into t2 values (5); unlock tables; drop table t1, t2; set timestamp= default; # # MDEV-29872 MSAN/Valgrind uninitialised value errors in TABLE::vers_switch_partition # create table t (a int) with system versioning partition by system_time limit 100 partitions 3; drop table t; # # End of 10.9 tests # set global innodb_stats_persistent= @save_persistent;