1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

Don't automaticly generate a new key for a foreign key constraint if there is already a usable key.

Prefer not automatic keys before automatic keys. If there is two conf


BitKeeper/etc/ignore:
  added *.d
include/my_base.h:
  Added flag for automaticly generated key
mysql-test/r/constraints.result:
  Update tests after bug fix
mysql-test/r/create.result:
  Update tests after bug fix
mysql-test/r/innodb.result:
  Added test of automatic creation of foreign keys
mysql-test/t/innodb.test:
  Added test of automatic creation of foreign keys
mysql-test/t/key_cache.test:
  Portability fixes (64 BIT os)
sql/sql_acl.cc:
  Indentation fixes
sql/sql_class.cc:
  Fix key comparison to handle prefix and optionally key segments in different order.
sql/sql_class.h:
  Added flag for automaticly generated keys
sql/sql_parse.cc:
  Added flag for automaticly generated keys
sql/sql_table.cc:
  Don't automaticly generate a new key for a foreign key constraint if there is already a usable key.
  Prefer not automatic keys before automatic keys. If there is two conflicting automatic keys, prefer the longer one.
sql/sql_yacc.yy:
  Added flag for automaticly generated keys
strings/strings-x86.s:
  Portability fix.
This commit is contained in:
unknown
2004-05-12 00:29:52 +03:00
parent 7b4cbde8ed
commit d3fcd8d4c0
14 changed files with 298 additions and 49 deletions

View File

@@ -84,26 +84,71 @@ bool key_part_spec::operator==(const key_part_spec& other) const
return length == other.length && !strcmp(field_name, other.field_name);
}
/* Equality comparison of keys (ignoring name) */
bool Key::operator==(Key& other)
/*
Test if a foreign key is a prefix of the given key
(ignoring key name, key type and order of columns)
NOTES:
This is only used to test if an index for a FOREIGN KEY exists
IMPLEMENTATION
We only compare field names
RETURN
0 Generated key is a prefix of other key
1 Not equal
*/
bool foreign_key_prefix(Key *a, Key *b)
{
if (type == other.type &&
algorithm == other.algorithm &&
columns.elements == other.columns.elements)
/* Ensure that 'a' is the generated key */
if (a->generated)
{
List_iterator<key_part_spec> col_it1(columns);
List_iterator<key_part_spec> col_it2(other.columns);
const key_part_spec *col1, *col2;
while ((col1 = col_it1++))
{
col2 = col_it2++;
DBUG_ASSERT(col2 != NULL);
if (!(*col1 == *col2))
return false;
}
return true;
if (b->generated && a->columns.elements > b->columns.elements)
swap(Key*, a, b); // Put shorter key in 'a'
}
return false;
else
{
if (!b->generated)
return TRUE; // No foreign key
swap(Key*, a, b); // Put generated key in 'a'
}
/* Test if 'a' is a prefix of 'b' */
if (a->columns.elements > b->columns.elements)
return TRUE; // Can't be prefix
List_iterator<key_part_spec> col_it1(a->columns);
List_iterator<key_part_spec> col_it2(b->columns);
const key_part_spec *col1, *col2;
#ifdef ENABLE_WHEN_INNODB_CAN_HANDLE_SWAPED_FOREIGN_KEY_COLUMNS
while ((col1= col_it1++))
{
bool found= 0;
col_it2.rewind();
while ((col2= col_it2++))
{
if (*col1 == *col2)
{
found= TRUE;
break;
}
}
if (!found)
return TRUE; // Error
}
return FALSE; // Is prefix
#else
while ((col1= col_it1++))
{
col2= col_it2++;
if (!(*col1 == *col2))
return TRUE;
}
return FALSE; // Is prefix
#endif
}