mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
cleanup: fill_alter_inplace_info
remove attempts to track "candidate keys", use what was already decided in create_table_impl().
This commit is contained in:
@ -5691,7 +5691,8 @@ static bool is_candidate_key(KEY *key)
|
||||
KEY_PART_INFO *key_part;
|
||||
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;
|
||||
|
||||
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)
|
||||
@retval false success
|
||||
*/
|
||||
|
||||
static bool fill_alter_inplace_info(THD *thd,
|
||||
TABLE *table,
|
||||
bool varchar,
|
||||
static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
|
||||
Alter_inplace_info *ha_alter_info)
|
||||
{
|
||||
Field **f_ptr, *field;
|
||||
@ -6167,7 +6166,6 @@ static bool fill_alter_inplace_info(THD *thd,
|
||||
Create_field *new_field;
|
||||
KEY_PART_INFO *key_part, *new_part;
|
||||
KEY_PART_INFO *end;
|
||||
uint candidate_key_count= 0;
|
||||
Alter_info *alter_info= ha_alter_info->alter_info;
|
||||
DBUG_ENTER("fill_alter_inplace_info");
|
||||
|
||||
@ -6443,8 +6441,13 @@ static bool fill_alter_inplace_info(THD *thd,
|
||||
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)) ?
|
||||
(!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;
|
||||
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",
|
||||
table->s->keys, ha_alter_info->key_count));
|
||||
@ -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
|
||||
(ii) Primary key changed to another existing index
|
||||
*/
|
||||
if ((new_key == new_pk) !=
|
||||
((uint) (table_key - table->key_info) == table->s->primary_key))
|
||||
if ((new_key == new_pk) != (table_key == old_pk))
|
||||
goto index_changed;
|
||||
|
||||
continue;
|
||||
@ -6581,22 +6583,6 @@ static bool fill_alter_inplace_info(THD *thd,
|
||||
|
||||
/* 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. */
|
||||
KEY **dropped_key;
|
||||
KEY **dropped_key_end= ha_alter_info->index_drop_buffer +
|
||||
@ -6609,21 +6595,10 @@ static bool fill_alter_inplace_info(THD *thd,
|
||||
|
||||
if (table_key->flags & HA_NOSAME)
|
||||
{
|
||||
/*
|
||||
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)
|
||||
{
|
||||
if (table_key == old_pk)
|
||||
ha_alter_info->handler_flags|= Alter_inplace_info::DROP_PK_INDEX;
|
||||
candidate_key_count--;
|
||||
}
|
||||
else
|
||||
{
|
||||
ha_alter_info->handler_flags|= Alter_inplace_info::DROP_UNIQUE_INDEX;
|
||||
if (is_candidate_key(table_key))
|
||||
candidate_key_count--;
|
||||
}
|
||||
}
|
||||
else
|
||||
ha_alter_info->handler_flags|= Alter_inplace_info::DROP_INDEX;
|
||||
@ -6636,23 +6611,10 @@ static bool fill_alter_inplace_info(THD *thd,
|
||||
|
||||
if (new_key->flags & HA_NOSAME)
|
||||
{
|
||||
bool is_pk= !my_strcasecmp(system_charset_info, new_key->name, primary_key_name);
|
||||
|
||||
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++;
|
||||
}
|
||||
if (new_key == new_pk)
|
||||
ha_alter_info->handler_flags|= Alter_inplace_info::ADD_PK_INDEX;
|
||||
else
|
||||
{
|
||||
ha_alter_info->handler_flags|= Alter_inplace_info::ADD_UNIQUE_INDEX;
|
||||
}
|
||||
}
|
||||
else
|
||||
ha_alter_info->handler_flags|= Alter_inplace_info::ADD_INDEX;
|
||||
|
Reference in New Issue
Block a user