diff --git a/sql/handler.cc b/sql/handler.cc index 5a577f93792..0fdf8596f51 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -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) { diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 87719717faa..2b1ca706ab5 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -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 diff --git a/sql/sql_base.cc b/sql/sql_base.cc index f6814e733a6..0a1ddde9efc 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -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); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 3da63dc187e..967547b3750 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -4640,7 +4640,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List *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; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 10244d2e7ef..fce59358a19 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -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 diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 65f8e42a4ca..63c5c27a4eb 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -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); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index ad39e9c8798..56500f2b2d5 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -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, diff --git a/sql/table.cc b/sql/table.cc index 17b577502f8..7432af927e5 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -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; diff --git a/sql/table.h b/sql/table.h index 6084701b913..0859103f203 100644 --- a/sql/table.h +++ b/sql/table.h @@ -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); diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc index 671240cb3f6..117170a5dc6 100644 --- a/sql/temporary_tables.cc +++ b/sql/temporary_tables.cc @@ -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 diff --git a/storage/oqgraph/ha_oqgraph.cc b/storage/oqgraph/ha_oqgraph.cc index b888501740e..8d1a237fc43 100644 --- a/storage/oqgraph/ha_oqgraph.cc +++ b/storage/oqgraph/ha_oqgraph.cc @@ -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`