diff options
author | unknown <heikki@hundin.mysql.fi> | 2004-05-14 09:02:06 +0300 |
---|---|---|
committer | unknown <heikki@hundin.mysql.fi> | 2004-05-14 09:02:06 +0300 |
commit | 6f0946d6dd0568c36d33f34e548b5ac8e26842ad (patch) | |
tree | e291e867ede60b57f77e555a37043a628b54e503 /sql | |
parent | 65755a9cb70b4247cf0fc0d2a3c57ac020e95e5b (diff) | |
download | mariadb-git-6f0946d6dd0568c36d33f34e548b5ac8e26842ad.tar.gz |
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.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_table.cc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index b90ff942cc6..47574eab666 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -683,6 +683,11 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, { 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))) { /* TO DO: issue warning message */ @@ -693,10 +698,17 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, key->name= ignore_key; else { - /* Remove the previous, generated key */ - key2->name= ignore_key; - key_parts-= key2->columns.elements; - (*key_count)--; + /* + Remove the previous, generated key if it has not yet been + removed. Note that if we have several identical generated keys, + 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; } |