mariadb/mysql-test/suite/vcol/r/innodb_virtual_fk.result
Marko Mäkelä cffbb17480 MDEV-28933: Per-table unique FOREIGN KEY constraint names
Before MySQL 4.0.18, user-specified constraint names were ignored.
Starting with MySQL 4.0.18, the specified constraint name was
prepended with the schema name and '/'.  Now we are transforming
into a format where the constraint name is prepended with the
dict_table_t::name and the impossible UTF-8 sequence 0xff.
Generated constraint names will be ASCII decimal numbers.

On upgrade, old FOREIGN KEY constraint names will be displayed
without any schema name prefix. They will be updated to the new
format on DDL operations.

dict_foreign_t::sql_id(): Return the SQL constraint name
without any schemaname/tablename\377 or schemaname/ prefix.

row_rename_table_for_mysql(), dict_table_rename_in_cache():
Simplify the logic: Just rename constraints to the new format.

dict_table_get_foreign_id(): Replaces dict_table_get_highest_foreign_id().

innobase_get_foreign_key_info(): Let my_error() refer to erroneous
anonymous constraints as "(null)".

row_delete_constraint(): Try to drop all 3 constraint name variants.

Reviewed by: Thirunarayanan Balathandayuthapani
Tested by: Matthias Leich
2025-07-08 12:30:27 +03:00

101 lines
7.8 KiB
Text

set default_storage_engine=innodb;
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;
id id2
select * from t2;
id
drop table t2;
drop table t1;
#
# End of 10.2 tests
#
#
# MDEV-18114 Foreign Key Constraint actions don't affect Virtual Column
#
create table t1 (id int primary key);
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);
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);
create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on update cascade);
ERROR HY000: Function or expression 'id' cannot be used in the GENERATED ALWAYS AS clause of `id2`
create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on delete set null);
ERROR HY000: Function or expression 'id' cannot be used in the GENERATED ALWAYS AS clause of `id2`
create or replace table t2 (id int, id2 int as (id) stored, foreign key (id) references t1 (id) on update set null);
ERROR HY000: Function or expression 'id' cannot be used in the GENERATED ALWAYS AS clause of `id2`
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);
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 HY000: Function or expression 'id2' cannot be used in the GENERATED ALWAYS AS clause of `id3`
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 HY000: Function or expression 'id2' cannot be used in the GENERATED ALWAYS AS clause of `id3`
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);
ERROR HY000: Function or expression 'id2' cannot be used in the GENERATED ALWAYS AS clause of `id3`
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);
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);
create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on update cascade);
ERROR HY000: Function or expression 'id' cannot be used in the CHECK clause of `id2`
create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on delete set null);
ERROR HY000: Function or expression 'id' cannot be used in the CHECK clause of `id2`
create or replace table t2 (id int, id2 int check (id), foreign key (id) references t1 (id) on update set null);
ERROR HY000: Function or expression 'id' cannot be used in the CHECK clause of `id2`
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);
create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on update cascade);
ERROR HY000: Function or expression 'id' cannot be used in the CHECK clause of `CONSTRAINT_1`
create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on delete set null);
ERROR HY000: Function or expression 'id' cannot be used in the CHECK clause of `CONSTRAINT_1`
create or replace table t2 (id int, id2 int, check (id), foreign key (id) references t1 (id) on update set null);
ERROR HY000: Function or expression 'id' cannot be used in the CHECK clause of `CONSTRAINT_1`
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);
create or replace table t2 (id int, id2 int as (id) virtual, check (id2), foreign key (id) references t1 (id) on update cascade);
ERROR HY000: Function or expression 'id2' cannot be used in the CHECK clause of `CONSTRAINT_1`
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 HY000: Function or expression 'id2' cannot be used in the CHECK clause of `CONSTRAINT_1`
create or replace table t2 (id int, id2 int as (id) virtual, check (id2), foreign key (id) references t1 (id) on update set null);
ERROR HY000: Function or expression 'id2' cannot be used in the CHECK clause of `CONSTRAINT_1`
drop table if exists t2, t1;
Warnings:
Note 1051 Unknown table 'test.t2'
#
# MDEV-31853 Assertion failure in Column_definition::check_vcol_for_key upon adding FK
#
create table t (a int, b int, c int generated always as (a), key(b), key(c));
alter table t add foreign key (a) references t (b) on update set null, algorithm=nocopy;
ERROR 0A000: ALGORITHM=NOCOPY is not supported. Reason: Adding foreign keys needs foreign_key_checks=OFF. Try ALGORITHM=COPY
alter table t add foreign key (a) references t (b);
show create table t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL,
KEY `b` (`b`),
KEY `c` (`c`),
KEY `a` (`a`),
CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t;
#
# End of 10.5 tests
#