Skip to content
Permalink
Browse files
IB: CASCADE operation for DELETE
* Removed "Not supported for TIMESTAMP-based" error
* Fixed code duplication with node->vers_set_fields()
* Recovered foreign.test

[closes tempesta-tech#473]
  • Loading branch information
midenok authored and kevgs committed Mar 19, 2018
1 parent 85ddd9e commit 0cf97ad
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 151 deletions.
@@ -77,4 +77,26 @@ if ($MTR_COMBINATION_TRX_ID)
let $sys_datatype_expl_uc= BIGINT(20) UNSIGNED;
let $sys_datatype_max= 18446744073709551615;
}

eval create or replace function current_row(sys_trx_end $sys_datatype_expl)
returns int
deterministic
return sys_trx_end = $sys_datatype_max;

delimiter ~~;
eval create or replace function check_row(row_start $sys_datatype_expl, row_end $sys_datatype_expl)
returns varchar(255)
deterministic
begin
if row_end < row_start then
return "ERROR: row_end < row_start";
elseif row_end = row_start then
return "ERROR: row_end == row_start";
elseif current_row(row_end) then
return "CURRENT ROW";
end if;
return "HISTORICAL ROW";
end~~
delimiter ;~~

--enable_query_log
@@ -4,4 +4,6 @@ drop procedure verify_vtq_dummy;
drop function sys_commit_ts;
drop procedure concat_exec2;
drop procedure concat_exec3;
drop function current_row;
drop function check_row;
--enable_query_log
@@ -6,8 +6,8 @@ id int unique key
) engine innodb;
create table child(
parent_id int,
sys_start timestamp(6) as row start invisible,
sys_end timestamp(6) as row end invisible,
sys_start SYS_DATATYPE as row start invisible,
sys_end SYS_DATATYPE as row end invisible,
period for system_time(sys_start, sys_end),
foreign key(parent_id) references parent(id)
on delete restrict
@@ -25,7 +25,7 @@ update parent set id=id+1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))
delete from child;
update parent set id=id+1;
select * from child for system_time from timestamp 0 to timestamp now(6);
select * from child for system_time all;
parent_id
1
1
@@ -39,8 +39,8 @@ id int(10) unsigned unique key
) engine innodb;
create table child(
parent_id int(10) unsigned primary key,
sys_start timestamp(6) as row start invisible,
sys_end timestamp(6) as row end invisible,
sys_start SYS_DATATYPE as row start invisible,
sys_end SYS_DATATYPE as row end invisible,
period for system_time(sys_start, sys_end),
foreign key(parent_id) references parent(id)
) engine innodb with system versioning;
@@ -58,19 +58,37 @@ id int unique key
) engine innodb;
create table child(
parent_id int,
sys_start timestamp(6) as row start invisible,
sys_end timestamp(6) as row end invisible,
sys_start SYS_DATATYPE as row start invisible,
sys_end SYS_DATATYPE as row end invisible,
period for system_time(sys_start, sys_end),
foreign key(parent_id) references parent(id)
on delete cascade
on update cascade
) engine innodb with system versioning;
ERROR HY000: CASCADE is not supported for TIMESTAMP(6) AS ROW START/END system-versioned tables
insert into parent values(1);
insert into child values(1);
delete from parent where id = 1;
select * from child;
parent_id
select * from child for system_time all;
parent_id
1
insert into parent values(1);
insert into child values(1);
update parent set id = id + 1;
select * from child;
parent_id
2
select * from child for system_time all;
parent_id
1
2
drop table child;
drop table parent;
create or replace table parent (
id int primary key,
sys_start timestamp(6) as row start invisible,
sys_end timestamp(6) as row end invisible,
sys_start SYS_DATATYPE as row start invisible,
sys_end SYS_DATATYPE as row end invisible,
period for system_time(sys_start, sys_end)
) with system versioning
engine innodb;
@@ -97,41 +115,73 @@ engine innodb;
create or replace table child (
id int primary key,
parent_id int not null,
row_start timestamp(6) as row start invisible,
row_end timestamp(6) as row end invisible,
row_start SYS_DATATYPE as row start invisible,
row_end SYS_DATATYPE as row end invisible,
period for system_time(row_start, row_end),
constraint `parent-fk`
foreign key (parent_id) references parent (id)
on delete cascade
on update restrict
) with system versioning
engine innodb;
ERROR HY000: CASCADE is not supported for TIMESTAMP(6) AS ROW START/END system-versioned tables
insert into parent (id) values (3);
insert into child (id, parent_id) values (3, 3);
delete from parent;
select * from child;
id parent_id
select *, check_row(row_start, row_end) from child for system_time all;
id parent_id check_row(row_start, row_end)
3 3 HISTORICAL ROW
drop table child;
drop table parent;
#################
# Test SET NULL #
#################
create table parent(
create or replace table parent(
id int unique key
) engine innodb;
create table child(
create or replace table child(
parent_id int,
sys_start timestamp(6) as row start invisible,
sys_end timestamp(6) as row end invisible,
sys_start SYS_DATATYPE as row start invisible,
sys_end SYS_DATATYPE as row end invisible,
period for system_time(sys_start, sys_end),
foreign key(parent_id) references parent(id)
on delete set null
on update set null
) engine innodb with system versioning;
ERROR HY000: SET NULL is not supported for TIMESTAMP(6) AS ROW START/END system-versioned tables
insert into parent values(1);
insert into child values(1);
delete from child;
insert into child values(1);
delete from parent where id = 1;
select * from child;
parent_id
NULL
select *, current_row(sys_end) as current_row from child for system_time all order by sys_end;
parent_id current_row
1 0
NULL 1
delete from child;
insert into parent values(1);
insert into child values(1);
update parent set id= id + 1;
select * from child;
parent_id
NULL
select *, current_row(sys_end) as current_row from child for system_time all order by sys_end;
parent_id current_row
1 0
NULL 0
NULL 1
drop table child;
drop table parent;
###########################
# Parent table is foreign #
###########################
create or replace table parent(
id int unique key,
sys_start timestamp(6) as row start invisible,
sys_end timestamp(6) as row end invisible,
sys_start SYS_DATATYPE as row start invisible,
sys_end SYS_DATATYPE as row end invisible,
period for system_time(sys_start, sys_end)
) engine innodb with system versioning;
create or replace table child(
@@ -162,16 +212,16 @@ drop table parent;
create or replace table a (
cola int(10) primary key,
v_cola int(10) as (cola mod 10) virtual,
sys_start timestamp(6) as row start invisible,
sys_end timestamp(6) as row end invisible,
sys_start SYS_DATATYPE as row start invisible,
sys_end SYS_DATATYPE as row end invisible,
period for system_time(sys_start, sys_end)
) engine=innodb with system versioning;
create index v_cola on a (v_cola);
create or replace table b(
cola int(10),
v_cola int(10),
sys_start timestamp(6) as row start invisible,
sys_end timestamp(6) as row end invisible,
sys_start SYS_DATATYPE as row start invisible,
sys_end SYS_DATATYPE as row end invisible,
period for system_time(sys_start, sys_end)
) engine=innodb with system versioning;
alter table b add constraint `v_cola_fk`
@@ -8,6 +8,7 @@ create table parent(
id int unique key
) engine innodb;

--replace_result $sys_datatype_expl SYS_DATATYPE
eval create table child(
parent_id int,
sys_start $sys_datatype_expl as row start invisible,
@@ -32,7 +33,7 @@ insert into child values(1);
update parent set id=id+1;
delete from child;
update parent set id=id+1;
select * from child for system_time from timestamp 0 to timestamp now(6);
select * from child for system_time all;

drop table child;
drop table parent;
@@ -45,6 +46,7 @@ create table parent(
id int(10) unsigned unique key
) engine innodb;

--replace_result $sys_datatype_expl SYS_DATATYPE
eval create table child(
parent_id int(10) unsigned primary key,
sys_start $sys_datatype_expl as row start invisible,
@@ -70,7 +72,7 @@ create table parent(
id int unique key
) engine innodb;

--disable_abort_on_error
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create table child(
parent_id int,
sys_start $sys_datatype_expl as row start invisible,
@@ -80,14 +82,10 @@ eval create table child(
on delete cascade
on update cascade
) engine innodb with system versioning;
--enable_abort_on_error

if ($MTR_COMBINATION_TRX_ID) {
insert into parent values(1);
insert into child values(1);

delete from parent where id = 1;
delete from child where parent_id = 1;
delete from parent where id = 1;
select * from child;
select * from child for system_time all;
@@ -99,8 +97,9 @@ select * from child;
select * from child for system_time all;

drop table child;
}
drop table parent;

--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table parent (
id int primary key,
sys_start $sys_datatype_expl as row start invisible,
@@ -132,7 +131,7 @@ create or replace table parent (
)
engine innodb;

--disable_abort_on_error
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table child (
id int primary key,
parent_id int not null,
@@ -145,33 +144,26 @@ eval create or replace table child (
on update restrict
) with system versioning
engine innodb;
--enable_abort_on_error

if ($MTR_COMBINATION_TRX_ID) {
insert into parent (id) values (3);
insert into child (id, parent_id) values (3, 3);
--echo ## FIXME: #415 update of foreign constraints is disabled
delete from child;
--echo ## FIXME END
delete from parent;
select * from child;
--replace_result $sys_datatype_max MAXVAL
eval select *, row_start < row_end, row_end < $sys_datatype_max from child for system_time all;
select *, check_row(row_start, row_end) from child for system_time all;

drop table child;
}
drop table parent;

--echo #################
--echo # Test SET NULL #
--echo #################

create table parent(
create or replace table parent(
id int unique key
) engine innodb;

--disable_abort_on_error
eval create table child(
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table child(
parent_id int,
sys_start $sys_datatype_expl as row start invisible,
sys_end $sys_datatype_expl as row end invisible,
@@ -180,41 +172,31 @@ eval create table child(
on delete set null
on update set null
) engine innodb with system versioning;
--enable_abort_on_error

if ($MTR_COMBINATION_TRX_ID) {
insert into parent values(1);
insert into child values(1);
delete from child;
insert into child values(1);

--echo ## FIXME: #415 update of foreign constraints is disabled
delete from child where parent_id = 1;
--echo ## FIXME END
delete from parent where id = 1;
select * from child;
select * from child for system_time from timestamp 0 to timestamp now(6);
select *, current_row(sys_end) as current_row from child for system_time all order by sys_end;
delete from child;

insert into parent values(1);
insert into child values(1);
## FIXME: #415 update of foreign constraints is disabled
if (0)
{
update parent set id=id+1;
update parent set id= id + 1;
select * from child;
select * from child for system_time from timestamp 0 to timestamp now(6);
}
## FIXME END
select *, current_row(sys_end) as current_row from child for system_time all order by sys_end;

drop table child;
}
drop table parent;

--echo ###########################
--echo # Parent table is foreign #
--echo ###########################

--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table parent(
id int unique key,
sys_start $sys_datatype_expl as row start invisible,
@@ -254,6 +236,7 @@ drop table parent;
--echo # crash on DELETE #
--echo ###################

--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table a (
cola int(10) primary key,
v_cola int(10) as (cola mod 10) virtual,
@@ -264,6 +247,7 @@ eval create or replace table a (

create index v_cola on a (v_cola);

--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table b(
cola int(10),
v_cola int(10),

0 comments on commit 0cf97ad

Please sign in to comment.