2023-07-13 10:59:39 +02:00
|
|
|
create table t1(f1 int primary key) engine=innodb;
|
2017-12-05 19:13:12 +05:30
|
|
|
# Create statement with FK on base column of stored column
|
2023-07-13 10:59:39 +02:00
|
|
|
create table t2(f1 int not null, f2 int as (f1) stored,
|
|
|
|
foreign key(f1) references t1(f1) on update cascade)engine=innodb;
|
|
|
|
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f2`
|
|
|
|
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;
|
|
|
|
ERROR HY000: Function or expression 'f2' cannot be used in the GENERATED ALWAYS AS clause of `f3`
|
2017-12-05 19:13:12 +05:30
|
|
|
# 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;
|
|
|
|
alter table t2 add column f3 int as (f1) stored, add column f4 int as (f1) virtual;
|
2023-07-13 10:59:39 +02:00
|
|
|
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f3`
|
2018-05-11 15:08:08 +03:00
|
|
|
show create table t2;
|
|
|
|
Table Create Table
|
|
|
|
t2 CREATE TABLE `t2` (
|
|
|
|
`f1` int(11) NOT NULL,
|
|
|
|
`f2` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL,
|
|
|
|
KEY `f1` (`f1`),
|
|
|
|
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE
|
2022-09-02 17:32:14 +04:00
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
2018-05-11 15:08:08 +03:00
|
|
|
drop table t2;
|
2017-12-05 19:13:12 +05:30
|
|
|
# adding foreign key constraint for base columns during alter copy.
|
2018-05-11 15:08:08 +03:00
|
|
|
create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb;
|
2017-12-05 19:13:12 +05:30
|
|
|
alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=copy;
|
2023-07-13 10:59:39 +02:00
|
|
|
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f2`
|
2018-05-11 15:08:08 +03:00
|
|
|
show create table t2;
|
|
|
|
Table Create Table
|
|
|
|
t2 CREATE TABLE `t2` (
|
|
|
|
`f1` int(11) NOT NULL,
|
2023-07-13 10:59:39 +02:00
|
|
|
`f2` int(11) GENERATED ALWAYS AS (`f1`) STORED
|
2022-09-02 17:32:14 +04:00
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
2018-05-11 15:08:08 +03:00
|
|
|
drop table t2;
|
2017-12-05 19:13:12 +05:30
|
|
|
# adding foreign key constraint for base columns during online alter.
|
2018-05-11 15:08:08 +03:00
|
|
|
create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb;
|
2017-12-05 19:13:12 +05:30
|
|
|
set foreign_key_checks = 0;
|
|
|
|
alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=inplace;
|
2023-07-13 10:59:39 +02:00
|
|
|
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f2`
|
2018-05-11 15:08:08 +03:00
|
|
|
drop table t2;
|
2017-12-05 19:13:12 +05:30
|
|
|
# adding stored column via online alter.
|
|
|
|
create table t2(f1 int not null,
|
|
|
|
foreign key(f1) references t1(f1) on update cascade)engine=innodb;
|
|
|
|
alter table t2 add column f2 int as (f1) stored, algorithm=inplace;
|
2023-07-13 10:59:39 +02:00
|
|
|
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f2`
|
2017-12-05 19:13:12 +05:30
|
|
|
drop table t2, t1;
|
|
|
|
#
|
|
|
|
# BUG#26731689 FK ON TABLE WITH GENERATED COLS: ASSERTION POS < N_DEF
|
|
|
|
#
|
|
|
|
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;
|
|
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null;
|
2022-04-03 21:48:15 -05:00
|
|
|
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'c' in the referenced table 't'
|
2017-12-05 19:13:12 +05:30
|
|
|
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;
|
|
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null;
|
2022-04-03 21:48:15 -05:00
|
|
|
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'c' in the referenced table 't'
|
2017-12-05 19:13:12 +05:30
|
|
|
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;
|
|
|
|
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null;
|
2022-04-03 21:48:15 -05:00
|
|
|
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'c' in the referenced table 't'
|
2017-12-05 19:13:12 +05:30
|
|
|
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;
|