Commit 6f0946d6 authored by unknown's avatar unknown

sql_table.cc:

  Fix bug #3749: if there were several indexs that made an automatically generated FOREIGN KEY index redundant, then MySQL miscalculated the number of keys, and the AUTO_INCREMENT flag was forgotten by MySQL from a PRIMARY KEY. There were probably a multitude of other errors caused by this.


sql/sql_table.cc:
  Fix bug #3749: if there were several indexs that made an automatically generated FOREIGN KEY index redundant, then MySQL miscalculated the number of keys, and the AUTO_INCREMENT flag was forgotten by MySQL from a PRIMARY KEY. There were probably a multitude of other errors caused by this.
parent 65755a9c
...@@ -683,6 +683,11 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, ...@@ -683,6 +683,11 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
{ {
while ((key2 = key_iterator2++) != key) while ((key2 = key_iterator2++) != key)
{ {
/*
foreign_key_prefix(key, key2) returns 0 if key or key2, or both, is
'generated', and a generated key is a prefix of the other key. Then we
do not need the generated shorter key.
*/
if ((key2->type != Key::FOREIGN_KEY && !foreign_key_prefix(key, key2))) if ((key2->type != Key::FOREIGN_KEY && !foreign_key_prefix(key, key2)))
{ {
/* TO DO: issue warning message */ /* TO DO: issue warning message */
...@@ -693,10 +698,17 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, ...@@ -693,10 +698,17 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
key->name= ignore_key; key->name= ignore_key;
else else
{ {
/* Remove the previous, generated key */ /*
key2->name= ignore_key; Remove the previous, generated key if it has not yet been
key_parts-= key2->columns.elements; removed. Note that if we have several identical generated keys,
(*key_count)--; the last one will remain and others get removed here.
*/
if (key2->name != ignore_key)
{
key2->name= ignore_key;
key_parts-= key2->columns.elements;
(*key_count)--;
}
} }
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment