| 1 |
create table t1(f1 int primary key) engine=innodb; |
| 2 |
# Create statement with FK on base column of stored column |
| 3 |
create table t2(f1 int not null, f2 int as (f1) stored, |
| 4 |
foreign key(f1) references t1(f1) on update cascade)engine=innodb; |
| 5 |
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f2` |
| 6 |
create table t2(f1 int not null, f2 int as (f1) virtual, f3 int as (f2) stored, |
| 7 |
foreign key(f1) references t1(f1) on update cascade)engine=innodb; |
| 8 |
ERROR HY000: Function or expression 'f2' cannot be used in the GENERATED ALWAYS AS clause of `f3` |
| 9 |
# adding new stored column during alter table copy operation. |
| 10 |
create table t2(f1 int not null, f2 int as (f1) virtual, |
| 11 |
foreign key(f1) references t1(f1) on update cascade)engine=innodb; |
| 12 |
alter table t2 add column f3 int as (f1) stored, add column f4 int as (f1) virtual; |
| 13 |
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f3` |
| 14 |
show create table t2; |
| 15 |
Table Create Table |
| 16 |
t2 CREATE TABLE `t2` ( |
| 17 |
`f1` int(11) NOT NULL, |
| 18 |
`f2` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL, |
| 19 |
KEY `f1` (`f1`), |
| 20 |
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE |
| 21 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 22 |
drop table t2; |
| 23 |
# adding foreign key constraint for base columns during alter copy. |
| 24 |
create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb; |
| 25 |
alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=copy; |
| 26 |
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f2` |
| 27 |
show create table t2; |
| 28 |
Table Create Table |
| 29 |
t2 CREATE TABLE `t2` ( |
| 30 |
`f1` int(11) NOT NULL, |
| 31 |
`f2` int(11) GENERATED ALWAYS AS (`f1`) STORED |
| 32 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 33 |
drop table t2; |
| 34 |
# adding foreign key constraint for base columns during online alter. |
| 35 |
create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb; |
| 36 |
set foreign_key_checks = 0; |
| 37 |
alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=inplace; |
| 38 |
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f2` |
| 39 |
drop table t2; |
| 40 |
# adding stored column via online alter. |
| 41 |
create table t2(f1 int not null, |
| 42 |
foreign key(f1) references t1(f1) on update cascade)engine=innodb; |
| 43 |
alter table t2 add column f2 int as (f1) stored, algorithm=inplace; |
| 44 |
ERROR HY000: Function or expression 'f1' cannot be used in the GENERATED ALWAYS AS clause of `f2` |
| 45 |
drop table t2, t1; |
| 46 |
# |
| 47 |
# BUG#26731689 FK ON TABLE WITH GENERATED COLS: ASSERTION POS < N_DEF |
| 48 |
# |
| 49 |
CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED, c INT, |
| 50 |
d INT GENERATED ALWAYS AS (0) VIRTUAL, e INT) ENGINE=innodb; |
| 51 |
CREATE TABLE t (a INT) ENGINE=innodb; |
| 52 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null; |
| 53 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'c' in the referenced table 't' |
| 54 |
ALTER TABLE t ADD PRIMARY KEY(a); |
| 55 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null; |
| 56 |
DROP TABLE s,t; |
| 57 |
CREATE TABLE s (a INT GENERATED ALWAYS AS (0) VIRTUAL, |
| 58 |
b INT GENERATED ALWAYS AS (0) STORED, c INT) ENGINE=innodb; |
| 59 |
CREATE TABLE t (a INT) ENGINE=innodb; |
| 60 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null; |
| 61 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'c' in the referenced table 't' |
| 62 |
ALTER TABLE t ADD PRIMARY KEY(a); |
| 63 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null; |
| 64 |
DROP TABLE s,t; |
| 65 |
CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED) ENGINE=innodb; |
| 66 |
CREATE TABLE t (a INT PRIMARY KEY) ENGINE=innodb; |
| 67 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null; |
| 68 |
DROP TABLE s,t; |
| 69 |
CREATE TABLE s (a INT, b INT) ENGINE=innodb; |
| 70 |
CREATE TABLE t (a INT) ENGINE=innodb; |
| 71 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null; |
| 72 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'c' in the referenced table 't' |
| 73 |
ALTER TABLE t ADD PRIMARY KEY(a); |
| 74 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null; |
| 75 |
DROP TABLE s,t; |