Skip to content

Commit c1b4f3a

Browse files
committed
cleanup: extract ha_create_table_from_share()
1 parent 1fe8a1b commit c1b4f3a

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

sql/handler.cc

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6319,6 +6319,33 @@ int handler::calculate_checksum()
63196319
** Some general functions that isn't in the handler class
63206320
****************************************************************************/
63216321

6322+
static int ha_create_table_from_share(THD *thd, TABLE_SHARE *share,
6323+
HA_CREATE_INFO *create_info)
6324+
{
6325+
TABLE table;
6326+
6327+
if (open_table_from_share(thd, share, &empty_clex_str, 0, READ_ALL, 0,
6328+
&table, true))
6329+
return 1;
6330+
6331+
update_create_info_from_table(create_info, &table);
6332+
6333+
Table_path_buffer name_buff;
6334+
Lex_cstring name= table.file->get_canonical_filename(share->path, &name_buff);
6335+
int error= table.file->ha_create(name.str, &table, create_info);
6336+
6337+
if (error)
6338+
{
6339+
if (!thd->is_error())
6340+
my_error(ER_CANT_CREATE_TABLE, MYF(0), share->db.str,
6341+
share->table_name.str, error);
6342+
table.file->print_error(error, MYF(ME_WARNING));
6343+
}
6344+
6345+
(void) closefrm(&table);
6346+
return error;
6347+
}
6348+
63226349
/**
63236350
Initiates table-file and calls appropriate database-creator.
63246351
@@ -6340,12 +6367,9 @@ int ha_create_table(THD *thd, const char *path, const char *db,
63406367
LEX_CUSTRING *frm, bool skip_frm_file)
63416368
{
63426369
int error= 1;
6343-
TABLE table;
6344-
Table_path_buffer name_buff;
6345-
const char *name;
63466370
TABLE_SHARE share;
63476371
Abort_on_warning_instant_set old_abort_on_warning(thd, 0);
6348-
bool temp_table __attribute__((unused)) =
6372+
bool is_tmp __attribute__((unused)) =
63496373
create_info->options & (HA_LEX_CREATE_TMP_TABLE | HA_CREATE_TMP_ALTER);
63506374
DBUG_ENTER("ha_create_table");
63516375

@@ -6372,29 +6396,13 @@ int ha_create_table(THD *thd, const char *path, const char *db,
63726396
goto err;
63736397
}
63746398

6375-
share.m_psi= PSI_CALL_get_table_share(temp_table, &share);
6376-
6377-
if (open_table_from_share(thd, &share, &empty_clex_str, 0, READ_ALL, 0,
6378-
&table, true))
6379-
goto err;
6380-
6381-
update_create_info_from_table(create_info, &table);
6382-
6383-
name= table.file->get_canonical_filename(share.path, &name_buff).str;
6384-
6385-
error= table.file->ha_create(name, &table, create_info);
6386-
6387-
if (unlikely(error))
6399+
share.m_psi= PSI_CALL_get_table_share(is_tmp, &share);
6400+
if ((error= ha_create_table_from_share(thd, &share, create_info)))
63886401
{
6389-
if (!thd->is_error())
6390-
my_error(ER_CANT_CREATE_TABLE, MYF(0), db, table_name, error);
6391-
table.file->print_error(error, MYF(ME_WARNING));
6392-
PSI_CALL_drop_table_share(temp_table, share.db.str, (uint)share.db.length,
6393-
share.table_name.str, (uint)share.table_name.length);
6402+
PSI_CALL_drop_table_share(is_tmp, share.db.str, (uint)share.db.length,
6403+
share.table_name.str, (uint)share.table_name.length);
63946404
}
63956405

6396-
(void) closefrm(&table);
6397-
63986406
err:
63996407
free_table_share(&share);
64006408
DBUG_RETURN(error != 0);

0 commit comments

Comments
 (0)