1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-33658 2/2 Cannot add a foreign key on a table with a matching long UNIQUE

Cannot add a foreign key on a table with a long UNIQUE multi-column index, that
contains a foreign key as a prefix.

Check that index algorithms match during the "generated" keys duplicate removal.
This commit is contained in:
Nikita Malyavin
2024-10-13 19:28:51 +02:00
parent ecaedbe299
commit e7cc1a3047
3 changed files with 47 additions and 1 deletions

View File

@@ -204,7 +204,7 @@ Foreign_key::Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root)
/*
Test if a foreign key (= generated key) is a prefix of the given key
(ignoring key name, key type and order of columns)
(ignoring key name and type, but minding the algorithm)
NOTES:
This is only used to test if an index for a FOREIGN KEY exists
@@ -219,6 +219,16 @@ Foreign_key::Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root)
bool is_foreign_key_prefix(Key *a, Key *b)
{
ha_key_alg a_alg= a->key_create_info.algorithm;
ha_key_alg b_alg= b->key_create_info.algorithm;
// The real algorithm in InnoDB will be BTREE if none was given by user.
a_alg= a_alg == HA_KEY_ALG_UNDEF ? HA_KEY_ALG_BTREE : a_alg;
b_alg= b_alg == HA_KEY_ALG_UNDEF ? HA_KEY_ALG_BTREE : b_alg;
if (a_alg != b_alg)
return false;
/* Ensure that 'a' is the generated key */
if (a->generated)
{