|
1 | 1 | # Create statement with FK on base column of stored column
|
2 | 2 | create table t1(f1 int, f2 int as(f1) stored,
|
3 | 3 | foreign key(f1) references t2(f1) on delete cascade)engine=innodb;
|
4 |
| -ERROR HY000: Cannot add foreign key constraint |
| 4 | +ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") |
5 | 5 | # adding new stored column during alter table copy operation.
|
6 |
| -create table t1(f1 int primary key); |
| 6 | +create table t1(f1 int primary key) engine=innodb; |
7 | 7 | create table t2(f1 int not null, f2 int as (f1) virtual,
|
8 | 8 | foreign key(f1) references t1(f1) on update cascade)engine=innodb;
|
9 | 9 | alter table t2 add column f3 int as (f1) stored, add column f4 int as (f1) virtual;
|
10 |
| -ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 150 - Foreign key constraint is incorrectly formed) |
11 |
| -drop table t2, t1; |
| 10 | +show create table t2; |
| 11 | +Table Create Table |
| 12 | +t2 CREATE TABLE `t2` ( |
| 13 | + `f1` int(11) NOT NULL, |
| 14 | + `f2` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL, |
| 15 | + `f3` int(11) GENERATED ALWAYS AS (`f1`) STORED, |
| 16 | + `f4` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL, |
| 17 | + KEY `f1` (`f1`), |
| 18 | + CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE |
| 19 | +) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
| 20 | +drop table t2; |
12 | 21 | # adding foreign key constraint for base columns during alter copy.
|
13 |
| -create table t1(f1 int primary key); |
14 |
| -create table t2(f1 int not null, f2 int as (f1) stored); |
| 22 | +create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb; |
15 | 23 | alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=copy;
|
16 |
| -ERROR HY000: Cannot add foreign key constraint |
17 |
| -drop table t2, t1; |
| 24 | +show create table t2; |
| 25 | +Table Create Table |
| 26 | +t2 CREATE TABLE `t2` ( |
| 27 | + `f1` int(11) NOT NULL, |
| 28 | + `f2` int(11) GENERATED ALWAYS AS (`f1`) STORED, |
| 29 | + KEY `f1` (`f1`), |
| 30 | + CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE |
| 31 | +) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
| 32 | +drop table t2; |
18 | 33 | # adding foreign key constraint for base columns during online alter.
|
19 |
| -create table t1(f1 int primary key); |
20 |
| -create table t2(f1 int not null, f2 int as (f1) stored); |
| 34 | +create table t2(f1 int not null, f2 int as (f1) stored) engine=innodb; |
21 | 35 | set foreign_key_checks = 0;
|
22 | 36 | alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=inplace;
|
23 |
| -ERROR HY000: Cannot add foreign key on the base column of stored column. |
24 |
| -drop table t2, t1; |
| 37 | +ERROR 0A000: Cannot add foreign key on the base column of stored column |
| 38 | +drop table t2; |
25 | 39 | # adding stored column via online alter.
|
26 |
| -create table t1(f1 int primary key); |
27 | 40 | create table t2(f1 int not null,
|
28 | 41 | foreign key(f1) references t1(f1) on update cascade)engine=innodb;
|
29 | 42 | alter table t2 add column f2 int as (f1) stored, algorithm=inplace;
|
30 |
| -ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. |
| 43 | +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY |
31 | 44 | drop table t2, t1;
|
32 |
| -set foreign_key_checks = 1; |
33 | 45 | #
|
34 | 46 | # BUG#26731689 FK ON TABLE WITH GENERATED COLS: ASSERTION POS < N_DEF
|
35 | 47 | #
|
36 |
| -SET @foreign_key_checks_saved = @@foreign_key_checks; |
37 |
| -SET foreign_key_checks=0; |
38 |
| -DROP TABLE IF EXISTS s,t; |
39 | 48 | CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED, c INT,
|
40 | 49 | d INT GENERATED ALWAYS AS (0) VIRTUAL, e INT) ENGINE=innodb;
|
41 | 50 | CREATE TABLE t (a INT) ENGINE=innodb;
|
@@ -63,4 +72,3 @@ ERROR HY000: Failed to add the foreign key constaint. Missing index for constrai
|
63 | 72 | ALTER TABLE t ADD PRIMARY KEY(a);
|
64 | 73 | ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null;
|
65 | 74 | DROP TABLE s,t;
|
66 |
| -SET @@foreign_key_checks = @foreign_key_checks_saved; |
|
0 commit comments