1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Merge branch '10.5' into 10.6

This commit is contained in:
Oleksandr Byelkin
2023-08-02 20:20:50 +02:00
42 changed files with 639 additions and 404 deletions

View File

@ -82,12 +82,9 @@ static int copy_data_between_tables(THD *, TABLE *,TABLE *,
ha_rows *, ha_rows *,
Alter_info::enum_enable_or_disable,
Alter_table_ctx *);
static int append_system_key_parts(THD *thd, HA_CREATE_INFO *create_info,
Key *key);
static int append_system_key_parts(THD *, HA_CREATE_INFO *, Key *);
static int mysql_prepare_create_table(THD *, HA_CREATE_INFO *, Alter_info *,
uint *, handler *, KEY **, uint *, int,
const LEX_CSTRING db,
const LEX_CSTRING table_name);
uint *, handler *, KEY **, uint *, int);
static uint blob_length_by_type(enum_field_types type);
static bool fix_constraints_names(THD *, List<Virtual_column_info> *,
const HA_CREATE_INFO *);
@ -401,8 +398,7 @@ uint filename_to_tablename(const char *from, char *to, size_t to_length,
system_charset_info, to, to_length, &errors);
if (unlikely(errors)) // Old 5.0 name
{
res= (strxnmov(to, to_length, MYSQL50_TABLE_NAME_PREFIX, from, NullS) -
to);
res= strxnmov(to, to_length, MYSQL50_TABLE_NAME_PREFIX, from, NullS) - to;
if (!stay_quiet)
sql_print_error("Invalid (old?) table or database name '%s'", from);
}
@ -673,9 +669,9 @@ uint build_table_shadow_filename(char *buff, size_t bufflen,
{
char tmp_name[FN_REFLEN];
my_snprintf(tmp_name, sizeof (tmp_name), "%s-shadow-%lx-%s", tmp_file_prefix,
(ulong) current_thd->thread_id, lpt->table_name.str);
return build_table_filename(buff, bufflen, lpt->db.str, tmp_name, "",
FN_IS_TMP);
(ulong) current_thd->thread_id, lpt->alter_info->table_name.str);
return build_table_filename(buff, bufflen, lpt->alter_info->db.str, tmp_name,
"", FN_IS_TMP);
}
@ -734,7 +730,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
if (mysql_prepare_create_table(lpt->thd, lpt->create_info, lpt->alter_info,
&lpt->db_options, lpt->table->file,
&lpt->key_info_buffer, &lpt->key_count,
C_ALTER_TABLE, lpt->db, lpt->table_name))
C_ALTER_TABLE))
{
DBUG_RETURN(TRUE);
}
@ -754,7 +750,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
#endif
/* Write shadow frm file */
lpt->create_info->table_options= lpt->db_options;
LEX_CUSTRING frm= build_frm_image(lpt->thd, lpt->table_name,
LEX_CUSTRING frm= build_frm_image(lpt->thd, lpt->alter_info->table_name,
lpt->create_info,
lpt->alter_info->create_list,
lpt->key_count, lpt->key_info_buffer,
@ -765,7 +761,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
goto end;
}
int error= writefile(shadow_frm_name, lpt->db.str, lpt->table_name.str,
int error= writefile(shadow_frm_name, lpt->alter_info->db.str,
lpt->alter_info->table_name.str,
lpt->create_info->tmp_table(), frm.str, frm.length);
my_free(const_cast<uchar*>(frm.str));
@ -787,8 +784,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
/*
Build frm file name
*/
build_table_filename(path, sizeof(path) - 1, lpt->db.str,
lpt->table_name.str, "", 0);
build_table_filename(path, sizeof(path) - 1, lpt->alter_info->db.str,
lpt->alter_info->table_name.str, "", 0);
strxnmov(frm_name, sizeof(frm_name), path, reg_ext, NullS);
/*
When we are changing to use new frm file we need to ensure that we
@ -2207,7 +2204,7 @@ static void check_duplicate_key(THD *thd, const Key *key, const KEY *key_info,
Check is requested if the key was explicitly created or altered
by the user (unless it's a foreign key).
*/
if (!key->key_create_info.check_for_duplicate_indexes || key->generated)
if (key->old || key->type == Key::FOREIGN_KEY || key->generated)
return;
for (const Key &k : *key_list)
@ -2575,8 +2572,7 @@ static int
mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
Alter_info *alter_info, uint *db_options,
handler *file, KEY **key_info_buffer,
uint *key_count, int create_table_mode,
const LEX_CSTRING db, const LEX_CSTRING table_name)
uint *key_count, int create_table_mode)
{
const char *key_name;
Create_field *sql_field,*dup_field;
@ -2595,6 +2591,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
const Column_derived_attributes dattr(create_info->default_table_charset);
const Column_bulk_alter_attributes
battr(create_info->alter_table_convert_to_charset);
const CHARSET_INFO *scs= system_charset_info;
DBUG_ENTER("mysql_prepare_create_table");
DBUG_EXECUTE_IF("test_pseudo_invisible",{
@ -2608,23 +2605,17 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
new (thd->mem_root)Item_int(thd, 9));
});
DBUG_EXECUTE_IF("test_invisible_index",{
LEX_CSTRING temp;
temp.str= "invisible";
temp.length= strlen("invisible");
mysql_add_invisible_index(thd, &alter_info->key_list
, &temp, Key::MULTIPLE);
LEX_CSTRING temp= { STRING_WITH_LEN("invisible") };
mysql_add_invisible_index(thd, &alter_info->key_list, &temp,
Key::MULTIPLE);
});
LEX_CSTRING* connect_string = &create_info->connect_string;
if (connect_string->length != 0 &&
connect_string->length > CONNECT_STRING_MAXLEN &&
(system_charset_info->charpos(connect_string->str,
(connect_string->str +
connect_string->length),
CONNECT_STRING_MAXLEN)
< connect_string->length))
LEX_CSTRING* connstr = &create_info->connect_string;
if (connstr->length > CONNECT_STRING_MAXLEN &&
scs->charpos(connstr->str, connstr->str + connstr->length,
CONNECT_STRING_MAXLEN) < connstr->length)
{
my_error(ER_WRONG_STRING_LENGTH, MYF(0),
connect_string->str, "CONNECTION", CONNECT_STRING_MAXLEN);
my_error(ER_WRONG_STRING_LENGTH, MYF(0), connstr->str, "CONNECTION",
CONNECT_STRING_MAXLEN);
DBUG_RETURN(TRUE);
}
@ -2687,9 +2678,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
/* Check if we have used the same field name before */
for (dup_no=0; (dup_field=it2++) != sql_field; dup_no++)
{
if (lex_string_cmp(system_charset_info,
&sql_field->field_name,
&dup_field->field_name) == 0)
if (lex_string_cmp(scs, &sql_field->field_name, &dup_field->field_name) == 0)
{
/*
If this was a CREATE ... SELECT statement, accept a field
@ -2861,15 +2850,13 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
while ((key2 = key_iterator2++) != key)
{
/*
foreign_key_prefix(key, key2) returns 0 if key or key2, or both, is
'generated', and a generated key is a prefix of the other key.
Then we do not need the generated shorter key.
is_foreign_key_prefix(key, key2) returns true if key or key2, or
both, is 'generated', and a generated key is a prefix of the other
key. Then we do not need the generated shorter key.
*/
if ((key2->type != Key::FOREIGN_KEY &&
key2->name.str != ignore_key &&
!foreign_key_prefix(key, key2)))
if (key2->type != Key::FOREIGN_KEY && key2->name.str != ignore_key &&
is_foreign_key_prefix(key, key2))
{
/* TODO: issue warning message */
/* mark that the generated key should be ignored */
if (!key2->generated ||
(key->generated && key->columns.elements <
@ -2890,14 +2877,13 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
else
(*key_count)--;
if (key->name.str && !tmp_table && (key->type != Key::PRIMARY) &&
!my_strcasecmp(system_charset_info, key->name.str,
primary_key_name.str))
!my_strcasecmp(scs, key->name.str, primary_key_name.str))
{
my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.str);
DBUG_RETURN(TRUE);
}
if (key->type == Key::PRIMARY && key->name.str &&
my_strcasecmp(system_charset_info, key->name.str, primary_key_name.str) != 0)
my_strcasecmp(scs, key->name.str, primary_key_name.str) != 0)
{
bool sav_abort_on_warning= thd->abort_on_warning;
thd->abort_on_warning= FALSE; /* Don't make an error out of this. */
@ -2935,9 +2921,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
auto field_name= key->columns.elem(0)->field_name;
it.rewind();
while ((sql_field=it++) &&
lex_string_cmp(system_charset_info,
&field_name,
&sql_field->field_name));
lex_string_cmp(scs, &field_name, &sql_field->field_name));
if (sql_field)
field_name= sql_field->field_name;
key_name=make_unique_key_name(thd, field_name.str,
@ -3110,9 +3094,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
it.rewind();
field=0;
while ((sql_field=it++) &&
lex_string_cmp(system_charset_info,
&column->field_name,
&sql_field->field_name))
lex_string_cmp(scs, &column->field_name, &sql_field->field_name))
field++;
/*
Either field is not present or field visibility is > INVISIBLE_USER
@ -3132,8 +3114,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
}
while ((dup_column= cols2++) != column)
{
if (!lex_string_cmp(system_charset_info,
&column->field_name, &dup_column->field_name))
if (!lex_string_cmp(scs, &column->field_name, &dup_column->field_name))
{
my_error(ER_DUP_FIELDNAME, MYF(0), column->field_name.str);
DBUG_RETURN(TRUE);
@ -3436,8 +3417,7 @@ without_overlaps_err:
{
for (Key_part_spec& kp2: fk->columns)
{
if (!lex_string_cmp(system_charset_info, &kp.field_name,
&kp2.field_name))
if (!lex_string_cmp(scs, &kp.field_name, &kp2.field_name))
{
goto without_overlaps_err;
}
@ -3489,7 +3469,6 @@ without_overlaps_err:
create_info->null_bits= null_fields;
/* Check fields. */
Item::Check_table_name_prm walk_prm(db, table_name);
it.rewind();
while ((sql_field=it++))
{
@ -3547,33 +3526,22 @@ without_overlaps_err:
if (create_simple)
{
/*
NOTE: we cannot do this in check_vcol_func_processor() as there is already
no table name qualifier in expression.
*/
if (sql_field->vcol_info && sql_field->vcol_info->expr &&
sql_field->vcol_info->expr->walk(&Item::check_table_name_processor,
false, (void *) &walk_prm))
{
my_error(ER_BAD_FIELD_ERROR, MYF(0), walk_prm.field.c_ptr(), "GENERATED ALWAYS");
check_expression(sql_field->vcol_info, &sql_field->field_name,
sql_field->vcol_info->stored_in_db
? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL,
alter_info))
DBUG_RETURN(TRUE);
}
if (sql_field->default_value &&
sql_field->default_value->expr->walk(&Item::check_table_name_processor,
false, (void *) &walk_prm))
{
my_error(ER_BAD_FIELD_ERROR, MYF(0), walk_prm.field.c_ptr(), "DEFAULT");
check_expression(sql_field->default_value, &sql_field->field_name,
VCOL_DEFAULT, alter_info))
DBUG_RETURN(TRUE);
}
if (sql_field->check_constraint &&
sql_field->check_constraint->expr->walk(&Item::check_table_name_processor,
false, (void *) &walk_prm))
{
my_error(ER_BAD_FIELD_ERROR, MYF(0), walk_prm.field.c_ptr(), "CHECK");
check_expression(sql_field->check_constraint, &sql_field->field_name,
VCOL_CHECK_FIELD, alter_info))
DBUG_RETURN(TRUE);
}
}
}
@ -3581,22 +3549,9 @@ without_overlaps_err:
create_info->check_constraint_list= &alter_info->check_constraint_list;
{
List_iterator_fast<Virtual_column_info> c_it(alter_info->check_constraint_list);
Virtual_column_info *check;
while ((check= c_it++))
while (Virtual_column_info *check= c_it++)
{
if (create_simple && check->expr->walk(&Item::check_table_name_processor, false,
(void *) &walk_prm))
{
my_error(ER_BAD_FIELD_ERROR, MYF(0), walk_prm.field.c_ptr(), "CHECK");
DBUG_RETURN(TRUE);
}
if (!check->name.length || check->automatic_name)
{
if (check_expression(check, &check->name, VCOL_CHECK_TABLE, alter_info))
DBUG_RETURN(TRUE);
continue;
}
if (check->name.length && !check->automatic_name)
{
/* Check that there's no repeating table CHECK constraint names. */
List_iterator_fast<Virtual_column_info>
@ -3604,57 +3559,45 @@ without_overlaps_err:
const Virtual_column_info *dup_check;
while ((dup_check= dup_it++) && dup_check != check)
{
if (!lex_string_cmp(system_charset_info,
&check->name, &dup_check->name))
if (check->name.streq(dup_check->name))
{
my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "CHECK", check->name.str);
DBUG_RETURN(TRUE);
}
}
}
/* Check that there's no repeating key constraint names. */
List_iterator_fast<Key> key_it(alter_info->key_list);
while (const Key *key= key_it++)
{
/*
Not all keys considered to be the CONSTRAINT
Noly Primary Key UNIQUE and Foreign keys.
*/
if (key->type != Key::PRIMARY && key->type != Key::UNIQUE &&
key->type != Key::FOREIGN_KEY)
continue;
if (check->name.length == key->name.length &&
my_strcasecmp(system_charset_info,
check->name.str, key->name.str) == 0)
/* Check that there's no repeating key constraint names. */
List_iterator_fast<Key> key_it(alter_info->key_list);
while (const Key *key= key_it++)
{
my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "CHECK", check->name.str);
if (key->type != Key::PRIMARY && key->type != Key::UNIQUE &&
key->type != Key::FOREIGN_KEY)
continue;
if (check->name.length == key->name.length &&
my_strcasecmp(scs, check->name.str, key->name.str) == 0)
{
my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "CHECK", check->name.str);
DBUG_RETURN(TRUE);
}
}
if (check_string_char_length(&check->name, 0, NAME_CHAR_LEN, scs, 1))
{
my_error(ER_TOO_LONG_IDENT, MYF(0), check->name.str);
DBUG_RETURN(TRUE);
}
}
if (check_string_char_length(&check->name, 0, NAME_CHAR_LEN,
system_charset_info, 1))
{
my_error(ER_TOO_LONG_IDENT, MYF(0), check->name.str);
DBUG_RETURN(TRUE);
}
if (check_expression(check, &check->name, VCOL_CHECK_TABLE, alter_info))
DBUG_RETURN(TRUE);
}
}
/* Give warnings for not supported table options */
extern handlerton *maria_hton;
if (file->partition_ht() != maria_hton && create_info->transactional &&
!file->has_transaction_manager())
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_ILLEGAL_HA_CREATE_OPTION,
ER_THD(thd, ER_ILLEGAL_HA_CREATE_OPTION),
file->engine_name()->str,
create_info->transactional == HA_CHOICE_YES
? "TRANSACTIONAL=1" : "TRANSACTIONAL=0");
if (create_info->used_fields & HA_CREATE_USED_TRANSACTIONAL &&
!file->has_transactional_option())
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_OPTION,
ER_THD(thd, ER_UNKNOWN_OPTION), "transactional");
if (parse_option_list(thd, file->partition_ht(), &create_info->option_struct,
&create_info->option_list,
@ -3662,12 +3605,10 @@ without_overlaps_err:
thd->mem_root))
DBUG_RETURN(TRUE);
#ifndef DBUG_OFF
DBUG_EXECUTE_IF("key",
Debug_key::print_keys(thd, "prep_create_table: ",
*key_info_buffer, *key_count);
);
#endif
DBUG_RETURN(FALSE);
}
@ -3909,9 +3850,7 @@ static int append_system_key_parts(THD *thd, HA_CREATE_INFO *create_info,
return result;
}
handler *mysql_create_frm_image(THD *thd, const LEX_CSTRING &db,
const LEX_CSTRING &table_name,
HA_CREATE_INFO *create_info,
handler *mysql_create_frm_image(THD *thd, HA_CREATE_INFO *create_info,
Alter_info *alter_info, int create_table_mode,
KEY **key_info, uint *key_count,
LEX_CUSTRING *frm)
@ -3926,7 +3865,7 @@ handler *mysql_create_frm_image(THD *thd, const LEX_CSTRING &db,
DBUG_RETURN(NULL);
}
set_table_default_charset(thd, create_info, db);
set_table_default_charset(thd, create_info, alter_info->db);
db_options= create_info->table_options_with_row_type();
@ -4047,7 +3986,7 @@ handler *mysql_create_frm_image(THD *thd, const LEX_CSTRING &db,
if (part_info->vers_info && !create_info->versioned())
{
my_error(ER_VERS_NOT_VERSIONED, MYF(0), table_name.str);
my_error(ER_VERS_NOT_VERSIONED, MYF(0), alter_info->table_name.str);
goto err;
}
@ -4145,14 +4084,12 @@ handler *mysql_create_frm_image(THD *thd, const LEX_CSTRING &db,
#endif
if (mysql_prepare_create_table(thd, create_info, alter_info, &db_options,
file, key_info, key_count,
create_table_mode, db, table_name))
file, key_info, key_count, create_table_mode))
goto err;
create_info->table_options=db_options;
*frm= build_frm_image(thd, table_name, create_info,
alter_info->create_list, *key_count,
*key_info, file);
*frm= build_frm_image(thd, alter_info->table_name, create_info,
alter_info->create_list, *key_count, *key_info, file);
if (frm->str)
DBUG_RETURN(file);
@ -4457,9 +4394,10 @@ int create_table_impl(THD *thd,
&path, &db, &table_name, frm_only);
debug_crash_here("ddl_log_create_before_create_frm");
file= mysql_create_frm_image(thd, orig_db, orig_table_name, create_info,
alter_info, create_table_mode, key_info,
key_count, frm);
alter_info->db= orig_db;
alter_info->table_name= orig_table_name;
file= mysql_create_frm_image(thd, create_info, alter_info,
create_table_mode, key_info, key_count, frm);
/*
TODO: remove this check of thd->is_error() (now it intercept
errors in some val_*() methods and bring some single place to
@ -4548,8 +4486,6 @@ warn:
int mysql_create_table_no_lock(THD *thd,
DDL_LOG_STATE *ddl_log_state_create,
DDL_LOG_STATE *ddl_log_state_rm,
const LEX_CSTRING *db,
const LEX_CSTRING *table_name,
Table_specification_st *create_info,
Alter_info *alter_info, bool *is_trans,
int create_table_mode, TABLE_LIST *table_list)
@ -4560,6 +4496,8 @@ int mysql_create_table_no_lock(THD *thd,
uint path_length;
char path[FN_REFLEN + 1];
LEX_CSTRING cpath;
const LEX_CSTRING *db= &table_list->db;
const LEX_CSTRING *table_name= &table_list->table_name;
LEX_CUSTRING frm= {0,0};
if (create_info->tmp_table())
@ -4747,8 +4685,7 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
thd->abort_on_warning= thd->is_strict_mode();
if (mysql_create_table_no_lock(thd, &ddl_log_state_create, &ddl_log_state_rm,
&create_table->db,
&create_table->table_name, create_info,
create_info,
alter_info,
&is_trans, create_table_mode,
create_table) > 0)
@ -5260,7 +5197,6 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
res= ((create_res=
mysql_create_table_no_lock(thd,
&ddl_log_state_create, &ddl_log_state_rm,
&table->db, &table->table_name,
&local_create_info, &local_alter_info,
&is_trans, C_ORDINARY_CREATE,
table)) > 0);
@ -6948,10 +6884,8 @@ static void update_altered_table(const Alter_inplace_info &ha_alter_info,
@retval false success
*/
bool mysql_compare_tables(TABLE *table,
Alter_info *alter_info,
HA_CREATE_INFO *create_info,
bool *metadata_equal)
bool mysql_compare_tables(TABLE *table, Alter_info *alter_info,
HA_CREATE_INFO *create_info, bool *metadata_equal)
{
DBUG_ENTER("mysql_compare_tables");
@ -6976,15 +6910,16 @@ bool mysql_compare_tables(TABLE *table,
Alter_info tmp_alter_info(*alter_info, thd->mem_root);
uint db_options= 0; /* not used */
KEY *key_info_buffer= NULL;
LEX_CSTRING db= { table->s->db.str, table->s->db.length };
LEX_CSTRING table_name= { table->s->db.str, table->s->table_name.length };
tmp_alter_info.db= table->s->db;
tmp_alter_info.table_name= table->s->table_name;
/* Create the prepared information. */
int create_table_mode= table->s->tmp_table == NO_TMP_TABLE ?
C_ORDINARY_CREATE : C_ALTER_TABLE;
if (mysql_prepare_create_table(thd, create_info, &tmp_alter_info,
&db_options, table->file, &key_info_buffer,
&key_count, create_table_mode, db, table_name))
&key_count, create_table_mode))
DBUG_RETURN(1);
/* Some very basic checks. */
@ -7760,6 +7695,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
List<Create_field> new_create_tail;
/* New key definitions are added here */
List<Key> new_key_list;
List<FOREIGN_KEY_INFO> fk_list;
List<Alter_rename_key> rename_key_list(alter_info->alter_rename_key_list);
/*
@ -7793,12 +7729,13 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
bool drop_period= false;
LEX_CSTRING period_start_name= {nullptr, 0};
LEX_CSTRING period_end_name= {nullptr, 0};
DBUG_ENTER("mysql_prepare_alter_table");
if (table->s->period.name)
{
period_start_name= table->s->period_start_field()->field_name;
period_end_name= table->s->period_end_field()->field_name;
}
DBUG_ENTER("mysql_prepare_alter_table");
/*
Merge incompatible changes flag in case of upgrade of a table from an
@ -7859,6 +7796,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
create_info->option_list= merge_engine_table_options(table->s->option_list,
create_info->option_list, thd->mem_root);
table->file->get_foreign_key_list(thd, &fk_list);
/*
First collect all fields from table which isn't in drop_list
*/
@ -8473,12 +8412,6 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
key_create_info.comment= key_info->comment;
key_create_info.is_ignored= key_info->is_ignored;
/*
We're refreshing an already existing index. Since the index is not
modified, there is no need to check for duplicate indexes again.
*/
key_create_info.check_for_duplicate_indexes= false;
if (key_info->flags & HA_SPATIAL)
key_type= Key::SPATIAL;
else if (key_info->flags & HA_NOSAME)
@ -8525,10 +8458,11 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
tmp_name.length= strlen(key_name);
/* We dont need LONG_UNIQUE_HASH_FIELD flag because it will be autogenerated */
key= new (thd->mem_root) Key(key_type, &tmp_name, &key_create_info,
MY_TEST(key_info->flags & HA_GENERATED_KEY),
key_info->flags & HA_GENERATED_KEY,
&key_parts, key_info->option_list, DDL_options());
key->without_overlaps= key_info->without_overlaps;
key->period= table->s->period.name;
key->old= true;
new_key_list.push_back(key, thd->mem_root);
}
if (long_hash_key)
@ -8537,6 +8471,30 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
re_setup_keyinfo_hash(key_info);
}
}
{
// add existing foreign keys
for (auto &fk : fk_list)
{
Alter_drop *drop;
for(drop_it.rewind(); (drop=drop_it++); )
if (drop->type == Alter_drop::FOREIGN_KEY &&
!my_strcasecmp(system_charset_info, fk.foreign_id->str, drop->name))
break;
if (drop)
continue;
List<Key_part_spec> cols, ref_cols;
for (LEX_CSTRING &c : fk.foreign_fields)
cols.push_back(new (thd->mem_root) Key_part_spec(&c, 0));
for (LEX_CSTRING &c : fk.referenced_fields)
ref_cols.push_back(new (thd->mem_root) Key_part_spec(&c, 0));
auto key= new (thd->mem_root)
Foreign_key(fk.foreign_id, &cols, fk.foreign_id, fk.referenced_db,
fk.referenced_table, &ref_cols, fk.delete_method, fk.update_method,
Foreign_key::FK_MATCH_UNDEF, DDL_options());
key->old= true;
new_key_list.push_back(key, thd->mem_root);
}
}
{
Key *key;
while ((key=key_it++)) // Add new keys
@ -8661,10 +8619,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
if (!alter_info->check_constraint_list.is_empty())
{
/* Check the table FOREIGN KEYs for name duplications. */
List <FOREIGN_KEY_INFO> fk_child_key_list;
FOREIGN_KEY_INFO *f_key;
table->file->get_foreign_key_list(thd, &fk_child_key_list);
List_iterator<FOREIGN_KEY_INFO> fk_key_it(fk_child_key_list);
List_iterator<FOREIGN_KEY_INFO> fk_key_it(fk_list);
while ((f_key= fk_key_it++))
{
List_iterator_fast<Virtual_column_info>
@ -9089,7 +9045,7 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table,
while (Key *key= fk_list_it++)
{
if (key->type != Key::FOREIGN_KEY)
if (key->type != Key::FOREIGN_KEY || key->old)
continue;
Foreign_key *fk= static_cast<Foreign_key*>(key);
@ -10099,10 +10055,10 @@ do_continue:;
}
// In-place execution of ALTER TABLE for partitioning.
alter_info->db= alter_ctx.db;
alter_info->table_name= alter_ctx.table_name;
DBUG_RETURN(fast_alter_partition_table(thd, table, alter_info,
create_info, table_list,
&alter_ctx.db,
&alter_ctx.table_name));
create_info, table_list));
}
#endif
@ -10255,9 +10211,9 @@ do_continue:;
alter_ctx.db, alter_ctx.table_name,
alter_ctx.new_db, alter_ctx.tmp_name,
alter_ctx.get_tmp_cstring_path(),
thd->lex->create_info, create_info, alter_info,
C_ALTER_TABLE_FRM_ONLY, NULL,
&key_info, &key_count, &frm);
thd->lex->create_info,
create_info, alter_info, C_ALTER_TABLE_FRM_ONLY,
NULL, &key_info, &key_count, &frm);
thd->abort_on_warning= false;
reenable_binlog(thd);