diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:00:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:00:34 +0000 |
commit | 3f619478f796eddbba6e39502fe941b285dd97b1 (patch) | |
tree | e2c7b5777f728320e5b5542b6213fd3591ba51e2 /mysql-test/suite/vcol/t/innodb_virtual_fk.test | |
parent | Initial commit. (diff) | |
download | mariadb-upstream.tar.xz mariadb-upstream.zip |
Adding upstream version 1:10.11.6.upstream/1%10.11.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mysql-test/suite/vcol/t/innodb_virtual_fk.test')
-rw-r--r-- | mysql-test/suite/vcol/t/innodb_virtual_fk.test | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/mysql-test/suite/vcol/t/innodb_virtual_fk.test b/mysql-test/suite/vcol/t/innodb_virtual_fk.test new file mode 100644 index 00000000..cab43914 --- /dev/null +++ b/mysql-test/suite/vcol/t/innodb_virtual_fk.test @@ -0,0 +1,115 @@ +source include/have_innodb.inc; +set default_storage_engine=innodb; + +# +# MDEV-13708 Crash with indexed virtual columns and FK cascading deletes +# + +create table t1 (id int primary key, id2 int as (id) virtual, key id2 (id2)); +create table t2 (id int key, constraint fk_id foreign key (id) references t1 (id) on delete cascade); +insert into t1 (id) values (1), (2); +insert into t2 (id) values (1), (2); +delete from t1; +select * from t1; +select * from t2; +drop table t2; +drop table t1; + +--echo # +--echo # End of 10.2 tests +--echo # + +--echo # +--echo # MDEV-18114 Foreign Key Constraint actions don't affect Virtual Column +--echo # +create table t1 (id int primary key); + +# note that RESTRICT, NO ACTION, and DELETE CASCADE are fine +# because they don't change values of referenced columns + +# virtual indexed +create or replace table t2 (id int, id2 int as (id) virtual, key(id2), foreign key (id) references t1 (id) on update restrict); +create or replace table t2 (id int, id2 int as (id) virtual, key(id2), foreign key (id) references t1 (id) on update no action); +create or replace table t2 (id int, id2 int as (id) virtual, key(id2), foreign key (id) references t1 (id) on delete cascade); +create or replace table t2 (id int, id2 int as (id) virtual, key(id2), foreign key (id) references t1 (id) on update cascade); +create or replace table t2 (id int, id2 int as (id) virtual, key(id2), foreign key (id) references t1 (id) on delete set null); +create or replace table t2 (id int, id2 int as (id) virtual, key(id2), foreign key (id) references t1 (id) on update set null); + +# stored +create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on update restrict); +create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on update no action); +create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on delete cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on update cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on delete set null); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on update set null); + +# stored indirect +create or replace table t2 (id int, id2 int as (id) virtual, id3 int as (id2) stored, foreign key (id) references t1 (id) on update restrict); +create or replace table t2 (id int, id2 int as (id) virtual, id3 int as (id2) stored, foreign key (id) references t1 (id) on update no action); +create or replace table t2 (id int, id2 int as (id) virtual, id3 int as (id2) stored, foreign key (id) references t1 (id) on delete cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) virtual, id3 int as (id2) stored, foreign key (id) references t1 (id) on update cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) virtual, id3 int as (id2) stored, foreign key (id) references t1 (id) on delete set null); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) virtual, id3 int as (id2) stored, foreign key (id) references t1 (id) on update set null); + +# default +create or replace table t2 (id int, id2 int default (id), foreign key (id) references t1 (id) on update restrict); +create or replace table t2 (id int, id2 int default (id), foreign key (id) references t1 (id) on update no action); +create or replace table t2 (id int, id2 int default (id), foreign key (id) references t1 (id) on delete cascade); +create or replace table t2 (id int, id2 int default (id), foreign key (id) references t1 (id) on update cascade); +create or replace table t2 (id int, id2 int default (id), foreign key (id) references t1 (id) on delete set null); +create or replace table t2 (id int, id2 int default (id), foreign key (id) references t1 (id) on update set null); + +# field check +create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on update restrict); +create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on update no action); +create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on delete cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on update cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on delete set null); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on update set null); + +# table check +create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on update restrict); +create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on update no action); +create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on delete cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on update cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on delete set null); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on update set null); + +# table check indirect +create or replace table t2 (id int, id2 int as (id) virtual, check (id2), foreign key (id) references t1 (id) on update restrict); +create or replace table t2 (id int, id2 int as (id) virtual, check (id2), foreign key (id) references t1 (id) on update no action); +create or replace table t2 (id int, id2 int as (id) virtual, check (id2), foreign key (id) references t1 (id) on delete cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) virtual, check (id2), foreign key (id) references t1 (id) on update cascade); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) virtual, check (id2), foreign key (id) references t1 (id) on delete set null); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t2 (id int, id2 int as (id) virtual, check (id2), foreign key (id) references t1 (id) on update set null); + +drop table if exists t2, t1; + +--echo # +--echo # MDEV-31853 Assertion failure in Column_definition::check_vcol_for_key upon adding FK +--echo # +create table t (a int, b int, c int generated always as (a), key(b), key(c)); +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +alter table t add foreign key (a) references t (b) on update set null, algorithm=nocopy; +alter table t add foreign key (a) references t (b); +show create table t; +drop table t; + +--echo # +--echo # End of 10.5 tests +--echo # |