mirror of
https://github.com/MariaDB/server.git
synced 2025-02-05 13:22:17 +01:00
da09ae05a9
* invoke check_expression() for all vcol_info's in mysql_prepare_create_table() to check for FK CASCADE * also check for SET NULL and SET DEFAULT * to check against existing FKs when a vcol is added in ALTER TABLE, old FKs must be added to the new_key_list just like other indexes are * check columns recursively, if vcol1 references vcol2, flags of vcol2 must be taken into account * remove check_table_name_processor(), put that logic under check_vcol_func_processor() to avoid walking the tree twice
98 lines
3.4 KiB
Text
98 lines
3.4 KiB
Text
--source include/have_innodb.inc
|
|
|
|
create table t1(f1 int primary key) engine=innodb;
|
|
|
|
--echo # Create statement with FK on base column of stored column
|
|
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
|
create table t2(f1 int not null, f2 int as (f1) stored,
|
|
foreign key(f1) references t1(f1) on update cascade)engine=innodb;
|
|
|
|
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
|
create table t2(f1 int not null, f2 int as (f1) virtual, f3 int as (f2) stored,
|
|
foreign key(f1) references t1(f1) on update cascade)engine=innodb;
|
|
|
|
--echo # adding new stored column during alter table copy operation.
|
|
create table t2(f1 int not null, f2 int as (f1) virtual,
|
|
foreign key(f1) references t1(f1) on update cascade)engine=innodb;
|
|
|
|
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
|
alter table t2 add column f3 int as (f1) stored, add column f4 int as (f1) virtual;
|
|
show create table t2;
|
|
drop table t2;
|
|
|
|
--echo # adding foreign key constraint for base columns during alter copy.
|
|
create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb;
|
|
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
|
alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=copy;
|
|
show create table t2;
|
|
drop table t2;
|
|
|
|
--echo # adding foreign key constraint for base columns during online alter.
|
|
create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb;
|
|
set foreign_key_checks = 0;
|
|
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
|
alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=inplace;
|
|
drop table t2;
|
|
|
|
--echo # adding stored column via online alter.
|
|
create table t2(f1 int not null,
|
|
foreign key(f1) references t1(f1) on update cascade)engine=innodb;
|
|
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
|
alter table t2 add column f2 int as (f1) stored, algorithm=inplace;
|
|
drop table t2, t1;
|
|
|
|
--echo #
|
|
--echo # BUG#26731689 FK ON TABLE WITH GENERATED COLS: ASSERTION POS < N_DEF
|
|
--echo #
|
|
|
|
CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED, c INT,
|
|
d INT GENERATED ALWAYS AS (0) VIRTUAL, e INT) ENGINE=innodb;
|
|
|
|
CREATE TABLE t (a INT) ENGINE=innodb;
|
|
|
|
# This would fail. No corresponding index
|
|
--error ER_FK_NO_INDEX_PARENT
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null;
|
|
|
|
ALTER TABLE t ADD PRIMARY KEY(a);
|
|
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null;
|
|
|
|
DROP TABLE s,t;
|
|
|
|
CREATE TABLE s (a INT GENERATED ALWAYS AS (0) VIRTUAL,
|
|
b INT GENERATED ALWAYS AS (0) STORED, c INT) ENGINE=innodb;
|
|
|
|
CREATE TABLE t (a INT) ENGINE=innodb;
|
|
|
|
# This would fail. No corresponding index
|
|
--error ER_FK_NO_INDEX_PARENT
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null;
|
|
|
|
ALTER TABLE t ADD PRIMARY KEY(a);
|
|
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null;
|
|
|
|
DROP TABLE s,t;
|
|
|
|
CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED) ENGINE=innodb;
|
|
|
|
CREATE TABLE t (a INT PRIMARY KEY) ENGINE=innodb;
|
|
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null;
|
|
|
|
DROP TABLE s,t;
|
|
|
|
CREATE TABLE s (a INT, b INT) ENGINE=innodb;
|
|
|
|
CREATE TABLE t (a INT) ENGINE=innodb;
|
|
|
|
# This would fail. No corresponding index
|
|
--error ER_FK_NO_INDEX_PARENT
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null;
|
|
|
|
ALTER TABLE t ADD PRIMARY KEY(a);
|
|
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null;
|
|
|
|
DROP TABLE s,t;
|