2017-12-26 15:16:50 +01:00
|
|
|
--source suite/versioning/common.inc
|
2016-11-01 17:51:44 +01:00
|
|
|
|
2017-12-18 17:03:51 +01:00
|
|
|
--echo #################
|
|
|
|
--echo # Test RESTRICT #
|
|
|
|
--echo #################
|
2016-11-01 17:51:44 +01:00
|
|
|
|
|
|
|
create table parent(
|
|
|
|
id int unique key
|
|
|
|
) engine innodb;
|
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
2017-12-26 15:16:50 +01:00
|
|
|
eval create table child(
|
2016-11-01 17:51:44 +01:00
|
|
|
parent_id int,
|
2017-12-26 15:16:50 +01:00
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end),
|
2016-11-01 17:51:44 +01:00
|
|
|
foreign key(parent_id) references parent(id)
|
|
|
|
on delete restrict
|
|
|
|
on update restrict
|
|
|
|
) engine innodb with system versioning;
|
|
|
|
|
|
|
|
insert into parent values(1);
|
|
|
|
insert into child values(1);
|
|
|
|
|
|
|
|
-- error ER_ROW_IS_REFERENCED_2
|
|
|
|
delete from parent where id = 1;
|
|
|
|
delete from child where parent_id = 1;
|
|
|
|
delete from parent where id = 1;
|
|
|
|
|
|
|
|
insert into parent values(1);
|
|
|
|
insert into child values(1);
|
|
|
|
-- error ER_ROW_IS_REFERENCED_2
|
|
|
|
update parent set id=id+1;
|
|
|
|
delete from child;
|
|
|
|
update parent set id=id+1;
|
2018-01-12 22:19:16 +01:00
|
|
|
select * from child for system_time all;
|
2016-11-01 17:51:44 +01:00
|
|
|
|
|
|
|
drop table child;
|
|
|
|
drop table parent;
|
|
|
|
|
2017-12-18 17:03:51 +01:00
|
|
|
--echo ##############################################
|
|
|
|
--echo # Test when clustered index is a foreign key #
|
|
|
|
--echo ##############################################
|
2016-11-01 17:51:44 +01:00
|
|
|
|
|
|
|
create table parent(
|
|
|
|
id int(10) unsigned unique key
|
|
|
|
) engine innodb;
|
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
2017-12-26 15:16:50 +01:00
|
|
|
eval create table child(
|
2016-11-01 17:51:44 +01:00
|
|
|
parent_id int(10) unsigned primary key,
|
2017-12-26 15:16:50 +01:00
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end),
|
2016-11-01 17:51:44 +01:00
|
|
|
foreign key(parent_id) references parent(id)
|
|
|
|
) engine innodb with system versioning;
|
|
|
|
|
|
|
|
insert into parent values(1);
|
|
|
|
insert into child values(1);
|
|
|
|
|
|
|
|
-- error ER_ROW_IS_REFERENCED_2
|
|
|
|
delete from parent where id = 1;
|
|
|
|
|
|
|
|
drop table child;
|
|
|
|
drop table parent;
|
|
|
|
|
2017-12-18 17:03:51 +01:00
|
|
|
--echo ################
|
|
|
|
--echo # Test CASCADE #
|
|
|
|
--echo ################
|
2016-11-01 17:51:44 +01:00
|
|
|
|
|
|
|
create table parent(
|
|
|
|
id int unique key
|
|
|
|
) engine innodb;
|
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
2017-12-26 15:16:50 +01:00
|
|
|
eval create table child(
|
2016-11-01 17:51:44 +01:00
|
|
|
parent_id int,
|
2017-12-26 15:16:50 +01:00
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end),
|
2016-11-01 17:51:44 +01:00
|
|
|
foreign key(parent_id) references parent(id)
|
|
|
|
on delete cascade
|
|
|
|
on update cascade
|
|
|
|
) engine innodb with system versioning;
|
|
|
|
|
|
|
|
insert into parent values(1);
|
|
|
|
insert into child values(1);
|
|
|
|
|
|
|
|
delete from parent where id = 1;
|
|
|
|
select * from child;
|
2016-12-21 06:57:00 +01:00
|
|
|
select * from child for system_time all;
|
2016-11-01 17:51:44 +01:00
|
|
|
|
|
|
|
insert into parent values(1);
|
|
|
|
insert into child values(1);
|
2016-12-21 06:57:00 +01:00
|
|
|
update parent set id = id + 1;
|
|
|
|
select * from child;
|
|
|
|
select * from child for system_time all;
|
|
|
|
|
|
|
|
drop table child;
|
|
|
|
drop table parent;
|
2018-01-12 22:19:16 +01:00
|
|
|
|
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
2017-12-26 15:16:50 +01:00
|
|
|
eval create or replace table parent (
|
|
|
|
id int primary key,
|
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end)
|
2016-12-21 06:57:00 +01:00
|
|
|
) with system versioning
|
|
|
|
engine innodb;
|
|
|
|
|
|
|
|
create or replace table child (
|
|
|
|
x int,
|
|
|
|
parent_id int not null,
|
|
|
|
constraint `parent-fk`
|
|
|
|
foreign key (parent_id) references parent (id)
|
|
|
|
on delete cascade
|
|
|
|
on update restrict
|
|
|
|
)
|
|
|
|
engine innodb;
|
|
|
|
|
2016-12-25 09:25:17 +01:00
|
|
|
insert into parent (id) values (2);
|
|
|
|
insert into child (x, parent_id) values (2, 2);
|
2016-12-21 06:57:00 +01:00
|
|
|
delete from parent;
|
2016-11-01 17:51:44 +01:00
|
|
|
select * from child;
|
|
|
|
|
|
|
|
drop table child;
|
|
|
|
drop table parent;
|
|
|
|
|
2016-12-25 09:25:17 +01:00
|
|
|
create or replace table parent (
|
|
|
|
id int primary key
|
|
|
|
)
|
|
|
|
engine innodb;
|
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
2018-02-16 09:34:52 +01:00
|
|
|
eval create or replace table child (
|
2016-12-25 09:25:17 +01:00
|
|
|
id int primary key,
|
|
|
|
parent_id int not null,
|
2018-02-16 09:34:52 +01:00
|
|
|
row_start $sys_datatype_expl as row start invisible,
|
|
|
|
row_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(row_start, row_end),
|
2016-12-25 09:25:17 +01:00
|
|
|
constraint `parent-fk`
|
|
|
|
foreign key (parent_id) references parent (id)
|
|
|
|
on delete cascade
|
|
|
|
on update restrict
|
|
|
|
) with system versioning
|
|
|
|
engine innodb;
|
|
|
|
|
|
|
|
insert into parent (id) values (3);
|
|
|
|
insert into child (id, parent_id) values (3, 3);
|
|
|
|
delete from parent;
|
|
|
|
select * from child;
|
2018-01-12 22:19:16 +01:00
|
|
|
select *, check_row(row_start, row_end) from child for system_time all;
|
2016-12-25 09:25:17 +01:00
|
|
|
|
|
|
|
drop table child;
|
|
|
|
drop table parent;
|
|
|
|
|
2017-12-18 17:03:51 +01:00
|
|
|
--echo #################
|
|
|
|
--echo # Test SET NULL #
|
|
|
|
--echo #################
|
2016-11-01 17:51:44 +01:00
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
create or replace table parent(
|
2016-11-01 17:51:44 +01:00
|
|
|
id int unique key
|
|
|
|
) engine innodb;
|
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
|
|
|
eval create or replace table child(
|
2016-11-01 17:51:44 +01:00
|
|
|
parent_id int,
|
2017-12-26 15:16:50 +01:00
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end),
|
2016-11-01 17:51:44 +01:00
|
|
|
foreign key(parent_id) references parent(id)
|
|
|
|
on delete set null
|
|
|
|
on update set null
|
|
|
|
) engine innodb with system versioning;
|
|
|
|
|
|
|
|
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;
|
2018-01-12 22:19:16 +01:00
|
|
|
select *, current_row(sys_end) as current_row from child for system_time all order by sys_end;
|
2016-11-01 17:51:44 +01:00
|
|
|
delete from child;
|
|
|
|
|
|
|
|
insert into parent values(1);
|
|
|
|
insert into child values(1);
|
2018-01-12 22:19:16 +01:00
|
|
|
update parent set id= id + 1;
|
2016-11-01 17:51:44 +01:00
|
|
|
select * from child;
|
2018-01-12 22:19:16 +01:00
|
|
|
select *, current_row(sys_end) as current_row from child for system_time all order by sys_end;
|
2016-11-01 17:51:44 +01:00
|
|
|
|
|
|
|
drop table child;
|
|
|
|
drop table parent;
|
|
|
|
|
2017-12-18 17:03:51 +01:00
|
|
|
--echo ###########################
|
|
|
|
--echo # Parent table is foreign #
|
|
|
|
--echo ###########################
|
2016-11-01 17:51:44 +01:00
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
2017-12-26 15:16:50 +01:00
|
|
|
eval create or replace table parent(
|
|
|
|
id int unique key,
|
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end)
|
2016-11-01 17:51:44 +01:00
|
|
|
) engine innodb with system versioning;
|
|
|
|
|
|
|
|
create or replace table child(
|
|
|
|
parent_id int,
|
|
|
|
foreign key(parent_id) references parent(id)
|
|
|
|
) engine innodb;
|
|
|
|
|
|
|
|
insert into parent values(1);
|
|
|
|
insert into child values(1);
|
|
|
|
-- error ER_ROW_IS_REFERENCED_2
|
|
|
|
delete from parent;
|
|
|
|
-- error ER_ROW_IS_REFERENCED_2
|
|
|
|
update parent set id=2;
|
|
|
|
|
|
|
|
delete from child;
|
|
|
|
delete from parent;
|
|
|
|
|
|
|
|
-- error ER_NO_REFERENCED_ROW_2
|
|
|
|
insert into child values(1);
|
|
|
|
|
|
|
|
insert into parent values(1);
|
|
|
|
insert into child values(1);
|
|
|
|
-- error ER_ROW_IS_REFERENCED_2
|
|
|
|
delete from parent;
|
|
|
|
-- error ER_ROW_IS_REFERENCED_2
|
|
|
|
update parent set id=2;
|
|
|
|
|
|
|
|
drop table child;
|
|
|
|
drop table parent;
|
2017-12-02 10:54:32 +01:00
|
|
|
|
2017-12-18 17:03:51 +01:00
|
|
|
--echo ###################
|
|
|
|
--echo # crash on DELETE #
|
|
|
|
--echo ###################
|
2017-12-02 10:54:32 +01:00
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
2017-12-26 15:16:50 +01:00
|
|
|
eval create or replace table a (
|
2017-12-02 10:54:32 +01:00
|
|
|
cola int(10) primary key,
|
2017-12-26 15:16:50 +01:00
|
|
|
v_cola int(10) as (cola mod 10) virtual,
|
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end)
|
2017-12-02 10:54:32 +01:00
|
|
|
) engine=innodb with system versioning;
|
|
|
|
|
|
|
|
create index v_cola on a (v_cola);
|
|
|
|
|
2018-01-12 22:19:16 +01:00
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
2017-12-26 15:16:50 +01:00
|
|
|
eval create or replace table b(
|
2017-12-02 10:54:32 +01:00
|
|
|
cola int(10),
|
2017-12-26 15:16:50 +01:00
|
|
|
v_cola int(10),
|
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end)
|
2017-12-02 10:54:32 +01:00
|
|
|
) engine=innodb with system versioning;
|
|
|
|
|
|
|
|
alter table b add constraint `v_cola_fk`
|
|
|
|
foreign key (v_cola) references a (v_cola);
|
|
|
|
|
|
|
|
insert into a(cola) values (12);
|
|
|
|
insert into b(cola, v_cola) values (10,2);
|
|
|
|
--error ER_ROW_IS_REFERENCED_2
|
|
|
|
delete from a;
|
|
|
|
|
|
|
|
drop table b, a;
|
2017-12-26 15:16:50 +01:00
|
|
|
|
2018-03-19 15:25:58 +01:00
|
|
|
--echo ###############################################
|
|
|
|
--echo # CASCADE UPDATE foreign not system versioned #
|
|
|
|
--echo ###############################################
|
|
|
|
create or replace table parent (
|
|
|
|
id smallint unsigned not null auto_increment,
|
|
|
|
value int unsigned not null,
|
|
|
|
primary key (id, value)
|
|
|
|
) engine = innodb;
|
|
|
|
|
|
|
|
--replace_result $sys_datatype_expl SYS_DATATYPE
|
|
|
|
eval create or replace table child (
|
|
|
|
id mediumint unsigned not null auto_increment primary key,
|
|
|
|
parent_id smallint unsigned not null,
|
|
|
|
parent_value int unsigned not null,
|
|
|
|
sys_start $sys_datatype_expl as row start invisible,
|
|
|
|
sys_end $sys_datatype_expl as row end invisible,
|
|
|
|
period for system_time(sys_start, sys_end),
|
|
|
|
constraint `fk_child_parent`
|
|
|
|
foreign key (parent_id, parent_value) references parent (id, value)
|
|
|
|
on delete cascade
|
|
|
|
on update cascade
|
|
|
|
) engine = innodb with system versioning;
|
|
|
|
|
|
|
|
create or replace table subchild (
|
|
|
|
id int not null auto_increment primary key,
|
|
|
|
parent_id smallint unsigned not null,
|
|
|
|
parent_value int unsigned not null,
|
|
|
|
constraint `fk_subchild_child_parent`
|
|
|
|
foreign key (parent_id, parent_value) references child (parent_id, parent_value)
|
|
|
|
on delete cascade
|
|
|
|
on update cascade
|
|
|
|
) engine=innodb;
|
|
|
|
|
|
|
|
insert into parent (value) values (23);
|
|
|
|
select id, value from parent into @id, @value;
|
|
|
|
insert into child values (default, @id, @value);
|
|
|
|
insert into subchild values (default, @id, @value);
|
|
|
|
|
|
|
|
select parent_id from subchild;
|
|
|
|
update parent set id = 11, value = value + 1;
|
|
|
|
select parent_id from subchild;
|
|
|
|
select * from child;
|
|
|
|
|
|
|
|
delete from parent;
|
|
|
|
select count(*) from child;
|
|
|
|
select * from child for system_time all;
|
|
|
|
select count(*) from subchild;
|
|
|
|
|
|
|
|
drop table subchild, child, parent;
|
|
|
|
|
|
|
|
|
2017-12-26 15:16:50 +01:00
|
|
|
--source suite/versioning/common_finish.inc
|