diff options
author | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2019-01-24 13:52:51 +0530 |
---|---|---|
committer | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2019-01-24 13:52:51 +0530 |
commit | a0f3b9f94f3094ccb9ce75c53b25d36c4c78e922 (patch) | |
tree | 78554281d9e2b560cddf6b3835e7659e6858f102 /sql/sql_table.cc | |
parent | cce2b45c8f5b3245d2e63d2763aeec59153d2c6f (diff) | |
download | mariadb-git-a0f3b9f94f3094ccb9ce75c53b25d36c4c78e922.tar.gz |
MDEV-17376 Server fails to set ADD_PK_INDEX, DROP_PK_INDEX if unique index nominated as PK
Problem:
========
Server fails to notify the engine by not setting the ADD_PK_INDEX and
DROP_PK_INDEX When there is a
i) Change in candidate for primary key.
ii) New candidate for primary key.
Fix:
====
Server sets the ADD_PK_INDEX and DROP_PK_INDEX while doing alter for the
above problematic case.
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r-- | sql/sql_table.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 2302026b18b..df1ff8eaf5d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6439,6 +6439,12 @@ static bool fill_alter_inplace_info(THD *thd, KEY *new_key; KEY *new_key_end= ha_alter_info->key_info_buffer + ha_alter_info->key_count; + /* + Primary key index for the new table + */ + const KEY* const new_pk= (ha_alter_info->key_count > 0 && + is_candidate_key(ha_alter_info->key_info_buffer)) ? + ha_alter_info->key_info_buffer : NULL; DBUG_PRINT("info", ("index count old: %d new: %d", table->s->keys, ha_alter_info->key_count)); @@ -6513,6 +6519,17 @@ static bool fill_alter_inplace_info(THD *thd, new_field->field->field_index != key_part->fieldnr - 1) goto index_changed; } + + /* + Rebuild the index if following condition get satisfied: + + (i) Old table doesn't have primary key, new table has it and vice-versa + (ii) Primary key changed to another existing index + */ + if ((new_key == new_pk) != + ((uint) (table_key - table->key_info) == table->s->primary_key)) + goto index_changed; + continue; index_changed: |