cleanup: init_tmp_table_share(bool thread_specific)

let the caller tell init_tmp_table_share() whether the table
should be thread_specific or not.

In particular, internal tmp tables created in the slave thread
are perfectly thread specific
This commit is contained in:
Sergei Golubchik 2024-07-18 14:43:06 +02:00
parent 44c6328cbb
commit 08a7f18b19
11 changed files with 19 additions and 23 deletions

View File

@ -6373,7 +6373,7 @@ int ha_create_table(THD *thd, const char *path, const char *db,
create_info->options & (HA_LEX_CREATE_TMP_TABLE | HA_CREATE_TMP_ALTER);
DBUG_ENTER("ha_create_table");
init_tmp_table_share(thd, &share, db, 0, table_name, path);
init_tmp_table_share(thd, &share, db, 0, table_name, path, true);
if (frm)
{

View File

@ -4833,7 +4833,7 @@ SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd)
table->in_use= thd;
table->s= share;
init_tmp_table_share(thd, share, "", 0, tmpname, tmpname);
init_tmp_table_share(thd, share, "", 0, tmpname, tmpname, true);
share->blob_field= blob_field;
share->table_charset= NULL;
share->primary_key= MAX_KEY; // Indicate no primary key

View File

@ -9491,7 +9491,7 @@ my_bool mysql_rm_tmp_tables(void)
/* We should cut file extention before deleting of table */
memcpy(path_copy, path, path_len - ext_len);
path_copy[path_len - ext_len]= 0;
init_tmp_table_share(thd, &share, "", 0, "", path_copy);
init_tmp_table_share(thd, &share, "", 0, "", path_copy, true);
if (!open_table_def(thd, &share))
share.db_type()->drop_table(share.db_type(), path_copy);
free_table_share(&share);

View File

@ -4640,7 +4640,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List<Item> *items,
DBUG_ENTER("select_create::create_table_from_items");
tmp_table.s= &share;
init_tmp_table_share(thd, &share, "", 0, "", "");
init_tmp_table_share(thd, &share, "", 0, "", "", true);
tmp_table.s->db_create_options=0;
tmp_table.null_row= 0;

View File

@ -21687,7 +21687,7 @@ TABLE *Create_tmp_table::start(THD *thd,
table->expr_arena= thd;
table->s= share;
init_tmp_table_share(thd, share, "", 0, "(temporary)", tmpname);
init_tmp_table_share(thd, share, "", 0, "(temporary)", tmpname, true);
share->blob_field= blob_field;
share->table_charset= param->table_charset;
share->primary_key= MAX_KEY; // Indicate no primary key

View File

@ -6946,7 +6946,7 @@ int store_schema_params(THD *thd, TABLE *table, TABLE *proc_table,
bzero((char*) &tbl, sizeof(TABLE));
(void) build_table_filename(path, sizeof(path), "", "", "", 0);
init_tmp_table_share(thd, &share, "", 0, "", path);
init_tmp_table_share(thd, &share, "", 0, "", path, true);
proc_table->field[MYSQL_PROC_FIELD_DB]->val_str_nopad(thd->mem_root, &db);
proc_table->field[MYSQL_PROC_FIELD_NAME]->val_str_nopad(thd->mem_root, &name);
@ -7131,7 +7131,7 @@ int store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table,
bzero((char*) &tbl, sizeof(TABLE));
(void) build_table_filename(path, sizeof(path), "", "", "", 0);
init_tmp_table_share(thd, &share, "", 0, "", path);
init_tmp_table_share(thd, &share, "", 0, "", path ,true);
store_variable_type(thd, sp->m_return_field_def,
""_Lex_ident_column, &tbl, &share, cs, table, 5);
free_table_share(&share);

View File

@ -4577,7 +4577,7 @@ int create_table_impl(THD *thd,
goto err;
}
init_tmp_table_share(thd, &share, db.str, 0, table_name.str, path.str);
init_tmp_table_share(thd, &share, db.str, 0, table_name.str, path.str, true);
/* prepare everything for discovery */
share.field= &no_fields;
@ -9884,7 +9884,7 @@ static int create_table_for_inplace_alter(THD *thd,
TABLE *table)
{
init_tmp_table_share(thd, share, alter_ctx.new_db.str, 0,
alter_ctx.new_name.str, alter_ctx.get_tmp_path());
alter_ctx.new_name.str, alter_ctx.get_tmp_path(), true);
if (share->init_from_binary_frm_image(thd, true, frm->str, frm->length) ||
open_table_from_share(thd, share, &alter_ctx.new_name, 0,
EXTRA_RECORD, thd->open_options,

View File

@ -445,19 +445,15 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
uint key_length, const char *table_name,
const char *path)
const char *path, bool thread_specific)
{
DBUG_ENTER("init_tmp_table_share");
DBUG_PRINT("enter", ("table: '%s'.'%s'", key, table_name));
bzero((char*) share, sizeof(*share));
/*
This can't be MY_THREAD_SPECIFIC for slaves as they are freed
during cleanup() from Relay_log_info::close_temporary_tables()
*/
init_sql_alloc(key_memory_table_share, &share->mem_root,
TABLE_ALLOC_BLOCK_SIZE, 0,
MYF(thd->slave_thread ? 0 : MY_THREAD_SPECIFIC));
thread_specific ? MY_THREAD_SPECIFIC : 0);
share->table_category= TABLE_CATEGORY_TEMPORARY;
share->tmp_table= INTERNAL_TMP_TABLE;
share->db.str= (char*) key;

View File

@ -3489,8 +3489,8 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table,
TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
const char *key, uint key_length);
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
uint key_length,
const char *table_name, const char *path);
uint key_length, const char *table_name,
const char *path, bool thread_specific);
void free_table_share(TABLE_SHARE *share);
enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share,
uint flags = GTS_TABLE);

View File

@ -982,8 +982,12 @@ TMP_TABLE_SHARE *THD::create_temporary_table(LEX_CUSTRING *frm,
saved_key_cache= strmov(tmp_path, path) + 1;
memcpy(saved_key_cache, key_cache, key_length);
/*
Temp tables can't be thread specific for slaves as they are freed
during cleanup() from Relay_log_info::close_temporary_tables()
*/
init_tmp_table_share(this, share, saved_key_cache, key_length,
strend(saved_key_cache) + 1, tmp_path);
strend(saved_key_cache) + 1, tmp_path, !slave_thread);
/*
Prefer using frm image over file. The image might not be available in

View File

@ -530,12 +530,8 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
error_message.length(0);
origid= destid= weight= 0;
// Here we're abusing init_tmp_table_share() which is normally only works for thread-local shares.
THD* thd = current_thd;
init_tmp_table_share( thd, share, table->s->db.str, table->s->db.length, options->table_name, "");
// because of that, we need to reinitialize the memroot (to reset MY_THREAD_SPECIFIC flag)
DBUG_ASSERT(share->mem_root.used == NULL); // it's still empty
init_sql_alloc(PSI_INSTRUMENT_ME, &share->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0));
init_tmp_table_share( thd, share, table->s->db.str, table->s->db.length, options->table_name, "", false);
// What I think this code is doing:
// * Our OQGRAPH table is `database_blah/name`