diff options
Diffstat (limited to 'mysql-test/suite/versioning')
-rw-r--r-- | mysql-test/suite/versioning/r/data.result | 59 | ||||
-rw-r--r-- | mysql-test/suite/versioning/r/partition,heap.rdiff | 86 | ||||
-rw-r--r-- | mysql-test/suite/versioning/r/partition.result | 395 | ||||
-rw-r--r-- | mysql-test/suite/versioning/t/alter.test | 4 | ||||
-rw-r--r-- | mysql-test/suite/versioning/t/create.test | 6 | ||||
-rw-r--r-- | mysql-test/suite/versioning/t/data.test | 32 | ||||
-rw-r--r-- | mysql-test/suite/versioning/t/partition.test | 228 |
7 files changed, 801 insertions, 9 deletions
diff --git a/mysql-test/suite/versioning/r/data.result b/mysql-test/suite/versioning/r/data.result new file mode 100644 index 00000000000..7fea6c3d06e --- /dev/null +++ b/mysql-test/suite/versioning/r/data.result @@ -0,0 +1,59 @@ +# +# MDEV-16355 Add option for mysqldump to read data as of specific timestamp from system-versioned tables +# +create or replace table t1 (x int) with system versioning; +set timestamp=unix_timestamp('1990-01-01 00:00'); +insert t1 (x) values (1),(2),(3); +set timestamp=unix_timestamp('1990-08-03 00:00'); +delete from t1 where x=1; +set timestamp=unix_timestamp('1991-01-02 00:00'); +delete from t1 where x=2; +set timestamp=default; +#MYSQL_DUMP --compact test +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO `t1` VALUES +(3); +#MYSQL_DUMP --compact --as-of="1990-01-02 00:00" test +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO `t1` VALUES +(1), +(2), +(3); +#MYSQL_DUMP --compact --as-of="1990-08-02 00:00" --databases test + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci */; + +USE `test`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO `t1` VALUES +(1), +(2), +(3); +#MYSQL_DUMP --compact --as-of="1990-08-04 00:00" test t1 +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO `t1` VALUES +(2), +(3); +#MYSQL_DUMP --compact --as-of="1990-08-04 00:00' where 'abc" test 2>&1 +mariadb-dump: Incorrect DATETIME value: '1990-08-04 00:00' where 'abc' +drop tables t1; diff --git a/mysql-test/suite/versioning/r/partition,heap.rdiff b/mysql-test/suite/versioning/r/partition,heap.rdiff new file mode 100644 index 00000000000..361a74a4271 --- /dev/null +++ b/mysql-test/suite/versioning/r/partition,heap.rdiff @@ -0,0 +1,86 @@ +@@ -1969,85 +1969,6 @@ + (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) NOT 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) NOT 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; + # + # End of 10.7 tests + # diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index b8ad7693f51..6feee27818b 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -96,6 +96,16 @@ 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); @@ -150,7 +160,7 @@ 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 partitioning type, expected type: `SYSTEM_TIME` +ERROR HY000: Wrong partition type `SYSTEM_TIME` for partitioning by `HASH` ## INSERT, UPDATE, DELETE create or replace table t1 (x int) with system versioning @@ -253,7 +263,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY SYSTEM_TIME LIMIT 2 PARTITIONS 3 alter table t1 drop partition non_existent; -ERROR HY000: Error in list of partitions to DROP +ERROR HY000: Wrong partition name or partition list insert into t1 values (1), (2), (3), (4), (5), (6); select * from t1 partition (pn); x @@ -1105,7 +1115,7 @@ 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 partitioning type, expected type: `SYSTEM_TIME` +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; @@ -1741,6 +1751,7 @@ 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); @@ -1783,4 +1794,382 @@ drop tables t1; # # End of 10.5 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) NOT 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) NOT 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 +# set global innodb_stats_persistent= @save_persistent; diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index 607aa8d603a..61653550389 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -611,7 +611,7 @@ create or replace table t1 ( period for system_time(row_start, row_end) ) with system versioning; show create table t1; ---error ER_KEY_COLUMN_DOES_NOT_EXITS +--error ER_KEY_COLUMN_DOES_NOT_EXIST alter table t1 drop column b; create or replace table t1 ( @@ -621,7 +621,7 @@ a int, b int primary key, period for system_time(row_start, row_end) ) with system versioning; show create table t1; ---error ER_KEY_COLUMN_DOES_NOT_EXITS +--error ER_KEY_COLUMN_DOES_NOT_EXIST alter table t1 drop column b; # cleanup diff --git a/mysql-test/suite/versioning/t/create.test b/mysql-test/suite/versioning/t/create.test index 87cafdc7d32..6f5153b4ec1 100644 --- a/mysql-test/suite/versioning/t/create.test +++ b/mysql-test/suite/versioning/t/create.test @@ -412,11 +412,11 @@ drop tables t0, t1, t2, t3; --echo # --echo # MDEV-23968 CREATE TEMPORARY TABLE .. LIKE (system versioned table) returns error if unique index is defined in the table --echo # ---error ER_KEY_COLUMN_DOES_NOT_EXITS +--error ER_KEY_COLUMN_DOES_NOT_EXIST create table t1 (id int primary key, index(row_start)) with system versioning; ---error ER_KEY_COLUMN_DOES_NOT_EXITS +--error ER_KEY_COLUMN_DOES_NOT_EXIST create table t1 (id int primary key, index(row_end)) with system versioning; ---error ER_KEY_COLUMN_DOES_NOT_EXITS +--error ER_KEY_COLUMN_DOES_NOT_EXIST create table t1 (id int, primary key(id, row_end, row_end)) with system versioning; create table t1 (id int primary key) with system versioning; create temporary table t2 like t1; diff --git a/mysql-test/suite/versioning/t/data.test b/mysql-test/suite/versioning/t/data.test new file mode 100644 index 00000000000..ddae6633337 --- /dev/null +++ b/mysql-test/suite/versioning/t/data.test @@ -0,0 +1,32 @@ +--source include/not_embedded.inc +--source suite/versioning/common.inc + +--echo # +--echo # MDEV-16355 Add option for mysqldump to read data as of specific timestamp from system-versioned tables +--echo # +create or replace table t1 (x int) with system versioning; +set timestamp=unix_timestamp('1990-01-01 00:00'); +insert t1 (x) values (1),(2),(3); +set timestamp=unix_timestamp('1990-08-03 00:00'); +delete from t1 where x=1; +set timestamp=unix_timestamp('1991-01-02 00:00'); +delete from t1 where x=2; +set timestamp=default; + +--echo #MYSQL_DUMP --compact test +--exec $MYSQL_DUMP --compact test +--echo #MYSQL_DUMP --compact --as-of="1990-01-02 00:00" test +--exec $MYSQL_DUMP --compact --as-of="1990-01-02 00:00" test +--echo #MYSQL_DUMP --compact --as-of="1990-08-02 00:00" --databases test +--exec $MYSQL_DUMP --compact --as-of="1990-08-02 00:00" --databases test +--echo #MYSQL_DUMP --compact --as-of="1990-08-04 00:00" test t1 +--exec $MYSQL_DUMP --compact --as-of="1990-08-04 00:00" test t1 +## Forged query protection +--echo #MYSQL_DUMP --compact --as-of="1990-08-04 00:00' where 'abc" test 2>&1 +--replace_result mariadb-dump.exe mariadb-dump +--error 1 +--exec $MYSQL_DUMP --compact --as-of="1990-08-04 00:00' where 'abc" test 2>&1 + +drop tables t1; + +--source suite/versioning/common_finish.inc diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index 535e791c8c8..29de10e4738 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -106,6 +106,18 @@ partition by system_time ( partition p0 history, partition pn current); +--error ER_PARTITION_WRONG_TYPE +create or replace table t1 (a int) +partition by range (a) ( + partition p0 history, + partition p1 current); + +--error ER_PARTITION_WRONG_TYPE +create or replace table t1 (b int) +partition by range (a) ( + partition p0 current, + partition p1 history); + --echo ## ALTER TABLE @@ -232,7 +244,7 @@ partition by system_time limit 2 partitions 3; --replace_result $default_engine DEFAULT_ENGINE show create table t1; ---error ER_DROP_PARTITION_NON_EXISTENT +--error ER_PARTITION_DOES_NOT_EXIST alter table t1 drop partition non_existent; insert into t1 values (1), (2), (3), (4), (5), (6); @@ -1533,6 +1545,7 @@ drop tables t1; --echo # --echo # MDEV-22155 ALTER add default history partitions name clash on non-default partitions --echo # +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); @@ -1552,6 +1565,219 @@ drop tables t1; --echo # End of 10.5 tests --echo # +--echo # +--echo # MDEV-22166 MIGRATE PARTITION: move out partition into a table +--echo # +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; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table tp2; +select * from tp2; +select * from tp2 for system_time all order by x; + +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table t1; +select * from t1 order by x; +select * from t1 for system_time all order by x; + +--echo # SP +create or replace procedure sp() +alter table t1 convert partition p3 to table tp3; +call sp; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table tp3; +select * from tp3; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table t1; +select * from t1 order by x; +drop table tp3; +--error ER_PARTITION_DOES_NOT_EXIST +call sp; +--error ER_PARTITION_DOES_NOT_EXIST +call sp; +drop procedure sp; + +--echo # 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; + +# TODO: don't unlock here (see above TODO) +unlock tables; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table tp4; +select * from tp4; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table t1; +select * from t1 order by x; +drop table tp4; +lock tables t1 write; +--error ER_PARTITION_DOES_NOT_EXIST +execute stmt; +--error ER_PARTITION_DOES_NOT_EXIST +call sp; +drop prepare stmt; +unlock tables; +drop procedure sp; +unlock tables; + +drop tables t1, tp2; + +--echo # 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; + +select * from t1 partition (p1); +--error ER_VERS_WRONG_PARTS +alter table t1 convert partition pn to table tp1; +alter table t1 convert partition p1 to table tp1; + +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table tp1; +select * from tp1; +select * from tp1 for system_time all; + +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table t1; +select * from t1 order by x; +select * from t1 for system_time all order by x; + +drop tables t1, tp1; + +--echo # 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); +select * from t1 partition (p1); +select * from t1 partition (p2); +--error ER_VERS_DROP_PARTITION_INTERVAL +alter table t1 convert partition p1 to table tp1; +alter table t1 convert partition p0 to table tp0; +alter table t1 convert partition p1 to table tp1; +--error ER_VERS_WRONG_PARTS +alter table t1 convert partition p2 to table tp2; + +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table tp0; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table tp1; +select * from tp0; +select * from tp1; +select * from tp0 for system_time all; +select * from tp1 for system_time all; + +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table t1; +select * from t1; +select * from t1 for system_time all order by x; + +drop tables t1, tp0, tp1; + +--echo # 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; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table tp1; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table t1; + +drop tables t1, tp1; + +if (!$MTR_COMBINATION_HEAP) +{ +--echo # 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; + +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table tp1; +--replace_result $default_engine X ' PAGE_CHECKSUM=1' '' +show create table t1; + +drop tables t1, tp1; +} + +--echo # +--echo # MDEV-29841 Partition by system_time can be converted into table but not back +--echo # +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; +--error ER_ONLY_ON_RANGE_LIST_PARTITION +alter table t convert table tp to partition p0; +drop tables t, tp; + +--echo # +--echo # End of 10.7 tests +--echo # + set global innodb_stats_persistent= @save_persistent; --source suite/versioning/common_finish.inc |