diff options
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r-- | sql/sql_table.cc | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 99070bcd89c..00815fdd36c 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -8667,7 +8667,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, If the '0000-00-00' value isn't allowed then raise the error_if_not_empty flag to allow ALTER TABLE only if the table to be altered is empty. */ - if (!alter_ctx->implicit_default_value_error_field && + if (!alter_ctx->implicit_default_value_error_field && !def->field && !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) && def->type_handler()->validate_implicit_default_value(thd, *def)) { @@ -8913,7 +8913,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, key_parts.push_back(new (thd->mem_root) Key_part_spec(&cfield->field_name, key_part_length, true), thd->mem_root); - if (cfield->invisible < INVISIBLE_SYSTEM) + if (!(cfield->invisible == INVISIBLE_SYSTEM && cfield->vers_sys_field())) user_keyparts= true; } if (table->s->tmp_table == NO_TMP_TABLE) @@ -8925,6 +8925,14 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, (void) delete_statistics_for_index(thd, table, key_info, TRUE); } + if (!user_keyparts && key_parts.elements) + { + /* + If we dropped all user key-parts we also drop implicit system fields. + */ + key_parts.empty(); + } + if (key_parts.elements) { KEY_CREATE_INFO key_create_info; @@ -8960,7 +8968,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, key_type= Key::PRIMARY; else key_type= Key::UNIQUE; - if (dropped_key_part && user_keyparts) + if (dropped_key_part) { my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), dropped_key_part); if (long_hash_key) |