diff options
author | Aleksey Midenkov <midenok@gmail.com> | 2022-01-12 17:18:38 +0300 |
---|---|---|
committer | Aleksey Midenkov <midenok@gmail.com> | 2022-01-12 17:18:38 +0300 |
commit | 6831b3f2a0fd656fb41dd9df5f141431988448f1 (patch) | |
tree | 209b0a23a95cdcc3d600d01bcec5db0e558fd484 /mysql-test | |
parent | 017d1b867b12ff36b3b871c3d57719907a905659 (diff) | |
download | mariadb-git-6831b3f2a0fd656fb41dd9df5f141431988448f1.tar.gz |
MDEV-26824 Can't add foreign key with empty referenced columns list
create_table_info_t::create_foreign_keys() expects equal number of
iterations through fk->columns and fk->ref_columns. If fk->ref_columns
is empty copy it from fk->columns.
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/suite/innodb/r/foreign_key.result | 23 | ||||
-rw-r--r-- | mysql-test/suite/innodb/t/foreign_key.test | 18 |
2 files changed, 41 insertions, 0 deletions
diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index ff0e025246e..1968661b45a 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -896,4 +896,27 @@ create or replace table t1 (a varchar(4096) unique) engine=innodb; create or replace table t2 (pk int primary key, a varchar(4096) unique, foreign key(a) references t1(a) on update cascade) engine=innodb; ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") drop table t1; +# +# MDEV-26824 Can't add foreign key with empty referenced columns list +# +create table t2(a int primary key) engine=innodb; +create table t1(a int primary key, b int) engine=innodb; +alter table t2 add foreign key(a) references t1(a, b); +ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match +create or replace table t1(a tinyint primary key) engine innodb; +alter table t2 add foreign key(a) references t1; +ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") +create or replace table t1(b int primary key) engine innodb; +alter table t2 add foreign key(a) references t1; +ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") +create or replace table t1(a int primary key, b int) engine innodb; +alter table t2 add foreign key(a) references t1; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) NOT NULL, + PRIMARY KEY (`a`), + CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +drop tables t2, t1; # End of 10.5 tests diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index be248a5bed4..1f25d995827 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -902,6 +902,24 @@ create or replace table t2 (pk int primary key, a varchar(4096) unique, foreign drop table t1; +--echo # +--echo # MDEV-26824 Can't add foreign key with empty referenced columns list +--echo # +create table t2(a int primary key) engine=innodb; +create table t1(a int primary key, b int) engine=innodb; +--error ER_WRONG_FK_DEF +alter table t2 add foreign key(a) references t1(a, b); +create or replace table t1(a tinyint primary key) engine innodb; +--error ER_CANT_CREATE_TABLE +alter table t2 add foreign key(a) references t1; +create or replace table t1(b int primary key) engine innodb; +--error ER_CANT_CREATE_TABLE +alter table t2 add foreign key(a) references t1; +create or replace table t1(a int primary key, b int) engine innodb; +alter table t2 add foreign key(a) references t1; +show create table t2; +drop tables t2, t1; + --echo # End of 10.5 tests --source include/wait_until_count_sessions.inc |