1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

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.
This commit is contained in:
Aleksey Midenkov
2022-01-12 17:18:38 +03:00
parent 017d1b867b
commit 6831b3f2a0
3 changed files with 52 additions and 7 deletions

View File

@ -3809,15 +3809,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
Foreign_key *fk_key= (Foreign_key*) key;
if (fk_key->validate(alter_info->create_list))
DBUG_RETURN(TRUE);
if (fk_key->ref_columns.elements &&
fk_key->ref_columns.elements != fk_key->columns.elements)
if (fk_key->ref_columns.elements)
{
my_error(ER_WRONG_FK_DEF, MYF(0),
(fk_key->name.str ? fk_key->name.str :
"foreign key without name"),
ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
DBUG_RETURN(TRUE);
if (fk_key->ref_columns.elements != fk_key->columns.elements)
{
my_error(ER_WRONG_FK_DEF, MYF(0),
(fk_key->name.str ? fk_key->name.str :
"foreign key without name"),
ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
DBUG_RETURN(TRUE);
}
}
else
fk_key->ref_columns.append(&fk_key->columns);
continue;
}
(*key_count)++;