diff options
Diffstat (limited to 'mysql-test/suite/period')
-rw-r--r-- | mysql-test/suite/period/engines.combinations | 1 | ||||
-rw-r--r-- | mysql-test/suite/period/r/alter.result | 18 | ||||
-rw-r--r-- | mysql-test/suite/period/r/create.result | 8 | ||||
-rw-r--r-- | mysql-test/suite/period/r/delete.result | 5 | ||||
-rw-r--r-- | mysql-test/suite/period/r/long_unique.result | 17 | ||||
-rw-r--r-- | mysql-test/suite/period/r/overlaps.result | 353 | ||||
-rw-r--r-- | mysql-test/suite/period/t/alter.test | 16 | ||||
-rw-r--r-- | mysql-test/suite/period/t/delete.test | 10 | ||||
-rw-r--r-- | mysql-test/suite/period/t/long_unique.test | 23 | ||||
-rw-r--r-- | mysql-test/suite/period/t/overlaps.test | 346 |
10 files changed, 793 insertions, 4 deletions
diff --git a/mysql-test/suite/period/engines.combinations b/mysql-test/suite/period/engines.combinations index b740ec62a42..62bf838de6c 100644 --- a/mysql-test/suite/period/engines.combinations +++ b/mysql-test/suite/period/engines.combinations @@ -3,4 +3,5 @@ innodb default-storage-engine=innodb [myisam] +innodb default-storage-engine=myisam diff --git a/mysql-test/suite/period/r/alter.result b/mysql-test/suite/period/r/alter.result index a6466c8944b..7b9d1fea861 100644 --- a/mysql-test/suite/period/r/alter.result +++ b/mysql-test/suite/period/r/alter.result @@ -190,3 +190,21 @@ alter table t1 add primary key(x, s, e); ERROR 23000: Duplicate entry '1-2020-03-01-2020-03-02' for key 'PRIMARY' alter table t1 add system versioning; drop table t1; +# +# MDEV-21941 RENAME doesn't work for system time or period fields +# +create or replace table t1 ( +a int, s date, e date, +period for mytime(s, e)); +alter table t1 rename column s to x; +alter table t1 rename column e to y; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `x` date NOT NULL, + `y` date NOT NULL, + PERIOD FOR `mytime` (`x`, `y`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +# End of 10.5 tests diff --git a/mysql-test/suite/period/r/create.result b/mysql-test/suite/period/r/create.result index da4cf998918..69d7e918804 100644 --- a/mysql-test/suite/period/r/create.result +++ b/mysql-test/suite/period/r/create.result @@ -7,8 +7,8 @@ t CREATE TABLE `t` ( `id` int(11) NOT NULL, `s` date NOT NULL, `e` date NOT NULL, - PRIMARY KEY (`id`), - PERIOD FOR `mytime` (`s`, `e`) + PERIOD FOR `mytime` (`s`, `e`), + PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 create or replace table t (id int primary key, s timestamp(6), e timestamp(6), period for mytime(s,e)); @@ -18,8 +18,8 @@ t CREATE TABLE `t` ( `id` int(11) NOT NULL, `s` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', `e` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', - PRIMARY KEY (`id`), - PERIOD FOR `mytime` (`s`, `e`) + PERIOD FOR `mytime` (`s`, `e`), + PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 # SQL16, Part 2, 11.3 <table definition>, Syntax Rules, 2)a) # 2) If a <table period definition> TPD is specified, then: diff --git a/mysql-test/suite/period/r/delete.result b/mysql-test/suite/period/r/delete.result index a58f57761b6..1954c0fdf81 100644 --- a/mysql-test/suite/period/r/delete.result +++ b/mysql-test/suite/period/r/delete.result @@ -388,3 +388,8 @@ ERROR 22003: Out of range value for column 'f' at row ROW delete ignore from t for portion of app from '2015-07-07 00:00:00' to '2020-03-11 08:48:52'; drop table t; +create table t1 (pk int, s date, e date, period for se (s,e), primary key (pk,se without overlaps)); +insert into t1 values (1,'2020-01-01','2020-02-20'); +delete from t1 for portion of se from '2020-01-30' to '2020-01-31'; +drop table t1; +# End of 10.5 tests diff --git a/mysql-test/suite/period/r/long_unique.result b/mysql-test/suite/period/r/long_unique.result new file mode 100644 index 00000000000..5c5f4297fb9 --- /dev/null +++ b/mysql-test/suite/period/r/long_unique.result @@ -0,0 +1,17 @@ +# +# Assertion `inited == NONE || update_handler != this' failed in +# handler::ha_write_row +# +CREATE TABLE t1 (f VARCHAR(4096), s DATE, e DATE, PERIOD FOR app(s,e), UNIQUE(f)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo', '2023-08-30', '2025-07-09'),('bar', '2021-01-01', '2021-12-31'); +DELETE FROM t1 FOR PORTION OF app FROM '2023-08-29' TO '2025-07-01'; +DROP TABLE t1; +# +# MDEV-21819 Assertion `inited == NONE || update_handler != this' +# failed in handler::ha_write_row +# +CREATE OR REPLACE TABLE t1 (a INT, b BLOB, s DATE, e DATE, PERIOD FOR app(s,e), UNIQUE(b)) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2; +INSERT INTO t1 VALUES (1,'foo','2022-01-01', '2025-01-01'); +DELETE FROM t1 FOR PORTION OF app FROM '2023-01-01' TO '2024-01-01'; +ERROR 23000: Duplicate entry 'foo' for key 'b' +DROP TABLE t1; diff --git a/mysql-test/suite/period/r/overlaps.result b/mysql-test/suite/period/r/overlaps.result new file mode 100644 index 00000000000..b8f23ce413c --- /dev/null +++ b/mysql-test/suite/period/r/overlaps.result @@ -0,0 +1,353 @@ +create or replace table t(id int, s date, e date, +period for p(s,e), +primary key(id, p without overlaps) +) partition by key (id); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `id` int(11) NOT NULL, + `s` date NOT NULL, + `e` date NOT NULL, + PERIOD FOR `p` (`s`, `e`), + PRIMARY KEY (`id`,`p` WITHOUT OVERLAPS) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 + PARTITION BY KEY (`id`) +insert into t values (1, '2003-01-01', '2003-03-01'), +(1, '2003-05-01', '2003-07-01'); +insert into t values (1, '2003-02-01', '2003-04-01'); +ERROR 23000: Duplicate entry '1-2003-04-01-2003-02-01' for key 'PRIMARY' +insert into t values (1, '2003-04-01', '2003-06-01'); +ERROR 23000: Duplicate entry '1-2003-06-01-2003-04-01' for key 'PRIMARY' +insert into t values (1, '2003-05-15', '2003-06-15'); +ERROR 23000: Duplicate entry '1-2003-06-15-2003-05-15' for key 'PRIMARY' +insert into t values (1, '2003-04-01', '2003-08-01'); +ERROR 23000: Duplicate entry '1-2003-08-01-2003-04-01' for key 'PRIMARY' +insert into t values (1, '2003-03-01', '2003-05-01'); +# expand/shrink period +update t set s= '2002-12-01' where s = '2003-01-01'; +update t set s= '2003-01-01' where s = '2002-12-01'; +update t set e= '2003-08-01' where s = '2003-05-01'; +update t set e= '2003-07-01' where s = '2003-05-01'; +# move left/right +update t set s= '2002-12-15', e= '2003-01-15' where s = '2003-01-01'; +update t set s= '2003-01-01', e= '2003-02-01' where s = '2002-12-15'; +# diminish/enlarge +update t set s= '2003-01-10', e= '2003-01-20' where s = '2003-01-01'; +update t set s= '2003-01-01', e= '2003-02-01' where s = '2003-01-10'; +select * from t; +id s e +1 2003-01-01 2003-02-01 +1 2003-03-01 2003-05-01 +1 2003-05-01 2003-07-01 +# intersect left/right, strict inclusion/containment +update t set e= '2003-04-01' where s = '2003-01-01'; +ERROR 23000: Duplicate entry '1-2003-04-01-2003-01-01' for key 'PRIMARY' +update t set s= '2003-04-01' where s = '2003-05-01'; +ERROR 23000: Duplicate entry '1-2003-07-01-2003-04-01' for key 'PRIMARY' +update t set s= '2003-03-10', e= '2003-03-20' where s = '2003-01-01'; +ERROR 23000: Duplicate entry '1-2003-03-20-2003-03-10' for key 'PRIMARY' +update t set s= '2003-04-01', e= '2003-08-01' where s = '2003-03-01'; +ERROR 23000: Duplicate entry '1-2003-08-01-2003-04-01' for key 'PRIMARY' +# inclusion/containment with partial match +update t set s= '2003-03-01', e= '2003-04-01' where s = '2003-01-01'; +ERROR 23000: Duplicate entry '1-2003-04-01-2003-03-01' for key 'PRIMARY' +update t set s= '2003-04-01', e= '2003-05-01' where s = '2003-01-01'; +ERROR 23000: Duplicate entry '1-2003-05-01-2003-04-01' for key 'PRIMARY' +update t set s= '2003-03-01' where s = '2003-05-01'; +ERROR 23000: Duplicate entry '1-2003-07-01-2003-03-01' for key 'PRIMARY' +update t set e= '2003-05-01' where s = '2003-01-01'; +ERROR 23000: Duplicate entry '1-2003-05-01-2003-01-01' for key 'PRIMARY' +select * from t where year(s) = 2003; +id s e +1 2003-01-01 2003-02-01 +1 2003-03-01 2003-05-01 +1 2003-05-01 2003-07-01 +# UPDATE ... FOR PORTION test +insert t values (2, '2003-04-15', '2003-05-01'); +update t for portion of p from '2003-01-01' to '2003-01-15' + set id= 2; +select * from t; +id s e +1 2003-01-15 2003-02-01 +1 2003-03-01 2003-05-01 +1 2003-05-01 2003-07-01 +2 2003-01-01 2003-01-15 +2 2003-04-15 2003-05-01 +update t for portion of p from '2003-01-15' to '2003-02-01' + set id= 2; +select * from t; +id s e +1 2003-03-01 2003-05-01 +1 2003-05-01 2003-07-01 +2 2003-01-01 2003-01-15 +2 2003-01-15 2003-02-01 +2 2003-04-15 2003-05-01 +# Next, test UPDATE ... FOR PORTION resulting with an error +# Since MyISAM/Aria engines lack atomicity, the results would differ with +# innodb. So a table is going to be copied to one with explicit engine. +create table t_myisam (id int, s date, e date, +period for p(s,e), +primary key(id, p without overlaps)) +engine=myisam +select * from t; +update t_myisam for portion of p from '2003-04-01' to '2003-06-01' + set id= 2 order by s desc; +ERROR 23000: Duplicate entry '2-2003-05-01-2003-04-01' for key 'PRIMARY' +select * from t_myisam; +id s e +1 2003-03-01 2003-05-01 +1 2003-06-01 2003-07-01 +2 2003-01-01 2003-01-15 +2 2003-01-15 2003-02-01 +2 2003-04-15 2003-05-01 +2 2003-05-01 2003-06-01 +create table t_innodb (id int, s date, e date, +period for p(s,e), +primary key(id, p without overlaps)) +engine=innodb +select * from t; +update t_innodb for portion of p from '2003-04-01' to '2003-06-01' + set id= 2 order by s desc; +ERROR 23000: Duplicate entry '2-2003-05-01-2003-04-01' for key 'PRIMARY' +select * from t_innodb; +id s e +1 2003-03-01 2003-05-01 +1 2003-05-01 2003-07-01 +2 2003-01-01 2003-01-15 +2 2003-01-15 2003-02-01 +2 2003-04-15 2003-05-01 +drop table t_myisam, t_innodb; +create or replace table t(id int, s date, e date, +period for p(s,e), +primary key(id, q without overlaps)); +ERROR HY000: Period `q` is not found in table +create or replace table t(id int, s date, e date, +primary key(id, p without overlaps)); +ERROR HY000: Period `p` is not found in table +create or replace table t(id int, s date, e date, +period for p(s,e), +primary key(id, s, p without overlaps)); +ERROR HY000: Key `PRIMARY` cannot explicitly include column `s` +create or replace table t(id int, s date, e date, +period for p(s,e), +primary key(id)); +insert into t values (1, '2003-03-01', '2003-05-01'); +insert into t values (1, '2003-04-01', '2003-05-01'); +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +create or replace table t(id int, u int, s date, e date, +period for p(s,e), +primary key(id, p without overlaps), +unique(u)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `id` int(11) NOT NULL, + `u` int(11) DEFAULT NULL, + `s` date NOT NULL, + `e` date NOT NULL, + PERIOD FOR `p` (`s`, `e`), + PRIMARY KEY (`id`,`p` WITHOUT OVERLAPS), + UNIQUE KEY `u` (`u`) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +insert into t values (1, 1, '2003-03-01', '2003-05-01'); +insert into t values (1, 2, '2003-05-01', '2003-07-01'); +insert into t values (1, 3, '2003-04-01', '2003-05-01'); +ERROR 23000: Duplicate entry '1-2003-05-01-2003-04-01' for key 'PRIMARY' +create or replace table t(id int, u int, s date, e date, +period for p(s,e), +primary key(id, p without overlaps), +unique(u, p without overlaps)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `id` int(11) NOT NULL, + `u` int(11) DEFAULT NULL, + `s` date NOT NULL, + `e` date NOT NULL, + PERIOD FOR `p` (`s`, `e`), + PRIMARY KEY (`id`,`p` WITHOUT OVERLAPS), + UNIQUE KEY `u` (`u`,`p` WITHOUT OVERLAPS) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +insert into t values (2, NULL, '2003-03-01', '2003-05-01'); +insert into t values (2, NULL, '2003-03-01', '2003-05-01'); +ERROR 23000: Duplicate entry '2-2003-05-01-2003-03-01' for key 'PRIMARY' +insert into t values (3, NULL, '2003-03-01', '2003-05-01'); +insert into t values (1, 1, '2003-03-01', '2003-05-01'); +insert into t values (1, 2, '2003-05-01', '2003-07-01'); +insert into t values (4, NULL, '2003-03-01', '2003-05-01'); +create sequence seq start=5 engine=myisam; +update t set id= nextval(seq), u= nextval(seq), s='2003-05-01', e='2003-07-01' + where u is NULL; +select * from t; +id u s e +1 1 2003-03-01 2003-05-01 +1 2 2003-05-01 2003-07-01 +5 6 2003-05-01 2003-07-01 +7 8 2003-05-01 2003-07-01 +9 10 2003-05-01 2003-07-01 +drop sequence seq; +create or replace table t(id int, s date, e date, +period for p(s,e)); +insert into t values (1, '2003-01-01', '2003-03-01'), +(1, '2003-05-01', '2003-07-01'), +(1, '2003-02-01', '2003-04-01'); +alter table t add primary key(id, p without overlaps); +ERROR 23000: Duplicate entry '1-2003-04-01-2003-02-01' for key 'PRIMARY' +# Historical rows are not checked against constraints +set @@system_versioning_alter_history= keep; +alter table t add system versioning; +delete from t; +alter table t add primary key(id, p without overlaps); +insert into t values (1, '2003-01-01', '2003-03-01'), +(1, '2003-03-01', '2003-05-01'); +# `without overlaps` is not lost on alter table +alter table t add y int; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `id` int(11) NOT NULL, + `s` date NOT NULL, + `e` date NOT NULL, + `y` int(11) DEFAULT NULL, + PERIOD FOR `p` (`s`, `e`), + PRIMARY KEY (`id`,`p` WITHOUT OVERLAPS) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +alter table t drop y; +create or replace table t1 like t; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `s` date NOT NULL, + `e` date NOT NULL, + PERIOD FOR `p` (`s`, `e`), + PRIMARY KEY (`id`,`p` WITHOUT OVERLAPS) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +create or replace table t1 (x int, s date, e date, +period for p(s,e), +primary key(x, p without overlaps)); +alter table t1 partition by key (x); +create or replace table t1 (x int, s date, e date, period for p (s, e)) +partition by hash (x); +alter table t1 add primary key (x, p without overlaps); +create or replace table t2 (x int, s date, e date, +period for p (s, e), +key(x, p without overlaps)); +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 'without overlaps))' at line 3 +create or replace table t2 (x int, s date, e date, +period for p (s, e), +unique(x, p without overlaps, x, p without overlaps)); +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 ' x, p without overlaps))' at line 3 +create or replace table t1 (x varchar(100), s date, e date, +period for p(s,e), +primary key(x, p without overlaps)); +create or replace table t1 (x varchar(100) compressed, s date, e date, +period for p(s,e), +primary key(x, p without overlaps)); +ERROR HY000: Compressed column 'x' can't be used in key specification +create or replace table t (x int, s date, e date, period for apptime(s,e), +unique(x, apptime without overlaps) using hash); +ERROR HY000: Key `x` cannot have WITHOUT OVERLAPS +create or replace table t (x int, s date, e date, period for apptime(s,e), +b blob, unique(x, b, apptime without overlaps)); +ERROR HY000: Key `x` cannot have WITHOUT OVERLAPS +create or replace table t (x int, s date, e date, b blob unique, +period for apptime(s,e), +unique(x, apptime without overlaps)); +insert into t values (1, '2020-03-01', '2020-03-05', 'test'); +insert into t values (1, '2020-03-05', '2020-03-10', 'test'); +ERROR 23000: Duplicate entry 'test' for key 'b' +insert into t values (1, '2020-03-05', '2020-03-10', 'test2'); +insert into t values (1, '2020-03-03', '2020-03-10', 'test3'); +ERROR 23000: Duplicate entry '1-2020-03-10-2020-03-03' for key 'x' +create or replace table t (x int, s date, e date, period for apptime(s,e), +unique(x, apptime without overlaps)); +replace into t values (1, '2020-03-03', '2020-03-10'); +ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS' +insert into t values (1, '2020-03-03', '2020-03-10') +on duplicate key update x = 2; +ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS' +select * from t; +x s e +select * into outfile 'tmp_t.txt' from t; +load data infile 'tmp_t.txt' into table t; +load data infile 'tmp_t.txt' replace into table t; +ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS' +insert into t values (1, '2020-03-01', '2020-03-05'); +select * into outfile 'tmp_t.txt' from t; +load data infile 'tmp_t.txt' into table t; +ERROR 23000: Duplicate entry '1-2020-03-05-2020-03-01' for key 'x' +load data infile 'tmp_t.txt' ignore into table t; +Warnings: +Warning 1062 Duplicate entry '1-2020-03-05-2020-03-01' for key 'x' +load data infile 'tmp_t.txt' replace into table t; +ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS' +# MDEV-22599 WITHOUT OVERLAPS does not work with prefix indexes +create or replace table t1 (a varchar(6), s timestamp, e timestamp, +period for p(s,e), +unique(a(3), p without overlaps)); +insert into t1 values ('foo', '2012-01-01', '2015-12-31'); +insert into t1 values ('foobar', '2013-01-01', '2014-01-01'); +ERROR 23000: Duplicate entry 'foo-2014-01-01 00:00:00-2013-01-01 00:00:00' for key 'a' +insert into t1 values ('bar', '2012-01-01', '2015-12-31'), +('baz', '2013-01-01', '2014-01-01'); +select * from t1; +a s e +foo 2012-01-01 00:00:00 2015-12-31 00:00:00 +bar 2012-01-01 00:00:00 2015-12-31 00:00:00 +baz 2013-01-01 00:00:00 2014-01-01 00:00:00 +# MDEV-22753 Server crashes in handler::ha_check_overlaps or error 190 +# "Incompatible key or row definition" upon INSERT into versioned +# partitioned table with WITHOUT OVERLAPS +create or replace table t1 (f int, s date, e date, period for p(s,e), +unique(f, p without overlaps) +) engine=innodb with system versioning +partition by system_time limit 1000 +(partition p1 history, partition pn current); +alter table t1 add partition (partition p2 history); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f` int(11) DEFAULT NULL, + `s` date NOT NULL, + `e` date NOT NULL, + PERIOD FOR `p` (`s`, `e`), + UNIQUE KEY `f` (`f`,`p` WITHOUT OVERLAPS) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY SYSTEM_TIME LIMIT 1000 +(PARTITION `p1` HISTORY ENGINE = InnoDB, + PARTITION `p2` HISTORY ENGINE = InnoDB, + PARTITION `pn` CURRENT ENGINE = InnoDB) +insert into t1 values (1,'2013-01-12','2015-11-04'), +(2,'2016-03-15','2024-11-09'); +# MDEV-22714 Assertion `index->table->is_instant()' failed upon +# multi-update on table with WITHOUT OVERLAPS +create or replace table t (a int); +insert into t values (0),(null),(0); +create or replace table t1 (f int, s date, e date, period for p(s,e), +unique(f, p without overlaps)); +insert into t1 values (0,'2026-02-12','2036-09-16'), +(null,'2025-03-09','2032-12-05'); +update ignore t join t1 set f = a; +# MDEV-22639 Assertion `inited != NONE' failed in +# handler::ha_check_overlaps upon multi-table update +create or replace table t (f int, s date, e date, period for p(s,e), +unique(f, p without overlaps)) engine=myisam; +insert into t values (1,'1988-08-25','2024-03-06'); +create or replace table t1 (a int) engine=myisam; +insert into t1 values (1),(2); +update t join t1 set s = '2020-01-01'; +# MDEV-22608 ASAN use-after-poison in TABLE::check_period_overlaps +create or replace table t1 (s date, e date, b bit, period for p(s,e), +unique(b, p without overlaps)) engine=myisam; +insert into t1 values ('2024-12-21','2034-06-29',0), +('2024-12-21','2034-06-29',1); +update t1 set b = 1; +ERROR 23000: Duplicate entry '\x01-2034-06-29-2024-12-21' for key 'b' +# MDEV-22677 Server crashes in ha_partition::open upon update on +# partitioned HEAP table with WITHOUT OVERLAPS +create or replace table t (id int, s date, e date, period for p(s,e), +primary key(id, p without overlaps) +) engine=heap partition by hash(id); +update t set id = 1; +drop table t, t1; diff --git a/mysql-test/suite/period/t/alter.test b/mysql-test/suite/period/t/alter.test index 3fa3c5c87d5..68d9adf476a 100644 --- a/mysql-test/suite/period/t/alter.test +++ b/mysql-test/suite/period/t/alter.test @@ -151,3 +151,19 @@ alter table t1 add system versioning; # cleanup drop table t1; + +--echo # +--echo # MDEV-21941 RENAME doesn't work for system time or period fields +--echo # +create or replace table t1 ( + a int, s date, e date, + period for mytime(s, e)); + +alter table t1 rename column s to x; +alter table t1 rename column e to y; + +show create table t1; +# cleanup +drop table t1; + +--echo # End of 10.5 tests diff --git a/mysql-test/suite/period/t/delete.test b/mysql-test/suite/period/t/delete.test index 2a5f65d80ba..91670469bab 100644 --- a/mysql-test/suite/period/t/delete.test +++ b/mysql-test/suite/period/t/delete.test @@ -225,3 +225,13 @@ delete ignore from t --enable_warnings drop table t; + +# +# MDEV-22424 Server crashes in handler::check_duplicate_long_entry_key or Assertion `inited == NONE || lookup_handler != this' failed upon DELETE FOR PORTION on table with long unique key +# +create table t1 (pk int, s date, e date, period for se (s,e), primary key (pk,se without overlaps)); +insert into t1 values (1,'2020-01-01','2020-02-20'); +delete from t1 for portion of se from '2020-01-30' to '2020-01-31'; +drop table t1; + +--echo # End of 10.5 tests diff --git a/mysql-test/suite/period/t/long_unique.test b/mysql-test/suite/period/t/long_unique.test new file mode 100644 index 00000000000..c2dcd3f6c3f --- /dev/null +++ b/mysql-test/suite/period/t/long_unique.test @@ -0,0 +1,23 @@ +--source include/have_partition.inc + +--echo # +--echo # Assertion `inited == NONE || update_handler != this' failed in +--echo # handler::ha_write_row +--echo # + +CREATE TABLE t1 (f VARCHAR(4096), s DATE, e DATE, PERIOD FOR app(s,e), UNIQUE(f)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo', '2023-08-30', '2025-07-09'),('bar', '2021-01-01', '2021-12-31'); +DELETE FROM t1 FOR PORTION OF app FROM '2023-08-29' TO '2025-07-01'; +DROP TABLE t1; + +--echo # +--echo # MDEV-21819 Assertion `inited == NONE || update_handler != this' +--echo # failed in handler::ha_write_row +--echo # + +CREATE OR REPLACE TABLE t1 (a INT, b BLOB, s DATE, e DATE, PERIOD FOR app(s,e), UNIQUE(b)) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2; +INSERT INTO t1 VALUES (1,'foo','2022-01-01', '2025-01-01'); +--error ER_DUP_ENTRY +DELETE FROM t1 FOR PORTION OF app FROM '2023-01-01' TO '2024-01-01'; +DROP TABLE t1; + diff --git a/mysql-test/suite/period/t/overlaps.test b/mysql-test/suite/period/t/overlaps.test new file mode 100644 index 00000000000..6cd78769d4a --- /dev/null +++ b/mysql-test/suite/period/t/overlaps.test @@ -0,0 +1,346 @@ +--source include/have_partition.inc + +# Test both myisam and innodb +--source suite/period/engines.inc + +let $default_engine= `select @@default_storage_engine`; + +create or replace table t(id int, s date, e date, + period for p(s,e), + primary key(id, p without overlaps) +) partition by key (id); + +--replace_result $default_engine DEFAULT_ENGINE +show create table t; + + +insert into t values (1, '2003-01-01', '2003-03-01'), + (1, '2003-05-01', '2003-07-01'); + +--error ER_DUP_ENTRY +insert into t values (1, '2003-02-01', '2003-04-01'); +--error ER_DUP_ENTRY +insert into t values (1, '2003-04-01', '2003-06-01'); +--error ER_DUP_ENTRY +insert into t values (1, '2003-05-15', '2003-06-15'); +--error ER_DUP_ENTRY +insert into t values (1, '2003-04-01', '2003-08-01'); + +insert into t values (1, '2003-03-01', '2003-05-01'); + +--echo # expand/shrink period +update t set s= '2002-12-01' where s = '2003-01-01'; +update t set s= '2003-01-01' where s = '2002-12-01'; + +update t set e= '2003-08-01' where s = '2003-05-01'; +update t set e= '2003-07-01' where s = '2003-05-01'; + +--echo # move left/right +update t set s= '2002-12-15', e= '2003-01-15' where s = '2003-01-01'; +update t set s= '2003-01-01', e= '2003-02-01' where s = '2002-12-15'; + +--echo # diminish/enlarge +update t set s= '2003-01-10', e= '2003-01-20' where s = '2003-01-01'; +update t set s= '2003-01-01', e= '2003-02-01' where s = '2003-01-10'; + +select * from t; + +--echo # intersect left/right, strict inclusion/containment +--error ER_DUP_ENTRY +update t set e= '2003-04-01' where s = '2003-01-01'; +--error ER_DUP_ENTRY +update t set s= '2003-04-01' where s = '2003-05-01'; +--error ER_DUP_ENTRY +update t set s= '2003-03-10', e= '2003-03-20' where s = '2003-01-01'; +--error ER_DUP_ENTRY +update t set s= '2003-04-01', e= '2003-08-01' where s = '2003-03-01'; + +--echo # inclusion/containment with partial match +--error ER_DUP_ENTRY +update t set s= '2003-03-01', e= '2003-04-01' where s = '2003-01-01'; +--error ER_DUP_ENTRY +update t set s= '2003-04-01', e= '2003-05-01' where s = '2003-01-01'; +--error ER_DUP_ENTRY +update t set s= '2003-03-01' where s = '2003-05-01'; +--error ER_DUP_ENTRY +update t set e= '2003-05-01' where s = '2003-01-01'; + +select * from t where year(s) = 2003; + +--echo # UPDATE ... FOR PORTION test +insert t values (2, '2003-04-15', '2003-05-01'); + +update t for portion of p from '2003-01-01' to '2003-01-15' + set id= 2; +--sorted_result +select * from t; + +update t for portion of p from '2003-01-15' to '2003-02-01' + set id= 2; +--sorted_result +select * from t; + +--echo # Next, test UPDATE ... FOR PORTION resulting with an error +--echo # Since MyISAM/Aria engines lack atomicity, the results would differ with +--echo # innodb. So a table is going to be copied to one with explicit engine. + +create table t_myisam (id int, s date, e date, + period for p(s,e), + primary key(id, p without overlaps)) + engine=myisam + select * from t; +--error ER_DUP_ENTRY +update t_myisam for portion of p from '2003-04-01' to '2003-06-01' + set id= 2 order by s desc; +--sorted_result +select * from t_myisam; + +create table t_innodb (id int, s date, e date, + period for p(s,e), + primary key(id, p without overlaps)) + engine=innodb + select * from t; +--error ER_DUP_ENTRY +update t_innodb for portion of p from '2003-04-01' to '2003-06-01' + set id= 2 order by s desc; +--sorted_result +select * from t_innodb; + +drop table t_myisam, t_innodb; + +--error ER_PERIOD_NOT_FOUND +create or replace table t(id int, s date, e date, + period for p(s,e), + primary key(id, q without overlaps)); + +--error ER_PERIOD_NOT_FOUND +create or replace table t(id int, s date, e date, + primary key(id, p without overlaps)); + +--error ER_KEY_CONTAINS_PERIOD_FIELDS +create or replace table t(id int, s date, e date, + period for p(s,e), + primary key(id, s, p without overlaps)); + +create or replace table t(id int, s date, e date, + period for p(s,e), + primary key(id)); +insert into t values (1, '2003-03-01', '2003-05-01'); +--error ER_DUP_ENTRY +insert into t values (1, '2003-04-01', '2003-05-01'); + +create or replace table t(id int, u int, s date, e date, + period for p(s,e), + primary key(id, p without overlaps), + unique(u)); +--replace_result $default_engine DEFAULT_ENGINE +show create table t; +insert into t values (1, 1, '2003-03-01', '2003-05-01'); +insert into t values (1, 2, '2003-05-01', '2003-07-01'); +--error ER_DUP_ENTRY +insert into t values (1, 3, '2003-04-01', '2003-05-01'); + + + +create or replace table t(id int, u int, s date, e date, + period for p(s,e), + primary key(id, p without overlaps), + unique(u, p without overlaps)); +--replace_result $default_engine DEFAULT_ENGINE +show create table t; + +insert into t values (2, NULL, '2003-03-01', '2003-05-01'); +--error ER_DUP_ENTRY +insert into t values (2, NULL, '2003-03-01', '2003-05-01'); +insert into t values (3, NULL, '2003-03-01', '2003-05-01'); +insert into t values (1, 1, '2003-03-01', '2003-05-01'); +insert into t values (1, 2, '2003-05-01', '2003-07-01'); +insert into t values (4, NULL, '2003-03-01', '2003-05-01'); + +create sequence seq start=5 engine=myisam; +update t set id= nextval(seq), u= nextval(seq), s='2003-05-01', e='2003-07-01' + where u is NULL; + +--sorted_result +select * from t; +drop sequence seq; + +create or replace table t(id int, s date, e date, + period for p(s,e)); + +insert into t values (1, '2003-01-01', '2003-03-01'), + (1, '2003-05-01', '2003-07-01'), + (1, '2003-02-01', '2003-04-01'); + +--replace_regex /#sql-\w+/#sql-temp/ +--error ER_DUP_ENTRY +alter table t add primary key(id, p without overlaps); + +--echo # Historical rows are not checked against constraints +set @@system_versioning_alter_history= keep; +alter table t add system versioning; +delete from t; +alter table t add primary key(id, p without overlaps); + +insert into t values (1, '2003-01-01', '2003-03-01'), + (1, '2003-03-01', '2003-05-01'); + + +--echo # `without overlaps` is not lost on alter table +alter table t add y int; +--replace_result $default_engine DEFAULT_ENGINE +show create table t; +alter table t drop y; + +create or replace table t1 like t; +--replace_result $default_engine DEFAULT_ENGINE +show create table t1; + +create or replace table t1 (x int, s date, e date, + period for p(s,e), + primary key(x, p without overlaps)); +alter table t1 partition by key (x); + +create or replace table t1 (x int, s date, e date, period for p (s, e)) + partition by hash (x); +alter table t1 add primary key (x, p without overlaps); + +--error ER_PARSE_ERROR +create or replace table t2 (x int, s date, e date, + period for p (s, e), + key(x, p without overlaps)); + +--error ER_PARSE_ERROR +create or replace table t2 (x int, s date, e date, + period for p (s, e), + unique(x, p without overlaps, x, p without overlaps)); + +create or replace table t1 (x varchar(100), s date, e date, + period for p(s,e), + primary key(x, p without overlaps)); + +--error ER_COMPRESSED_COLUMN_USED_AS_KEY +create or replace table t1 (x varchar(100) compressed, s date, e date, + period for p(s,e), + primary key(x, p without overlaps)); + +--error ER_KEY_CANT_HAVE_WITHOUT_OVERLAPS +create or replace table t (x int, s date, e date, period for apptime(s,e), + unique(x, apptime without overlaps) using hash); + +--error ER_KEY_CANT_HAVE_WITHOUT_OVERLAPS +create or replace table t (x int, s date, e date, period for apptime(s,e), + b blob, unique(x, b, apptime without overlaps)); + +create or replace table t (x int, s date, e date, b blob unique, + period for apptime(s,e), + unique(x, apptime without overlaps)); + +insert into t values (1, '2020-03-01', '2020-03-05', 'test'); +--error ER_DUP_ENTRY +insert into t values (1, '2020-03-05', '2020-03-10', 'test'); +insert into t values (1, '2020-03-05', '2020-03-10', 'test2'); +--error ER_DUP_ENTRY +insert into t values (1, '2020-03-03', '2020-03-10', 'test3'); + +let $MYSQLD_DATADIR= `select @@datadir`; +create or replace table t (x int, s date, e date, period for apptime(s,e), + unique(x, apptime without overlaps)); +--error ER_NOT_SUPPORTED_YET +replace into t values (1, '2020-03-03', '2020-03-10'); +--error ER_NOT_SUPPORTED_YET +insert into t values (1, '2020-03-03', '2020-03-10') + on duplicate key update x = 2; + +select * from t; +select * into outfile 'tmp_t.txt' from t; +load data infile 'tmp_t.txt' into table t; +--error ER_NOT_SUPPORTED_YET +load data infile 'tmp_t.txt' replace into table t; +remove_file $MYSQLD_DATADIR/test/tmp_t.txt; + +insert into t values (1, '2020-03-01', '2020-03-05'); +select * into outfile 'tmp_t.txt' from t; +--error ER_DUP_ENTRY +load data infile 'tmp_t.txt' into table t; + +load data infile 'tmp_t.txt' ignore into table t; + +--error ER_NOT_SUPPORTED_YET +load data infile 'tmp_t.txt' replace into table t; + +remove_file $MYSQLD_DATADIR/test/tmp_t.txt; + + +--echo # MDEV-22599 WITHOUT OVERLAPS does not work with prefix indexes +create or replace table t1 (a varchar(6), s timestamp, e timestamp, + period for p(s,e), + unique(a(3), p without overlaps)); + +insert into t1 values ('foo', '2012-01-01', '2015-12-31'); +--error ER_DUP_ENTRY +insert into t1 values ('foobar', '2013-01-01', '2014-01-01'); + +insert into t1 values ('bar', '2012-01-01', '2015-12-31'), + ('baz', '2013-01-01', '2014-01-01'); +select * from t1; + +--echo # MDEV-22753 Server crashes in handler::ha_check_overlaps or error 190 +--echo # "Incompatible key or row definition" upon INSERT into versioned +--echo # partitioned table with WITHOUT OVERLAPS +create or replace table t1 (f int, s date, e date, period for p(s,e), + unique(f, p without overlaps) + ) engine=innodb with system versioning + partition by system_time limit 1000 + (partition p1 history, partition pn current); +alter table t1 add partition (partition p2 history); +show create table t1; +insert into t1 values (1,'2013-01-12','2015-11-04'), + (2,'2016-03-15','2024-11-09'); + + +--echo # MDEV-22714 Assertion `index->table->is_instant()' failed upon +--echo # multi-update on table with WITHOUT OVERLAPS + +create or replace table t (a int); +insert into t values (0),(null),(0); + +create or replace table t1 (f int, s date, e date, period for p(s,e), + unique(f, p without overlaps)); + +insert into t1 values (0,'2026-02-12','2036-09-16'), + (null,'2025-03-09','2032-12-05'); + +update ignore t join t1 set f = a; + +--echo # MDEV-22639 Assertion `inited != NONE' failed in +--echo # handler::ha_check_overlaps upon multi-table update + +create or replace table t (f int, s date, e date, period for p(s,e), + unique(f, p without overlaps)) engine=myisam; +insert into t values (1,'1988-08-25','2024-03-06'); +create or replace table t1 (a int) engine=myisam; +insert into t1 values (1),(2); + +update t join t1 set s = '2020-01-01'; + + +--echo # MDEV-22608 ASAN use-after-poison in TABLE::check_period_overlaps + +create or replace table t1 (s date, e date, b bit, period for p(s,e), + unique(b, p without overlaps)) engine=myisam; +insert into t1 values ('2024-12-21','2034-06-29',0), + ('2024-12-21','2034-06-29',1); +--error ER_DUP_ENTRY +update t1 set b = 1; + + +--echo # MDEV-22677 Server crashes in ha_partition::open upon update on +--echo # partitioned HEAP table with WITHOUT OVERLAPS + +create or replace table t (id int, s date, e date, period for p(s,e), + primary key(id, p without overlaps) + ) engine=heap partition by hash(id); +update t set id = 1; + +drop table t, t1; |