summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2015-11-19 16:50:09 +0400
committerSergey Vojtovich <svoj@mariadb.org>2015-11-26 11:34:17 +0400
commit54689e1d5c358851c93d928c8ec453c929921f42 (patch)
treea52d829b99f79ffc1338947b95238eb12ab2dbd9
parent753d1f868c0fd52c2ec44a97fe116c01a38d5ffd (diff)
downloadmariadb-git-54689e1d5c358851c93d928c8ec453c929921f42.tar.gz
MDEV-8715 - Obsolete sql_alloc() in favor of THD::alloc() and thd_alloc()
The following left in semi-improved state to keep patch size reasonable: - Field operator new: left thd_alloc(current_thd) - Sql_alloc operator new: left thd_alloc(thd_get_current_thd()) - Item_args constructors: left thd_alloc(thd) - Item_func_interval::fix_length_and_dec(): no THD arg, have to call current_thd - Item_func_dyncol_exists::val_int(): same - Item_dyncol_get::val_str(): same - Item_dyncol_get::val_int(): same - Item_dyncol_get::val_real(): same - Item_dyncol_get::val_decimal(): same - Item_singlerow_subselect::fix_length_and_dec(): same
-rw-r--r--client/mysqlbinlog.cc10
-rw-r--r--sql/field.h2
-rw-r--r--sql/ha_partition.cc6
-rw-r--r--sql/item.cc6
-rw-r--r--sql/item.h20
-rw-r--r--sql/item_cmpfunc.cc11
-rw-r--r--sql/item_func.cc2
-rw-r--r--sql/item_strfunc.cc31
-rw-r--r--sql/item_strfunc.h2
-rw-r--r--sql/item_subselect.cc3
-rw-r--r--sql/mysqld.cc6
-rw-r--r--sql/mysqld.h6
-rw-r--r--sql/sp_head.cc6
-rw-r--r--sql/sp_head.h2
-rw-r--r--sql/sql_acl.cc13
-rw-r--r--sql/sql_analyse.cc2
-rw-r--r--sql/sql_class.cc28
-rw-r--r--sql/sql_class.h1
-rw-r--r--sql/sql_handler.cc2
-rw-r--r--sql/sql_lex.h4
-rw-r--r--sql/sql_list.h7
-rw-r--r--sql/sql_load.cc8
-rw-r--r--sql/sql_parse.cc8
-rw-r--r--sql/sql_partition.cc4
-rw-r--r--sql/sql_partition.h2
-rw-r--r--sql/sql_select.cc8
-rw-r--r--sql/sql_show.cc2
-rw-r--r--sql/sql_statistics.cc2
-rw-r--r--sql/sql_table.cc6
-rw-r--r--sql/sql_yacc.yy18
-rw-r--r--sql/table.cc10
-rw-r--r--sql/thr_malloc.cc13
-rw-r--r--sql/thr_malloc.h3
-rw-r--r--sql/threadpool_common.cc1
-rw-r--r--sql/tztime.cc2
-rw-r--r--sql/unireg.cc4
-rw-r--r--storage/maria/ha_maria.cc4
-rw-r--r--storage/myisam/ha_myisam.cc4
-rw-r--r--storage/myisammrg/ha_myisammrg.cc2
-rw-r--r--storage/spider/spd_table.cc2
40 files changed, 113 insertions, 160 deletions
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 1284f520ea1..5b07232f65c 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -2443,9 +2443,6 @@ end:
return retval;
}
-/* Used in sql_alloc(). Inited and freed in main() */
-MEM_ROOT s_mem_root;
-
int main(int argc, char** argv)
{
char **defaults_argv;
@@ -2458,7 +2455,6 @@ int main(int argc, char** argv)
my_init_time(); // for time functions
tzset(); // set tzname
- init_alloc_root(&s_mem_root, 16384, 0, MYF(0));
if (load_defaults("my", load_groups, &argc, &argv))
exit(1);
@@ -2569,7 +2565,6 @@ int main(int argc, char** argv)
my_fclose(result_file, MYF(0));
cleanup();
free_annotate_event();
- free_root(&s_mem_root, MYF(0));
free_defaults(defaults_argv);
my_free_open_file_info();
load_processor.destroy();
@@ -2582,11 +2577,6 @@ int main(int argc, char** argv)
}
-void *sql_alloc(size_t size)
-{
- return alloc_root(&s_mem_root, size);
-}
-
struct encryption_service_st encryption_handler=
{
0, 0, 0, 0, 0, 0, 0
diff --git a/sql/field.h b/sql/field.h
index 5ad4dcf30b3..0591914b8c7 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -610,7 +610,7 @@ public:
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
static void *operator new(size_t size) throw ()
- { return sql_alloc(size); }
+ { return thd_alloc(current_thd, size); }
static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root)
{ DBUG_ASSERT(0); }
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 0e009e76066..5d789fa31e3 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -1281,8 +1281,8 @@ static bool print_admin_msg(THD* thd, uint len,
length=(uint) (strxmov(name, db_name, ".", table_name.c_ptr_safe(), NullS) - name);
/*
TODO: switch from protocol to push_warning here. The main reason we didn't
- it yet is parallel repair. Due to following trace:
- mi_check_print_msg/push_warning/sql_alloc/my_pthread_getspecific_ptr.
+ it yet is parallel repair, which threads have no THD object accessible via
+ current_thd.
Also we likely need to lock mutex here (in both cases with protocol and
push_warning).
@@ -9058,7 +9058,7 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt)
}
m_part_info->key_algorithm= partition_info::KEY_ALGORITHM_51;
if (skip_generation ||
- !(part_buf= generate_partition_syntax(m_part_info,
+ !(part_buf= generate_partition_syntax(thd, m_part_info,
&part_buf_len,
true,
true,
diff --git a/sql/item.cc b/sql/item.cc
index 3cc50b2a0fa..18879a813b0 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1018,7 +1018,7 @@ void Item::set_name(THD *thd, const char *str, uint length, CHARSET_INFO *cs)
if (!my_charset_same(cs, system_charset_info))
{
size_t res_length;
- name= sql_strmake_with_convert(str, length, cs,
+ name= sql_strmake_with_convert(thd, str, length, cs,
MAX_ALIAS_NAME, system_charset_info,
&res_length);
name_length= res_length;
@@ -1034,7 +1034,7 @@ void Item::set_name_no_truncate(THD *thd, const char *str, uint length,
if (!my_charset_same(cs, system_charset_info))
{
size_t res_length;
- name= sql_strmake_with_convert(str, length, cs,
+ name= sql_strmake_with_convert(thd, str, length, cs,
UINT_MAX, system_charset_info,
&res_length);
name_length= res_length;
@@ -8483,7 +8483,7 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item)
Item *new_item= NULL;
Item_result res_type= item_cmp_type(comp_item, item);
- char *name=item->name; // Alloced by sql_alloc
+ char *name= item->name; // Alloced on THD::mem_root
MEM_ROOT *mem_root= thd->mem_root;
switch (res_type) {
diff --git a/sql/item.h b/sql/item.h
index 5c377c7f998..4a0629c2a11 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -696,7 +696,7 @@ public:
bool with_subselect; /* If this item is a subselect or some
of its arguments is or contains a
subselect */
- // alloc & destruct is done as start of select using sql_alloc
+ // alloc & destruct is done as start of select on THD::mem_root
Item(THD *thd);
/*
Constructor used by Item_field, Item_ref & aggregate (sum) functions.
@@ -3560,28 +3560,28 @@ public:
{
args[0]= a; args[1]= b;
}
- Item_args(Item *a, Item *b, Item *c)
+ Item_args(THD *thd, Item *a, Item *b, Item *c)
{
arg_count= 0;
- if ((args= (Item**) sql_alloc(sizeof(Item*) * 3)))
+ if ((args= (Item**) thd_alloc(thd, sizeof(Item*) * 3)))
{
arg_count= 3;
args[0]= a; args[1]= b; args[2]= c;
}
}
- Item_args(Item *a, Item *b, Item *c, Item *d)
+ Item_args(THD *thd, Item *a, Item *b, Item *c, Item *d)
{
arg_count= 0;
- if ((args= (Item**) sql_alloc(sizeof(Item*) * 4)))
+ if ((args= (Item**) thd_alloc(thd, sizeof(Item*) * 4)))
{
arg_count= 4;
args[0]= a; args[1]= b; args[2]= c; args[3]= d;
}
}
- Item_args(Item *a, Item *b, Item *c, Item *d, Item* e)
+ Item_args(THD *thd, Item *a, Item *b, Item *c, Item *d, Item* e)
{
arg_count= 5;
- if ((args= (Item**) sql_alloc(sizeof(Item*) * 5)))
+ if ((args= (Item**) thd_alloc(thd, sizeof(Item*) * 5)))
{
arg_count= 5;
args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
@@ -3791,11 +3791,11 @@ public:
Item_func_or_sum(THD *thd, Item *a, Item *b):
Item_result_field(thd), Item_args(a, b) { }
Item_func_or_sum(THD *thd, Item *a, Item *b, Item *c):
- Item_result_field(thd), Item_args(a, b, c) { }
+ Item_result_field(thd), Item_args(thd, a, b, c) { }
Item_func_or_sum(THD *thd, Item *a, Item *b, Item *c, Item *d):
- Item_result_field(thd), Item_args(a, b, c, d) { }
+ Item_result_field(thd), Item_args(thd, a, b, c, d) { }
Item_func_or_sum(THD *thd, Item *a, Item *b, Item *c, Item *d, Item *e):
- Item_result_field(thd), Item_args(a, b, c, d, e) { }
+ Item_result_field(thd), Item_args(thd, a, b, c, d, e) { }
Item_func_or_sum(THD *thd, Item_func_or_sum *item):
Item_result_field(thd, item), Item_args(thd, item),
Used_tables_and_const_cache(item) { }
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 76b8b70ed98..0c73aadbca1 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1846,8 +1846,8 @@ void Item_func_interval::fix_length_and_dec()
}
if (not_null_consts &&
- (intervals=
- (interval_range*) sql_alloc(sizeof(interval_range) * (rows - 1))))
+ (intervals= (interval_range*) current_thd->alloc(sizeof(interval_range) *
+ (rows - 1))))
{
if (use_decimal_comparison)
{
@@ -3462,7 +3462,7 @@ in_string::~in_string()
{
if (base)
{
- // base was allocated with help of sql_alloc => following is OK
+ // base was allocated on THD::mem_root => following is OK
for (uint i=0 ; i < count ; i++)
((String*) base)[i].free();
}
@@ -6567,10 +6567,9 @@ longlong Item_func_dyncol_exists::val_int()
}
else
{
- uint strlen;
+ uint strlen= nm->length() * my_charset_utf8_general_ci.mbmaxlen + 1;
uint dummy_errors;
- buf.str= (char *)sql_alloc((strlen= nm->length() *
- my_charset_utf8_general_ci.mbmaxlen + 1));
+ buf.str= (char *) current_thd->alloc(strlen);
if (buf.str)
{
buf.length=
diff --git a/sql/item_func.cc b/sql/item_func.cc
index e4f6eafffa2..a58e64f0435 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -3553,7 +3553,7 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func,
func->used_tables_and_const_cache_join(item);
f_args.arg_type[i]=item->result_type();
}
- //TODO: why all following memory is not allocated with 1 call of sql_alloc?
+ //TODO: why all following memory is not allocated with 1 thd->alloc() call?
if (!(buffers=new String[arg_count]) ||
!(f_args.args= (char**) thd->alloc(arg_count * sizeof(char *))) ||
!(f_args.lengths= (ulong*) thd->alloc(arg_count * sizeof(long))) ||
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 203fc4a7481..9dba2627660 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -4436,11 +4436,9 @@ bool Item_func_dyncol_create::prepare_arguments(THD *thd, bool force_names_arg)
}
else
{
- uint strlen;
+ uint strlen= res->length() * my_charset_utf8_general_ci.mbmaxlen + 1;
uint dummy_errors;
- char *str=
- (char *)sql_alloc((strlen= res->length() *
- my_charset_utf8_general_ci.mbmaxlen + 1));
+ char *str= (char *) thd->alloc(strlen);
if (str)
{
keys_str[i].length=
@@ -4742,7 +4740,8 @@ void Item_func_dyncol_add::print(String *str,
This function ensures that null_value is set correctly
*/
-bool Item_dyncol_get::get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp)
+bool Item_dyncol_get::get_dyn_value(THD *thd, DYNAMIC_COLUMN_VALUE *val,
+ String *tmp)
{
DYNAMIC_COLUMN dyn_str;
String *res;
@@ -4770,10 +4769,9 @@ bool Item_dyncol_get::get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp)
}
else
{
- uint strlen;
+ uint strlen= nm->length() * my_charset_utf8_general_ci.mbmaxlen + 1;
uint dummy_errors;
- buf.str= (char *)sql_alloc((strlen= nm->length() *
- my_charset_utf8_general_ci.mbmaxlen + 1));
+ buf.str= (char *) thd->alloc(strlen);
if (buf.str)
{
buf.length=
@@ -4823,7 +4821,7 @@ String *Item_dyncol_get::val_str(String *str_result)
char buff[STRING_BUFFER_USUAL_SIZE];
String tmp(buff, sizeof(buff), &my_charset_bin);
- if (get_dyn_value(&val, &tmp))
+ if (get_dyn_value(current_thd, &val, &tmp))
return NULL;
switch (val.type) {
@@ -4905,11 +4903,12 @@ null:
longlong Item_dyncol_get::val_int()
{
+ THD *thd= current_thd;
DYNAMIC_COLUMN_VALUE val;
char buff[STRING_BUFFER_USUAL_SIZE];
String tmp(buff, sizeof(buff), &my_charset_bin);
- if (get_dyn_value(&val, &tmp))
+ if (get_dyn_value(thd, &val, &tmp))
return 0;
switch (val.type) {
@@ -4930,7 +4929,6 @@ longlong Item_dyncol_get::val_int()
num= double_to_longlong(val.x.double_value, unsigned_flag, &error);
if (error)
{
- THD *thd= current_thd;
char buff[30];
sprintf(buff, "%lg", val.x.double_value);
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
@@ -4950,7 +4948,6 @@ longlong Item_dyncol_get::val_int()
num= my_strtoll10(val.x.string.value.str, &end, &error);
if (end != org_end || error > 0)
{
- THD *thd= current_thd;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_BAD_DATA,
ER_THD(thd, ER_BAD_DATA),
@@ -4987,11 +4984,12 @@ null:
double Item_dyncol_get::val_real()
{
+ THD *thd= current_thd;
DYNAMIC_COLUMN_VALUE val;
char buff[STRING_BUFFER_USUAL_SIZE];
String tmp(buff, sizeof(buff), &my_charset_bin);
- if (get_dyn_value(&val, &tmp))
+ if (get_dyn_value(thd, &val, &tmp))
return 0.0;
switch (val.type) {
@@ -5014,7 +5012,6 @@ double Item_dyncol_get::val_real()
if (end != (char*) val.x.string.value.str + val.x.string.value.length ||
error)
{
- THD *thd= current_thd;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_BAD_DATA,
ER_THD(thd, ER_BAD_DATA),
@@ -5046,11 +5043,12 @@ null:
my_decimal *Item_dyncol_get::val_decimal(my_decimal *decimal_value)
{
+ THD *thd= current_thd;
DYNAMIC_COLUMN_VALUE val;
char buff[STRING_BUFFER_USUAL_SIZE];
String tmp(buff, sizeof(buff), &my_charset_bin);
- if (get_dyn_value(&val, &tmp))
+ if (get_dyn_value(thd, &val, &tmp))
return NULL;
switch (val.type) {
@@ -5075,7 +5073,6 @@ my_decimal *Item_dyncol_get::val_decimal(my_decimal *decimal_value)
if (rc != E_DEC_OK ||
end != val.x.string.value.str + val.x.string.value.length)
{
- THD *thd= current_thd;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_BAD_DATA,
ER_THD(thd, ER_BAD_DATA),
@@ -5110,7 +5107,7 @@ bool Item_dyncol_get::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
String tmp(buff, sizeof(buff), &my_charset_bin);
bool signed_value= 0;
- if (get_dyn_value(&val, &tmp))
+ if (get_dyn_value(current_thd, &val, &tmp))
return 1; // Error
switch (val.type) {
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 2f3fe0b9eca..d2a83b2995b 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -1253,7 +1253,7 @@ public:
longlong val_int();
double val_real();
my_decimal *val_decimal(my_decimal *);
- bool get_dyn_value(DYNAMIC_COLUMN_VALUE *val, String *tmp);
+ bool get_dyn_value(THD *thd, DYNAMIC_COLUMN_VALUE *val, String *tmp);
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
void print(String *str, enum_query_type query_type);
};
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 3224362b7f7..f232d77e851 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1149,7 +1149,8 @@ void Item_singlerow_subselect::fix_length_and_dec()
}
else
{
- if (!(row= (Item_cache**) sql_alloc(sizeof(Item_cache*)*max_columns)))
+ if (!(row= (Item_cache**) current_thd->alloc(sizeof(Item_cache*) *
+ max_columns)))
return;
engine->fix_length_and_dec(row);
value= *row;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 9dcf87adecb..d22d6d453e2 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -711,7 +711,6 @@ SHOW_COMP_OPTION have_openssl;
/* Thread specific variables */
-pthread_key(MEM_ROOT**,THR_MALLOC);
pthread_key(THD*, THR_THD);
mysql_mutex_t LOCK_thread_count, LOCK_thread_cache;
mysql_mutex_t
@@ -2051,8 +2050,6 @@ static void cleanup_tls()
{
if (THR_THD)
(void)pthread_key_delete(THR_THD);
- if (THR_MALLOC)
- (void)pthread_key_delete(THR_MALLOC);
}
@@ -4082,8 +4079,7 @@ static int init_common_variables()
connection_errors_peer_addr= 0;
my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
- if (pthread_key_create(&THR_THD,NULL) ||
- pthread_key_create(&THR_MALLOC,NULL))
+ if (pthread_key_create(&THR_THD, NULL))
{
sql_print_error("Can't create thread-keys");
return 1;
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 081d89c48a4..d94a9a2b6a9 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -262,12 +262,6 @@ extern my_bool encrypt_tmp_disk_tables, encrypt_tmp_files;
extern ulong encryption_algorithm;
extern const char *encryption_algorithm_names[];
-/*
- THR_MALLOC is a key which will be used to set/get MEM_ROOT** for a thread,
- using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
-*/
-extern pthread_key(MEM_ROOT**,THR_MALLOC);
-
#ifdef HAVE_PSI_INTERFACE
#ifdef HAVE_MMAP
extern PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active,
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 51a1f9c9539..d0af0807ade 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -1184,7 +1184,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success)
/*
Switch query context. This has to be done early as this is sometimes
- allocated trough sql_alloc
+ allocated on THD::mem_root
*/
if (m_creation_ctx)
saved_creation_ctx= m_creation_ctx->set_n_backup(thd);
@@ -2291,9 +2291,9 @@ sp_head::restore_lex(THD *thd)
Put the instruction on the backpatch list, associated with the label.
*/
int
-sp_head::push_backpatch(sp_instr *i, sp_label *lab)
+sp_head::push_backpatch(THD *thd, sp_instr *i, sp_label *lab)
{
- bp_t *bp= (bp_t *)sql_alloc(sizeof(bp_t));
+ bp_t *bp= (bp_t *) thd->alloc(sizeof(bp_t));
if (!bp)
return 1;
diff --git a/sql/sp_head.h b/sql/sp_head.h
index 12b8277a3be..e96a17f813e 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -386,7 +386,7 @@ public:
/// Put the instruction on the backpatch list, associated with the label.
int
- push_backpatch(sp_instr *, sp_label *);
+ push_backpatch(THD *thd, sp_instr *, sp_label *);
/// Update all instruction with this label in the backpatch list to
/// the current position.
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 1240d5d35b2..eff54602536 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -6584,12 +6584,10 @@ bool grant_init()
static bool grant_load(THD *thd, TABLE_LIST *tables)
{
- MEM_ROOT *memex_ptr;
bool return_val= 1;
TABLE *t_table, *c_table, *p_table;
bool check_no_resolve= specialflag & SPECIAL_NO_RESOLVE;
- MEM_ROOT **save_mem_root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**,
- THR_MALLOC);
+ MEM_ROOT *save_mem_root= thd->mem_root;
ulonglong old_sql_mode= thd->variables.sql_mode;
DBUG_ENTER("grant_load");
@@ -6614,15 +6612,14 @@ static bool grant_load(THD *thd, TABLE_LIST *tables)
t_table->use_all_columns();
c_table->use_all_columns();
- memex_ptr= &grant_memroot;
- my_pthread_setspecific_ptr(THR_MALLOC, &memex_ptr);
+ thd->mem_root= &grant_memroot;
if (!t_table->file->ha_index_first(t_table->record[0]))
{
do
{
GRANT_TABLE *mem_check;
- if (!(mem_check=new (memex_ptr) GRANT_TABLE(t_table,c_table)))
+ if (!(mem_check= new (&grant_memroot) GRANT_TABLE(t_table, c_table)))
{
/* This could only happen if we are out memory */
goto end_unlock;
@@ -6667,7 +6664,7 @@ static bool grant_load(THD *thd, TABLE_LIST *tables)
{
GRANT_NAME *mem_check;
HASH *hash;
- if (!(mem_check=new (memex_ptr) GRANT_NAME(p_table, TRUE)))
+ if (!(mem_check= new (&grant_memroot) GRANT_NAME(p_table, TRUE)))
{
/* This could only happen if we are out memory */
goto end_unlock_p;
@@ -6720,7 +6717,7 @@ end_unlock_p:
p_table->file->ha_index_end();
end_unlock:
t_table->file->ha_index_end();
- my_pthread_setspecific_ptr(THR_MALLOC, save_mem_root_ptr);
+ thd->mem_root= save_mem_root;
end_index_init:
thd->variables.sql_mode= old_sql_mode;
DBUG_RETURN(return_val);
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc
index 1f801a33dcd..b2bc9fc2e87 100644
--- a/sql/sql_analyse.cc
+++ b/sql/sql_analyse.cc
@@ -134,7 +134,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
}
if (!(pc->f_info=
- (field_info**)sql_alloc(sizeof(field_info*)*field_list.elements)))
+ (field_info**) thd->alloc(sizeof(field_info*) * field_list.elements)))
goto err;
pc->f_end = pc->f_info + field_list.elements;
pc->fields = field_list;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index e95e32a5e0b..6656a84b23e 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -370,16 +370,6 @@ void thd_close_connection(THD *thd)
}
/**
- Get current THD object from thread local data
-
- @retval The THD object for the thread, NULL if not connection thread
-*/
-THD *thd_get_current_thd()
-{
- return current_thd;
-}
-
-/**
Lock data that needs protection in THD object
@param thd THD object
@@ -469,6 +459,16 @@ my_socket thd_get_fd(THD *thd)
#endif
/**
+ Get current THD object from thread local data
+
+ @retval The THD object for the thread, NULL if not connection thread
+*/
+THD *thd_get_current_thd()
+{
+ return current_thd;
+}
+
+/**
Get thread attributes for connection threads
@retval Reference to thread attribute for connection threads
@@ -2043,7 +2043,7 @@ int killed_errno(killed_state killed)
/*
Remember the location of thread info, the structure needed for
- sql_alloc() and the structure for the net buffer
+ the structure for the net buffer
*/
bool THD::store_globals()
@@ -2054,8 +2054,7 @@ bool THD::store_globals()
*/
DBUG_ASSERT(thread_stack);
- if (set_current_thd(this) ||
- my_pthread_setspecific_ptr(THR_MALLOC, &mem_root))
+ if (set_current_thd(this))
return 1;
/*
mysys_var is concurrently readable by a killer thread.
@@ -2108,7 +2107,6 @@ void THD::reset_globals()
/* Undocking the thread specific data. */
set_current_thd(0);
- my_pthread_setspecific_ptr(THR_MALLOC, NULL);
net.thd= 0;
}
@@ -3547,7 +3545,7 @@ void Query_arena::free_items()
{
Item *next;
DBUG_ENTER("Query_arena::free_items");
- /* This works because items are allocated with sql_alloc() */
+ /* This works because items are allocated on THD::mem_root */
for (; free_list; free_list= next)
{
next= free_list->next;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index aee6d560bfb..ae240ae4667 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -36,6 +36,7 @@
#include "violite.h" /* vio_is_connected */
#include "thr_lock.h" /* thr_lock_type, THR_LOCK_DATA, THR_LOCK_INFO */
#include "thr_timer.h"
+#include "thr_malloc.h"
#include "sql_digest_stream.h" // sql_digest_state
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 662fa33dc9f..e8ade81062b 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -31,7 +31,7 @@
then do { handler_items=concat(handler_items, free_list); free_list=0; }
But !!! do_command calls free_root at the end of every query and frees up
- all the sql_alloc'ed memory. It's harder to work around...
+ all the memory allocated on THD::mem_root. It's harder to work around...
*/
/*
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 8c875fc3afb..9eddd6d61ee 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -496,10 +496,6 @@ public:
enum sub_select_type linkage;
bool no_table_names_allowed; /* used for global order by */
- static void *operator new(size_t size) throw ()
- {
- return sql_alloc(size);
- }
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return (void*) alloc_root(mem_root, (uint) size); }
static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
diff --git a/sql/sql_list.h b/sql/sql_list.h
index 6f01b64df70..718306c2193 100644
--- a/sql/sql_list.h
+++ b/sql/sql_list.h
@@ -22,7 +22,8 @@
#include "my_sys.h" /* alloc_root, TRASH, MY_WME,
MY_FAE, MY_ALLOW_ZERO_PTR */
#include "m_string.h" /* bfill */
-#include "thr_malloc.h" /* sql_alloc */
+
+THD *thd_get_current_thd();
/* mysql standard class memory allocator */
@@ -31,11 +32,11 @@ class Sql_alloc
public:
static void *operator new(size_t size) throw ()
{
- return sql_alloc(size);
+ return thd_alloc(thd_get_current_thd(), size);
}
static void *operator new[](size_t size) throw ()
{
- return sql_alloc(size);
+ return thd_alloc(thd_get_current_thd(), size);
}
static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index b2180d4997a..eb13e3fbadf 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -86,7 +86,7 @@ public:
CHARSET_INFO *read_charset;
LOAD_FILE_IO_CACHE cache;
- READ_INFO(File file,uint tot_length,CHARSET_INFO *cs,
+ READ_INFO(THD *thd, File file, uint tot_length, CHARSET_INFO *cs,
String &field_term,String &line_start,String &line_term,
String &enclosed,int escape,bool get_it_from_net, bool is_fifo);
~READ_INFO();
@@ -437,7 +437,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
!(thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)))
? (*escaped)[0] : INT_MAX;
- READ_INFO read_info(file,tot_length,
+ READ_INFO read_info(thd, file, tot_length,
ex->cs ? ex->cs : thd->variables.collation_database,
*field_term,*ex->line_start, *ex->line_term, *enclosed,
info.escape_char, read_file_from_client, is_fifo);
@@ -1330,7 +1330,7 @@ READ_INFO::unescape(char chr)
*/
-READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs,
+READ_INFO::READ_INFO(THD *thd, File file_par, uint tot_length, CHARSET_INFO *cs,
String &field_term, String &line_start, String &line_term,
String &enclosed_par, int escape, bool get_it_from_net,
bool is_fifo)
@@ -1377,7 +1377,7 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs,
/* Set of a stack for unget if long terminators */
uint length= MY_MAX(cs->mbmaxlen, MY_MAX(field_term_length, line_term_length)) + 1;
set_if_bigger(length,line_start.length());
- stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
+ stack= stack_pos= (int*) thd->alloc(sizeof(int) * length);
if (!(buffer=(uchar*) my_malloc(buff_length+1,MYF(MY_THREAD_SPECIFIC))))
error=1; /* purecov: inspected */
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index efec0c42b22..52dcc7ee5d6 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -858,7 +858,7 @@ end:
}
-/* This works because items are allocated with sql_alloc() */
+/* This works because items are allocated on THD::mem_root */
void free_items(Item *item)
{
@@ -873,7 +873,7 @@ void free_items(Item *item)
}
/**
- This works because items are allocated with sql_alloc().
+ This works because items are allocated on THD::mem_root.
@note The function also handles null pointers (empty list).
*/
void cleanup_items(Item *item)
@@ -2099,7 +2099,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
{
DBUG_RETURN(1);
}
- schema_select_lex= new SELECT_LEX();
+ schema_select_lex= new (thd->mem_root) SELECT_LEX();
db.str= schema_select_lex->db= lex->select_lex.db;
schema_select_lex->table_list.first= NULL;
db.length= strlen(db.str);
@@ -2122,7 +2122,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
#else
DBUG_ASSERT(table_ident);
TABLE_LIST **query_tables_last= lex->query_tables_last;
- schema_select_lex= new SELECT_LEX();
+ schema_select_lex= new (thd->mem_root) SELECT_LEX();
/* 'parent_lex' is used in init_query() so it must be before it. */
schema_select_lex->parent_lex= lex;
schema_select_lex->init_query();
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index c155d74b7d8..832f218fb51 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -2468,7 +2468,7 @@ static int add_key_with_algorithm(File fptr, partition_info *part_info,
common queries.
*/
-char *generate_partition_syntax(partition_info *part_info,
+char *generate_partition_syntax(THD *thd, partition_info *part_info,
uint *buf_length,
bool use_sql_alloc,
bool show_partition_options,
@@ -2642,7 +2642,7 @@ char *generate_partition_syntax(partition_info *part_info,
goto close_file;
*buf_length= (uint)buffer_length;
if (use_sql_alloc)
- buf= (char*) sql_alloc(*buf_length+1);
+ buf= (char*) thd->alloc(*buf_length + 1);
else
buf= (char*) my_malloc(*buf_length+1, MYF(MY_WME));
if (!buf)
diff --git a/sql/sql_partition.h b/sql/sql_partition.h
index b560c53562d..dd352b60120 100644
--- a/sql/sql_partition.h
+++ b/sql/sql_partition.h
@@ -262,7 +262,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
Alter_table_ctx *alter_ctx,
bool *partition_changed,
bool *fast_alter_table);
-char *generate_partition_syntax(partition_info *part_info,
+char *generate_partition_syntax(THD *thd, partition_info *part_info,
uint *buf_length, bool use_sql_alloc,
bool show_partition_options,
HA_CREATE_INFO *create_info,
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 277a4297e6f..6a12c056282 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -12372,9 +12372,9 @@ static void clear_tables(JOIN *join)
class COND_CMP :public ilink {
public:
- static void *operator new(size_t size)
+ static void *operator new(size_t size, MEM_ROOT *mem_root)
{
- return (void*) sql_alloc((uint) size);
+ return alloc_root(mem_root, size);
}
static void operator delete(void *ptr __attribute__((unused)),
size_t size __attribute__((unused)))
@@ -13994,7 +13994,7 @@ change_cond_ref_to_const(THD *thd, I_List<COND_CMP> *save_list,
{
cond->marker=1;
COND_CMP *tmp2;
- if ((tmp2=new COND_CMP(and_father,func)))
+ if ((tmp2= new (thd->mem_root) COND_CMP(and_father, func)))
save_list->push_back(tmp2);
}
/*
@@ -14026,7 +14026,7 @@ change_cond_ref_to_const(THD *thd, I_List<COND_CMP> *save_list,
thd->change_item_tree(args + 1, value);
cond->marker=1;
COND_CMP *tmp2;
- if ((tmp2=new COND_CMP(and_father,func)))
+ if ((tmp2=new (thd->mem_root) COND_CMP(and_father, func)))
save_list->push_back(tmp2);
}
if (functype != Item_func::LIKE_FUNC)
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 2211d9f58ae..1fb57d1132a 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2123,7 +2123,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
char *part_syntax;
String comment_start;
table->part_info->set_show_version_string(&comment_start);
- if ((part_syntax= generate_partition_syntax(table->part_info,
+ if ((part_syntax= generate_partition_syntax(thd, table->part_info,
&part_syntax_len,
FALSE,
show_table_options,
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index a13ffc3eae1..324741fb55e 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -1677,7 +1677,7 @@ public:
}
if ((calc_state=
- (Prefix_calc_state *) sql_alloc(sizeof(Prefix_calc_state)*key_parts)))
+ (Prefix_calc_state *) thd->alloc(sizeof(Prefix_calc_state)*key_parts)))
{
uint keyno= key_info-table->key_info;
for (i= 0, state= calc_state; i < key_parts; i++, state++)
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index a165cfdf866..40032c37b1e 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1814,7 +1814,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
partition_info *part_info= lpt->table->part_info;
if (part_info)
{
- if (!(part_syntax_buf= generate_partition_syntax(part_info,
+ if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info,
&syntax_len,
TRUE, TRUE,
lpt->create_info,
@@ -1897,7 +1897,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
{
TABLE_SHARE *share= lpt->table->s;
char *tmp_part_syntax_str;
- if (!(part_syntax_buf= generate_partition_syntax(part_info,
+ if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info,
&syntax_len,
TRUE, TRUE,
lpt->create_info,
@@ -4477,7 +4477,7 @@ handler *mysql_create_frm_image(THD *thd,
We reverse the partitioning parser and generate a standard format
for syntax stored in frm file.
*/
- if (!(part_syntax_buf= generate_partition_syntax(part_info,
+ if (!(part_syntax_buf= generate_partition_syntax(thd, part_info,
&syntax_len,
TRUE, TRUE,
create_info,
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 19bde4fceae..ddc9e901f2b 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -317,7 +317,7 @@ int case_stmt_action_when(LEX *lex, Item *when, bool simple)
*/
return !MY_TEST(i) ||
- sp->push_backpatch(i, ctx->push_label(thd, empty_lex_str, 0)) ||
+ sp->push_backpatch(thd, i, ctx->push_label(thd, empty_lex_str, 0)) ||
sp->add_cont_backpatch(i) ||
sp->add_instr(i);
}
@@ -351,7 +351,7 @@ int case_stmt_action_then(LEX *lex)
(jump from instruction 4 to 12, 7 to 12 ... in the example)
*/
- return sp->push_backpatch(i, ctx->last_label());
+ return sp->push_backpatch(lex->thd, i, ctx->last_label());
}
static bool
@@ -3131,10 +3131,10 @@ sp_decl:
/* For continue handlers, mark end of handler scope. */
if ($2 == sp_handler::CONTINUE &&
- sp->push_backpatch(i, ctx->last_label()))
+ sp->push_backpatch(thd, i, ctx->last_label()))
MYSQL_YYABORT;
- if (sp->push_backpatch(i, ctx->push_label(thd, empty_lex_str, 0)))
+ if (sp->push_backpatch(thd, i, ctx->push_label(thd, empty_lex_str, 0)))
MYSQL_YYABORT;
}
sp_hcond_list sp_proc_stmt
@@ -3159,7 +3159,7 @@ sp_decl:
sp_instr_hreturn(sp->instructions(), ctx);
if (i == NULL ||
sp->add_instr(i) ||
- sp->push_backpatch(i, lex->spcont->last_label())) /* Block end */
+ sp->push_backpatch(thd, i, lex->spcont->last_label())) /* Block end */
MYSQL_YYABORT;
}
lex->sphead->backpatch(hlab);
@@ -3858,7 +3858,7 @@ sp_proc_stmt_leave:
i= new (lex->thd->mem_root) sp_instr_jump(ip, ctx);
if (i == NULL)
MYSQL_YYABORT;
- sp->push_backpatch(i, lab); /* Jumping forward */
+ sp->push_backpatch(thd, i, lab); /* Jumping forward */
sp->add_instr(i);
}
}
@@ -4035,7 +4035,7 @@ sp_if:
sp_instr_jump_if_not *i= new (lex->thd->mem_root)
sp_instr_jump_if_not(ip, ctx, $2, lex);
if (i == NULL ||
- sp->push_backpatch(i, ctx->push_label(thd, empty_lex_str, 0)) ||
+ sp->push_backpatch(thd, i, ctx->push_label(thd, empty_lex_str, 0)) ||
sp->add_cont_backpatch(i) ||
sp->add_instr(i))
MYSQL_YYABORT;
@@ -4052,7 +4052,7 @@ sp_if:
sp->add_instr(i))
MYSQL_YYABORT;
sp->backpatch(ctx->pop_label());
- sp->push_backpatch(i, ctx->push_label(thd, empty_lex_str, 0));
+ sp->push_backpatch(thd, i, ctx->push_label(thd, empty_lex_str, 0));
}
sp_elseifs
{
@@ -4378,7 +4378,7 @@ sp_control_content:
sp_instr_jump_if_not(ip, lex->spcont, $3, lex);
if (i == NULL ||
/* Jumping forward */
- sp->push_backpatch(i, lex->spcont->last_label()) ||
+ sp->push_backpatch(thd, i, lex->spcont->last_label()) ||
sp->new_cont_backpatch(i) ||
sp->add_instr(i))
MYSQL_YYABORT;
diff --git a/sql/table.cc b/sql/table.cc
index ea21e647d30..933cfaaf27e 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -948,12 +948,10 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
plugin_ref se_plugin= 0;
keyinfo= &first_keyinfo;
share->ext_key_parts= 0;
- MEM_ROOT **root_ptr, *old_root;
+ MEM_ROOT *old_root= thd->mem_root;
DBUG_ENTER("TABLE_SHARE::init_from_binary_frm_image");
- root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
- old_root= *root_ptr;
- *root_ptr= &share->mem_root;
+ thd->mem_root= &share->mem_root;
if (write && write_frm_image(frm_image, frm_length))
goto err;
@@ -2087,7 +2085,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
share->db_plugin= se_plugin;
share->error= OPEN_FRM_OK;
thd->status_var.opened_shares++;
- *root_ptr= old_root;
+ thd->mem_root= old_root;
DBUG_RETURN(0);
err:
@@ -2100,7 +2098,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (!thd->is_error())
open_table_error(share, OPEN_FRM_CORRUPTED, share->open_errno);
- *root_ptr= old_root;
+ thd->mem_root= old_root;
DBUG_RETURN(HA_ERR_NOT_A_TABLE);
}
diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc
index e722b5a21a5..cbed769a424 100644
--- a/sql/thr_malloc.cc
+++ b/sql/thr_malloc.cc
@@ -66,16 +66,7 @@ void init_sql_alloc(MEM_ROOT *mem_root, uint block_size, uint pre_alloc,
}
-#ifndef MYSQL_CLIENT
-void *sql_alloc(size_t Size)
-{
- MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**,THR_MALLOC);
- return alloc_root(root,Size);
-}
-#endif
-
-
-char *sql_strmake_with_convert(const char *str, size_t arg_length,
+char *sql_strmake_with_convert(THD *thd, const char *str, size_t arg_length,
CHARSET_INFO *from_cs,
size_t max_res_length,
CHARSET_INFO *to_cs, size_t *result_length)
@@ -85,7 +76,7 @@ char *sql_strmake_with_convert(const char *str, size_t arg_length,
max_res_length--; // Reserve place for end null
set_if_smaller(new_length, max_res_length);
- if (!(pos= (char*) sql_alloc(new_length+1)))
+ if (!(pos= (char*) thd->alloc(new_length + 1)))
return pos; // Error
if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))
diff --git a/sql/thr_malloc.h b/sql/thr_malloc.h
index d35207c655a..fc23c87c9fd 100644
--- a/sql/thr_malloc.h
+++ b/sql/thr_malloc.h
@@ -22,8 +22,7 @@ typedef struct st_mem_root MEM_ROOT;
void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size,
myf my_flags);
-void *sql_alloc(size_t);
-char *sql_strmake_with_convert(const char *str, size_t arg_length,
+char *sql_strmake_with_convert(THD *thd, const char *str, size_t arg_length,
CHARSET_INFO *from_cs,
size_t max_res_length,
CHARSET_INFO *to_cs, size_t *result_length);
diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc
index 9e0cb07b86c..97352e401d4 100644
--- a/sql/threadpool_common.cc
+++ b/sql/threadpool_common.cc
@@ -87,7 +87,6 @@ struct Worker_thread_context
#endif
pthread_setspecific(THR_KEY_mysys,mysys_var);
pthread_setspecific(THR_THD, 0);
- pthread_setspecific(THR_MALLOC, 0);
}
};
diff --git a/sql/tztime.cc b/sql/tztime.cc
index 5e5f34f29a5..f94e10c4877 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -1800,8 +1800,6 @@ end:
delete thd;
if (org_thd)
org_thd->store_globals(); /* purecov: inspected */
- else
- my_pthread_setspecific_ptr(THR_MALLOC, 0);
default_tz= default_tz_name ? global_system_variables.time_zone
: my_tz_SYSTEM;
diff --git a/sql/unireg.cc b/sql/unireg.cc
index 16f7751ad5d..f565fc97d86 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -921,9 +921,7 @@ static bool make_empty_rec(THD *thd, uchar *buff, uint table_options,
thd->count_cuted_fields= CHECK_FIELD_WARN; // To find wrong default values
while ((field=it++))
{
- /*
- regfield don't have to be deleted as it's allocated with sql_alloc()
- */
+ /* regfield don't have to be deleted as it's allocated on THD::mem_root */
Field *regfield= make_field(&share, thd->mem_root,
buff+field->offset + data_offset,
field->length,
diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc
index 5fdd2a920a5..2e2aa71b744 100644
--- a/storage/maria/ha_maria.cc
+++ b/storage/maria/ha_maria.cc
@@ -435,8 +435,8 @@ static void _ma_check_print_msg(HA_CHECK *param, const char *msg_type,
NullS) - name);
/*
TODO: switch from protocol to push_warning here. The main reason we didn't
- it yet is parallel repair. Due to following trace:
- ma_check_print_msg/push_warning/sql_alloc/my_pthread_getspecific_ptr.
+ it yet is parallel repair, which threads have no THD object accessible via
+ current_thd.
Also we likely need to lock mutex here (in both cases with protocol and
push_warning).
diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc
index 3029909e79f..0d040b30e08 100644
--- a/storage/myisam/ha_myisam.cc
+++ b/storage/myisam/ha_myisam.cc
@@ -166,8 +166,8 @@ static void mi_check_print_msg(HA_CHECK *param, const char* msg_type,
name);
/*
TODO: switch from protocol to push_warning here. The main reason we didn't
- it yet is parallel repair. Due to following trace:
- mi_check_print_msg/push_warning/sql_alloc/my_pthread_getspecific_ptr.
+ it yet is parallel repair, which threads have no THD object accessible via
+ current_thd.
Also we likely need to lock mutex here (in both cases with protocol and
push_warning).
diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc
index 05d5ef1d6ca..418e09547da 100644
--- a/storage/myisammrg/ha_myisammrg.cc
+++ b/storage/myisammrg/ha_myisammrg.cc
@@ -100,7 +100,7 @@
#include "../myisam/ha_myisam.h"
#include "ha_myisammrg.h"
#include "myrg_def.h"
-#include "thr_malloc.h" // int_sql_alloc
+#include "thr_malloc.h" // init_sql_alloc
#include "sql_class.h" // THD
#include "debug_sync.h"
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index bb3cb139231..34f37686850 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -8504,7 +8504,7 @@ int spider_discover_table_structure(
DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM);
}
#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE_COMMENT
- if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len,
+ if (!(part_syntax = generate_partition_syntax(thd, part_info, &part_syntax_len,
FALSE, TRUE, info, NULL, NULL)))
#else
if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len,