Commit 24926352 authored by Monty's avatar Monty Committed by Sergei Golubchik

Avoid creating the .frm file twice in some cases

Other things:
- Updated code comments & fixed indentation
- Removed an old QQ (temporary) comment that does not apply anymore
parent 4832e549
...@@ -194,6 +194,6 @@ bool dd_recreate_table(THD *thd, const char *db, const char *table_name) ...@@ -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, build_table_filename(path_buf, sizeof(path_buf) - 1,
db, table_name, "", 0); db, table_name, "", 0);
/* Attempt to reconstruct the table. */ /* 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));
} }
...@@ -5525,9 +5525,9 @@ int handler::calculate_checksum() ...@@ -5525,9 +5525,9 @@ int handler::calculate_checksum()
@retval @retval
1 error 1 error
*/ */
int ha_create_table(THD *thd, const char *path, int ha_create_table(THD *thd, const char *path, const char *db,
const char *db, const char *table_name, const char *table_name, HA_CREATE_INFO *create_info,
HA_CREATE_INFO *create_info, LEX_CUSTRING *frm) LEX_CUSTRING *frm, bool skip_frm_file)
{ {
int error= 1; int error= 1;
TABLE table; TABLE table;
...@@ -5543,8 +5543,8 @@ int ha_create_table(THD *thd, const char *path, ...@@ -5543,8 +5543,8 @@ int ha_create_table(THD *thd, const char *path,
if (frm) if (frm)
{ {
bool write_frm_now= !create_info->db_type->discover_table && bool write_frm_now= (!create_info->db_type->discover_table &&
!create_info->tmp_table(); !create_info->tmp_table() && !skip_frm_file);
share.frm_image= frm; share.frm_image= frm;
......
...@@ -5172,9 +5172,9 @@ bool ha_flush_logs(); ...@@ -5172,9 +5172,9 @@ bool ha_flush_logs();
void ha_drop_database(char* path); void ha_drop_database(char* path);
void ha_checkpoint_state(bool disable); void ha_checkpoint_state(bool disable);
void ha_commit_checkpoint_request(void *cookie, void (*pre_hook)(void *)); void ha_commit_checkpoint_request(void *cookie, void (*pre_hook)(void *));
int ha_create_table(THD *thd, const char *path, int ha_create_table(THD *thd, const char *path, const char *db,
const char *db, const char *table_name, const char *table_name, HA_CREATE_INFO *create_info,
HA_CREATE_INFO *create_info, LEX_CUSTRING *frm); LEX_CUSTRING *frm, bool skip_frm_file);
int ha_delete_table(THD *thd, handlerton *db_type, const char *path, int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
const LEX_CSTRING *db, const LEX_CSTRING *alias, const LEX_CSTRING *db, const LEX_CSTRING *alias,
bool generate_warning); bool generate_warning);
......
...@@ -549,8 +549,13 @@ uint build_table_filename(char *buff, size_t bufflen, const char *db, ...@@ -549,8 +549,13 @@ uint build_table_filename(char *buff, size_t bufflen, const char *db,
(void) tablename_to_filename(db, dbbuff, sizeof(dbbuff)); (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)) check_if_frm_exists(tbbuff, dbbuff, table_name))
flags|= FN_IS_TMP; flags|= FN_IS_TMP;
...@@ -3997,13 +4002,17 @@ handler *mysql_create_frm_image(THD *thd, const LEX_CSTRING &db, ...@@ -3997,13 +4002,17 @@ handler *mysql_create_frm_image(THD *thd, const LEX_CSTRING &db,
the extension). the extension).
@param create_info Create information (like MAX_ROWS) @param create_info Create information (like MAX_ROWS)
@param alter_info Description of fields and keys for new table @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). 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 @param[out] is_trans Identifies the type of engine where the table
was created: either trans or non-trans. was created: either trans or non-trans.
@param[out] key_info Array of KEY objects describing keys in table @param[out] key_info Array of KEY objects describing keys in table
which was created. which was created.
@param[out] key_count Number of 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 If one creates a temporary table, its is automatically opened and its
TABLE_SHARE is added to THD::all_temp_tables list. 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, ...@@ -4264,7 +4273,8 @@ int create_table_impl(THD *thd, const LEX_CSTRING &orig_db,
if (!frm_only) 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); file->ha_create_partitioning_metadata(path, NULL, CHF_DELETE_FLAG);
deletefrm(path); deletefrm(path);
...@@ -7083,18 +7093,14 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -7083,18 +7093,14 @@ static bool mysql_inplace_alter_table(THD *thd,
goto rollback; goto rollback;
} }
if (trt.update(trx_start_id, trx_end_id)) if (trt.update(trx_start_id, trx_end_id))
{
goto rollback; goto rollback;
} }
} }
}
if (table->file->ha_commit_inplace_alter_table(altered_table, if (table->file->ha_commit_inplace_alter_table(altered_table,
ha_alter_info, ha_alter_info,
true)) true))
{
goto rollback; goto rollback;
}
DEBUG_SYNC(thd, "alter_table_inplace_after_commit"); DEBUG_SYNC(thd, "alter_table_inplace_after_commit");
} }
...@@ -7197,7 +7203,6 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -7197,7 +7203,6 @@ static bool mysql_inplace_alter_table(THD *thd,
NULL); NULL);
if (thd->locked_tables_list.reopen_tables(thd, false)) if (thd->locked_tables_list.reopen_tables(thd, false))
thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0);
/* QQ; do something about metadata locks ? */
} }
DBUG_RETURN(true); DBUG_RETURN(true);
} }
...@@ -8709,6 +8714,7 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list, ...@@ -8709,6 +8714,7 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list,
{ {
THD_STAGE_INFO(thd, stage_rename); THD_STAGE_INFO(thd, stage_rename);
handlerton *old_db_type= table->s->db_type(); handlerton *old_db_type= table->s->db_type();
/* /*
Then do a 'simple' rename of the table. First we need to close all Then do a 'simple' rename of the table. First we need to close all
instances of 'source' table. instances of 'source' table.
...@@ -8878,7 +8884,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, ...@@ -8878,7 +8884,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
uint order_num, ORDER *order, bool ignore, uint order_num, ORDER *order, bool ignore,
bool if_exists) 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 */ bool no_ha_table= true; /* We have not created table in storage engine yet */
TABLE *table, *new_table; TABLE *table, *new_table;
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
...@@ -9633,6 +9639,11 @@ do_continue:; ...@@ -9633,6 +9639,11 @@ do_continue:;
if (create_table_for_inplace_alter(thd, alter_ctx, &frm, &altered_share, if (create_table_for_inplace_alter(thd, alter_ctx, &frm, &altered_share,
&altered_table)) &altered_table))
goto err_new_table_cleanup; 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. */ /* Set markers for fields in TABLE object for altered table. */
update_altered_table(ha_alter_info, &altered_table); update_altered_table(ha_alter_info, &altered_table);
...@@ -9764,7 +9775,7 @@ do_continue:; ...@@ -9764,7 +9775,7 @@ do_continue:;
if (ha_create_table(thd, alter_ctx.get_tmp_path(), if (ha_create_table(thd, alter_ctx.get_tmp_path(),
alter_ctx.new_db.str, alter_ctx.new_name.str, alter_ctx.new_db.str, alter_ctx.new_name.str,
create_info, &frm)) create_info, &frm, frm_is_created))
goto err_new_table_cleanup; goto err_new_table_cleanup;
/* Mark that we have created table in storage engine. */ /* Mark that we have created table in storage engine. */
...@@ -9867,7 +9878,7 @@ do_continue:; ...@@ -9867,7 +9878,7 @@ do_continue:;
if (table->s->tmp_table != NO_TMP_TABLE) 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->lock)
{ {
if (thd->locked_tables_mode != LTM_LOCK_TABLES && if (thd->locked_tables_mode != LTM_LOCK_TABLES &&
...@@ -9888,6 +9899,7 @@ do_continue:; ...@@ -9888,6 +9899,7 @@ do_continue:;
goto err_new_table_cleanup; goto err_new_table_cleanup;
} }
} }
new_table->s->table_creation_was_logged= new_table->s->table_creation_was_logged=
table->s->table_creation_was_logged; table->s->table_creation_was_logged;
/* Remove link to old table and rename the new one */ /* Remove link to old table and rename the new one */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment