diff --git a/sql/datadict.cc b/sql/datadict.cc index e09eee98565..1321bf9a3a7 100644 --- a/sql/datadict.cc +++ b/sql/datadict.cc @@ -194,6 +194,6 @@ bool dd_recreate_table(THD *thd, const char *db, const char *table_name) build_table_filename(path_buf, sizeof(path_buf) - 1, db, table_name, "", 0); /* Attempt to reconstruct the table. */ - DBUG_RETURN(ha_create_table(thd, path_buf, db, table_name, &create_info, 0)); + DBUG_RETURN(ha_create_table(thd, path_buf, db, table_name, &create_info, 0, 0)); } diff --git a/sql/handler.cc b/sql/handler.cc index 2a2213af1cc..e67148fb5d3 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5525,9 +5525,9 @@ int handler::calculate_checksum() @retval 1 error */ -int ha_create_table(THD *thd, const char *path, - const char *db, const char *table_name, - HA_CREATE_INFO *create_info, LEX_CUSTRING *frm) +int ha_create_table(THD *thd, const char *path, const char *db, + const char *table_name, HA_CREATE_INFO *create_info, + LEX_CUSTRING *frm, bool skip_frm_file) { int error= 1; TABLE table; @@ -5543,8 +5543,8 @@ int ha_create_table(THD *thd, const char *path, if (frm) { - bool write_frm_now= !create_info->db_type->discover_table && - !create_info->tmp_table(); + bool write_frm_now= (!create_info->db_type->discover_table && + !create_info->tmp_table() && !skip_frm_file); share.frm_image= frm; diff --git a/sql/handler.h b/sql/handler.h index f43f91de18c..0f322987cc3 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -5172,9 +5172,9 @@ bool ha_flush_logs(); void ha_drop_database(char* path); void ha_checkpoint_state(bool disable); void ha_commit_checkpoint_request(void *cookie, void (*pre_hook)(void *)); -int ha_create_table(THD *thd, const char *path, - const char *db, const char *table_name, - HA_CREATE_INFO *create_info, LEX_CUSTRING *frm); +int ha_create_table(THD *thd, const char *path, const char *db, + const char *table_name, HA_CREATE_INFO *create_info, + LEX_CUSTRING *frm, bool skip_frm_file); int ha_delete_table(THD *thd, handlerton *db_type, const char *path, const LEX_CSTRING *db, const LEX_CSTRING *alias, bool generate_warning); diff --git a/sql/item_vers.h b/sql/item_vers.h index e816b3bf0e9..7cd5d847b15 100644 --- a/sql/item_vers.h +++ b/sql/item_vers.h @@ -46,7 +46,7 @@ public: LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= {STRING_WITH_LEN("is_history") }; - return name; + return name; } void print(String *str, enum_query_type query_type) override; Item *get_copy(THD *thd) override diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 3742cfbb0e9..1edc830016d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -549,8 +549,13 @@ uint build_table_filename(char *buff, size_t bufflen, const char *db, (void) tablename_to_filename(db, dbbuff, sizeof(dbbuff)); - /* Check if this is a temporary table name. Allow it if a corresponding .frm file exists */ - if (is_prefix(table_name, tmp_file_prefix) && strlen(table_name) < NAME_CHAR_LEN && + /* + Check if this is a temporary table name. Allow it if a corresponding .frm + file exists. + */ + if (!(flags & FN_IS_TMP) && + is_prefix(table_name, tmp_file_prefix) && + strlen(table_name) < NAME_CHAR_LEN && check_if_frm_exists(tbbuff, dbbuff, table_name)) flags|= FN_IS_TMP; @@ -3997,13 +4002,17 @@ err: the extension). @param create_info Create information (like MAX_ROWS) @param alter_info Description of fields and keys for new table - @param create_table_mode C_ORDINARY_CREATE, C_ALTER_TABLE, C_ASSISTED_DISCOVERY + @param create_table_mode C_ORDINARY_CREATE, C_ALTER_TABLE, + C_ASSISTED_DISCOVERY or C_ALTER_TABLE_FRM_ONLY. or any positive number (for C_CREATE_SELECT). + If set to C_ALTER_TABLE_FRM_ONY then no frm or + table is created, only the frm image in memory. @param[out] is_trans Identifies the type of engine where the table was created: either trans or non-trans. @param[out] key_info Array of KEY objects describing keys in table which was created. @param[out] key_count Number of keys in table which was created. + @param[out] frm The frm image. If one creates a temporary table, its is automatically opened and its TABLE_SHARE is added to THD::all_temp_tables list. @@ -4264,7 +4273,8 @@ int create_table_impl(THD *thd, const LEX_CSTRING &orig_db, if (!frm_only) { - if (ha_create_table(thd, path, db.str, table_name.str, create_info, frm)) + if (ha_create_table(thd, path, db.str, table_name.str, create_info, + frm, 0)) { file->ha_create_partitioning_metadata(path, NULL, CHF_DELETE_FLAG); deletefrm(path); @@ -7083,18 +7093,14 @@ static bool mysql_inplace_alter_table(THD *thd, goto rollback; } if (trt.update(trx_start_id, trx_end_id)) - { goto rollback; - } } } if (table->file->ha_commit_inplace_alter_table(altered_table, ha_alter_info, true)) - { goto rollback; - } DEBUG_SYNC(thd, "alter_table_inplace_after_commit"); } @@ -7197,7 +7203,6 @@ static bool mysql_inplace_alter_table(THD *thd, NULL); if (thd->locked_tables_list.reopen_tables(thd, false)) thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); - /* QQ; do something about metadata locks ? */ } DBUG_RETURN(true); } @@ -8709,6 +8714,7 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list, { THD_STAGE_INFO(thd, stage_rename); handlerton *old_db_type= table->s->db_type(); + /* Then do a 'simple' rename of the table. First we need to close all instances of 'source' table. @@ -8878,7 +8884,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, uint order_num, ORDER *order, bool ignore, bool if_exists) { - bool engine_changed, error; + bool engine_changed, error, frm_is_created= false; bool no_ha_table= true; /* We have not created table in storage engine yet */ TABLE *table, *new_table; #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -9633,6 +9639,11 @@ do_continue:; if (create_table_for_inplace_alter(thd, alter_ctx, &frm, &altered_share, &altered_table)) goto err_new_table_cleanup; + /* + Avoid creating frm again in ha_create_table() if inline alter will not + be used. + */ + frm_is_created= 1; /* Set markers for fields in TABLE object for altered table. */ update_altered_table(ha_alter_info, &altered_table); @@ -9764,7 +9775,7 @@ do_continue:; if (ha_create_table(thd, alter_ctx.get_tmp_path(), alter_ctx.new_db.str, alter_ctx.new_name.str, - create_info, &frm)) + create_info, &frm, frm_is_created)) goto err_new_table_cleanup; /* Mark that we have created table in storage engine. */ @@ -9867,7 +9878,7 @@ do_continue:; if (table->s->tmp_table != NO_TMP_TABLE) { - /* Close lock if this is a transactional table */ + /* Release lock if this is a transactional temporary table */ if (thd->lock) { if (thd->locked_tables_mode != LTM_LOCK_TABLES && @@ -9888,6 +9899,7 @@ do_continue:; goto err_new_table_cleanup; } } + new_table->s->table_creation_was_logged= table->s->table_creation_was_logged; /* Remove link to old table and rename the new one */