Commit 38ad46e0 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: fill_alter_inplace_info

remove attempts to track "candidate keys", use what was already
decided in create_table_impl().
parent 013186eb
...@@ -5691,7 +5691,8 @@ static bool is_candidate_key(KEY *key) ...@@ -5691,7 +5691,8 @@ static bool is_candidate_key(KEY *key)
KEY_PART_INFO *key_part; KEY_PART_INFO *key_part;
KEY_PART_INFO *key_part_end= key->key_part + key->user_defined_key_parts; KEY_PART_INFO *key_part_end= key->key_part + key->user_defined_key_parts;
if (!(key->flags & HA_NOSAME) || (key->flags & HA_NULL_PART_KEY)) if (!(key->flags & HA_NOSAME) || (key->flags & HA_NULL_PART_KEY) ||
(key->flags & HA_KEY_HAS_PART_KEY_SEG))
return false; return false;
for (key_part= key->key_part; key_part < key_part_end; key_part++) for (key_part= key->key_part; key_part < key_part_end; key_part++)
...@@ -6157,9 +6158,7 @@ static int compare_uint(const uint *s, const uint *t) ...@@ -6157,9 +6158,7 @@ static int compare_uint(const uint *s, const uint *t)
@retval false success @retval false success
*/ */
static bool fill_alter_inplace_info(THD *thd, static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
TABLE *table,
bool varchar,
Alter_inplace_info *ha_alter_info) Alter_inplace_info *ha_alter_info)
{ {
Field **f_ptr, *field; Field **f_ptr, *field;
...@@ -6167,7 +6166,6 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -6167,7 +6166,6 @@ static bool fill_alter_inplace_info(THD *thd,
Create_field *new_field; Create_field *new_field;
KEY_PART_INFO *key_part, *new_part; KEY_PART_INFO *key_part, *new_part;
KEY_PART_INFO *end; KEY_PART_INFO *end;
uint candidate_key_count= 0;
Alter_info *alter_info= ha_alter_info->alter_info; Alter_info *alter_info= ha_alter_info->alter_info;
DBUG_ENTER("fill_alter_inplace_info"); DBUG_ENTER("fill_alter_inplace_info");
...@@ -6443,8 +6441,13 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -6443,8 +6441,13 @@ static bool fill_alter_inplace_info(THD *thd,
Primary key index for the new table Primary key index for the new table
*/ */
const KEY* const new_pk= (ha_alter_info->key_count > 0 && const KEY* const new_pk= (ha_alter_info->key_count > 0 &&
is_candidate_key(ha_alter_info->key_info_buffer)) ? (!my_strcasecmp(system_charset_info,
ha_alter_info->key_info_buffer->name,
primary_key_name) ||
is_candidate_key(ha_alter_info->key_info_buffer))) ?
ha_alter_info->key_info_buffer : NULL; ha_alter_info->key_info_buffer : NULL;
const KEY *const old_pk= table->s->primary_key == MAX_KEY ? NULL :
table->key_info + table->s->primary_key;
DBUG_PRINT("info", ("index count old: %d new: %d", DBUG_PRINT("info", ("index count old: %d new: %d",
table->s->keys, ha_alter_info->key_count)); table->s->keys, ha_alter_info->key_count));
...@@ -6526,8 +6529,7 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -6526,8 +6529,7 @@ static bool fill_alter_inplace_info(THD *thd,
(i) Old table doesn't have primary key, new table has it and vice-versa (i) Old table doesn't have primary key, new table has it and vice-versa
(ii) Primary key changed to another existing index (ii) Primary key changed to another existing index
*/ */
if ((new_key == new_pk) != if ((new_key == new_pk) != (table_key == old_pk))
((uint) (table_key - table->key_info) == table->s->primary_key))
goto index_changed; goto index_changed;
continue; continue;
...@@ -6581,22 +6583,6 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -6581,22 +6583,6 @@ static bool fill_alter_inplace_info(THD *thd,
/* Now let us calculate flags for storage engine API. */ /* Now let us calculate flags for storage engine API. */
/* Count all existing candidate keys. */
for (table_key= table->key_info; table_key < table_key_end; table_key++)
{
/*
Check if key is a candidate key, This key is either already primary key
or could be promoted to primary key if the original primary key is
dropped.
In MySQL one is allowed to create primary key with partial fields (i.e.
primary key which is not considered candidate). For simplicity we count
such key as a candidate key here.
*/
if (((uint) (table_key - table->key_info) == table->s->primary_key) ||
is_candidate_key(table_key))
candidate_key_count++;
}
/* Figure out what kind of indexes we are dropping. */ /* Figure out what kind of indexes we are dropping. */
KEY **dropped_key; KEY **dropped_key;
KEY **dropped_key_end= ha_alter_info->index_drop_buffer + KEY **dropped_key_end= ha_alter_info->index_drop_buffer +
...@@ -6609,21 +6595,10 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -6609,21 +6595,10 @@ static bool fill_alter_inplace_info(THD *thd,
if (table_key->flags & HA_NOSAME) if (table_key->flags & HA_NOSAME)
{ {
/* if (table_key == old_pk)
Unique key. Check for PRIMARY KEY. Also see comment about primary
and candidate keys above.
*/
if ((uint) (table_key - table->key_info) == table->s->primary_key)
{
ha_alter_info->handler_flags|= Alter_inplace_info::DROP_PK_INDEX; ha_alter_info->handler_flags|= Alter_inplace_info::DROP_PK_INDEX;
candidate_key_count--;
}
else else
{
ha_alter_info->handler_flags|= Alter_inplace_info::DROP_UNIQUE_INDEX; ha_alter_info->handler_flags|= Alter_inplace_info::DROP_UNIQUE_INDEX;
if (is_candidate_key(table_key))
candidate_key_count--;
}
} }
else else
ha_alter_info->handler_flags|= Alter_inplace_info::DROP_INDEX; ha_alter_info->handler_flags|= Alter_inplace_info::DROP_INDEX;
...@@ -6636,23 +6611,10 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -6636,23 +6611,10 @@ static bool fill_alter_inplace_info(THD *thd,
if (new_key->flags & HA_NOSAME) if (new_key->flags & HA_NOSAME)
{ {
bool is_pk= !my_strcasecmp(system_charset_info, new_key->name, primary_key_name); if (new_key == new_pk)
ha_alter_info->handler_flags|= Alter_inplace_info::ADD_PK_INDEX;
if ((!(new_key->flags & HA_KEY_HAS_PART_KEY_SEG) &&
!(new_key->flags & HA_NULL_PART_KEY)) ||
is_pk)
{
/* Candidate key or primary key! */
if (candidate_key_count == 0 || is_pk)
ha_alter_info->handler_flags|= Alter_inplace_info::ADD_PK_INDEX;
else
ha_alter_info->handler_flags|= Alter_inplace_info::ADD_UNIQUE_INDEX;
candidate_key_count++;
}
else else
{
ha_alter_info->handler_flags|= Alter_inplace_info::ADD_UNIQUE_INDEX; ha_alter_info->handler_flags|= Alter_inplace_info::ADD_UNIQUE_INDEX;
}
} }
else else
ha_alter_info->handler_flags|= Alter_inplace_info::ADD_INDEX; ha_alter_info->handler_flags|= Alter_inplace_info::ADD_INDEX;
......
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