1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-30 05:23:50 +03:00
Files
mariadb/mysql-test/suite/versioning/t/foreign.test
Aleksey Midenkov b55a149194 Timestamp-based versioning for InnoDB [closes #209]
* Removed integer_fields check
* Reworked Vers_parse_info::check_sys_fields()
* Misc renames
* versioned as vers_sys_type_t

* Removed versioned_by_sql(), versioned_by_engine()

versioned() works as before;
versioned(VERS_TIMESTAMP) is versioned_by_sql();
versioned(VERS_TRX_ID) is versioned_by_engine().

* create_tmp_table() fix
* Foreign constraints for timestamp-based
* Range auto-specifier fix
* SQL: 1-row partition rotation fix [fixes #260]
* Fix 'drop system versioning, algorithm=inplace'
2017-12-18 19:03:51 +03:00

249 lines
5.6 KiB
Plaintext

-- source include/have_innodb.inc
--echo #################
--echo # Test RESTRICT #
--echo #################
create table parent(
id int unique key
) engine innodb;
create table child(
parent_id int,
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;
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
drop table child;
drop table parent;
--echo ##############################################
--echo # Test when clustered index is a foreign key #
--echo ##############################################
create table parent(
id int(10) unsigned unique key
) engine innodb;
create table child(
parent_id int(10) unsigned primary key,
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;
--echo ################
--echo # Test CASCADE #
--echo ################
create table parent(
id int unique key
) engine innodb;
create table child(
parent_id int,
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);
--echo ## FIXME: #415 update of foreign constraints is disabled
call mtr.add_suppression("foreign key constraints in timestamp-based temporal table");
--error ER_UNSUPPORTED_EXTENSION
delete from parent where id = 1;
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 all;
insert into parent values(1);
insert into child values(1);
update parent set id = id + 1;
select * from child;
select * from child for system_time all;
drop table child;
drop table parent;
create or replace table parent (
id int primary key
) 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;
insert into parent (id) values (2);
insert into child (x, parent_id) values (2, 2);
delete from parent;
select * from child;
drop table child;
drop table parent;
create or replace table parent (
id int primary key
)
engine innodb;
create or replace table child (
id int primary key,
parent_id int not null,
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);
--echo ## FIXME: #415 update of foreign constraints is disabled
delete from child;
--echo ## FIXME END
delete from parent;
select * from child;
select * from child for system_time all;
drop table child;
drop table parent;
--echo #################
--echo # Test SET NULL #
--echo #################
create table parent(
id int unique key
) engine innodb;
create table child(
parent_id int,
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);
--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 '1-1-1' to timestamp now(6);
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;
select * from child;
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
}
## FIXME END
drop table child;
drop table parent;
--echo ###########################
--echo # Parent table is foreign #
--echo ###########################
create or replace table parent(
id int unique key
) 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;
--echo ###################
--echo # crash on DELETE #
--echo ###################
create or replace table a (
cola int(10) primary key,
v_cola int(10) as (cola mod 10) virtual
) 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)
) 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;