summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-02-02 13:00:15 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2019-02-02 13:00:15 +0200
commit213ece2f2e8c23ee0e727cc02dcecfae6f510ca2 (patch)
tree5ce93ecb5caa9a58ebc08f8cd3e94c59d7219377 /sql/sql_table.cc
parentc1e1764fc4b913ee688b383aac2698b83661d64c (diff)
parentd9d83f1d92b696ef56f4944df036b8a78364ebb4 (diff)
downloadmariadb-git-213ece2f2e8c23ee0e727cc02dcecfae6f510ca2.tar.gz
Merge 10.1 into 10.1
This is joint work with Oleksandr Byelkin.
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc69
1 files changed, 17 insertions, 52 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 670838a4cbb..55b77c8b934 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -5717,7 +5717,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++)
@@ -6203,9 +6204,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;
@@ -6213,7 +6212,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");
@@ -6489,8 +6487,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));
@@ -6572,8 +6575,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;
/* Check that key comment is not changed. */
@@ -6634,22 +6636,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 +
@@ -6662,21 +6648,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;
@@ -6689,23 +6664,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;
@@ -9984,7 +9946,10 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
{
/* calculating table's checksum */
ha_checksum crc= 0;
- uchar null_mask=256 - (1 << t->s->last_null_bit_pos);
+ DBUG_ASSERT(t->s->last_null_bit_pos < 8);
+ uchar null_mask= (t->s->last_null_bit_pos ?
+ (256 - (1 << t->s->last_null_bit_pos)):
+ 0);
t->use_all_columns();