Skip to content

Commit

Permalink
MDEV-22439 Add FOR PORTION OF statements to the test for WITHOUT OVER…
Browse files Browse the repository at this point in the history
…LAPS
  • Loading branch information
FooBarrior committed Jun 5, 2020
1 parent b1ab211 commit c3e09a2
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions mysql-test/suite/period/engines.combinations
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ innodb
default-storage-engine=innodb

[myisam]
innodb
default-storage-engine=myisam
55 changes: 55 additions & 0 deletions mysql-test/suite/period/r/overlaps.result
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,61 @@ 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));
Expand Down
41 changes: 41 additions & 0 deletions mysql-test/suite/period/t/overlaps.test
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,47 @@ 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),
Expand Down

0 comments on commit c3e09a2

Please sign in to comment.