| 1 |
|
| 2 |
--echo # Create statement with FK on base column of stored column |
| 3 |
create table t1(f1 int primary key); |
| 4 |
--error ER_CANNOT_ADD_FOREIGN |
| 5 |
create table t2(f1 int, f2 int as(f1) stored, |
| 6 |
foreign key(f1) references t1(f1) on delete cascade)engine=innodb; |
| 7 |
|
| 8 |
--echo # adding new stored column during alter table copy operation. |
| 9 |
create table t2(f1 int not null, f2 int as (f1) virtual, |
| 10 |
foreign key(f1) references t1(f1) on update cascade)engine=innodb; |
| 11 |
|
| 12 |
--replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/ |
| 13 |
--error ER_CANNOT_ADD_FOREIGN |
| 14 |
alter table t2 add column f3 int as (f1) stored, add column f4 int as (f1) virtual; |
| 15 |
drop table t2, t1; |
| 16 |
|
| 17 |
--echo # adding foreign key constraint for base columns during alter copy. |
| 18 |
create table t1(f1 int primary key); |
| 19 |
create table t2(f1 int not null, f2 int as (f1) stored); |
| 20 |
--error ER_CANNOT_ADD_FOREIGN |
| 21 |
alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=copy; |
| 22 |
drop table t2, t1; |
| 23 |
|
| 24 |
--echo # adding foreign key constraint for base columns during online alter. |
| 25 |
create table t1(f1 int primary key); |
| 26 |
create table t2(f1 int not null, f2 int as (f1) stored); |
| 27 |
set foreign_key_checks = 0; |
| 28 |
--error ER_CANNOT_ADD_FOREIGN_BASE_COL_STORED |
| 29 |
alter table t2 add foreign key(f1) references t1(f1) on update cascade, algorithm=inplace; |
| 30 |
drop table t2, t1; |
| 31 |
|
| 32 |
--echo # adding stored column via online alter. |
| 33 |
create table t1(f1 int primary key); |
| 34 |
create table t2(f1 int not null, |
| 35 |
foreign key(f1) references t1(f1) on update cascade)engine=innodb; |
| 36 |
--error ER_ALTER_OPERATION_NOT_SUPPORTED |
| 37 |
alter table t2 add column f2 int as (f1) stored, algorithm=inplace; |
| 38 |
drop table t2, t1; |
| 39 |
set foreign_key_checks = 1; |
| 40 |
|
| 41 |
--echo # |
| 42 |
--echo # BUG#26731689 FK ON TABLE WITH GENERATED COLS: ASSERTION POS < N_DEF |
| 43 |
--echo # |
| 44 |
|
| 45 |
SET @foreign_key_checks_saved = @@foreign_key_checks; |
| 46 |
SET foreign_key_checks=0; |
| 47 |
|
| 48 |
--disable_warnings |
| 49 |
DROP TABLE IF EXISTS s,t; |
| 50 |
--enable_warnings |
| 51 |
|
| 52 |
CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED, c INT, |
| 53 |
d INT GENERATED ALWAYS AS (0) VIRTUAL, e INT) ENGINE=innodb; |
| 54 |
|
| 55 |
CREATE TABLE t (a INT) ENGINE=innodb; |
| 56 |
|
| 57 |
# This would fail. No corresponding index |
| 58 |
--error ER_FK_NO_INDEX_PARENT |
| 59 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null; |
| 60 |
|
| 61 |
ALTER TABLE t ADD PRIMARY KEY(a); |
| 62 |
|
| 63 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (e) REFERENCES t(a) ON UPDATE SET null; |
| 64 |
|
| 65 |
DROP TABLE s,t; |
| 66 |
|
| 67 |
CREATE TABLE s (a INT GENERATED ALWAYS AS (0) VIRTUAL, |
| 68 |
b INT GENERATED ALWAYS AS (0) STORED, c INT) ENGINE=innodb; |
| 69 |
|
| 70 |
CREATE TABLE t (a INT) ENGINE=innodb; |
| 71 |
|
| 72 |
# This would fail. No corresponding index |
| 73 |
--error ER_FK_NO_INDEX_PARENT |
| 74 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null; |
| 75 |
|
| 76 |
ALTER TABLE t ADD PRIMARY KEY(a); |
| 77 |
|
| 78 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (c) REFERENCES t(a) ON UPDATE SET null; |
| 79 |
|
| 80 |
DROP TABLE s,t; |
| 81 |
|
| 82 |
CREATE TABLE s (a INT, b INT GENERATED ALWAYS AS (0) STORED) ENGINE=innodb; |
| 83 |
|
| 84 |
CREATE TABLE t (a INT PRIMARY KEY) ENGINE=innodb; |
| 85 |
|
| 86 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null; |
| 87 |
|
| 88 |
DROP TABLE s,t; |
| 89 |
|
| 90 |
CREATE TABLE s (a INT, b INT) ENGINE=innodb; |
| 91 |
|
| 92 |
CREATE TABLE t (a INT) ENGINE=innodb; |
| 93 |
|
| 94 |
# This would fail. No corresponding index |
| 95 |
--error ER_FK_NO_INDEX_PARENT |
| 96 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null; |
| 97 |
|
| 98 |
ALTER TABLE t ADD PRIMARY KEY(a); |
| 99 |
|
| 100 |
ALTER TABLE s ADD CONSTRAINT c FOREIGN KEY (a) REFERENCES t(a) ON UPDATE SET null; |
| 101 |
|
| 102 |
DROP TABLE s,t; |
| 103 |
|
| 104 |
SET @@foreign_key_checks = @foreign_key_checks_saved; |