Skip to content

Commit 01e8f3c

Browse files
committed
Allocate orig_list statically
tool_list is a temporary list needed only for SET SESSION session_track_system_variables, so allocate it on stack instead. Sane reinit() calls. Saves 2 new/delete per connection. Part of MDEV-14984 - regression in connect performance
1 parent 55bdd7f commit 01e8f3c

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

sql/session_tracker.cc

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ class Session_sysvars_tracker : public State_tracker
9898
my_hash_element(&m_registered_sysvars, i));
9999
}
100100
public:
101-
vars_list() :
102-
buffer_length(0)
101+
vars_list(): buffer_length(0), track_all(false)
103102
{
104103
m_mem_flag= current_thd ? MY_THREAD_SPECIFIC : 0;
105104
init();
@@ -150,30 +149,16 @@ class Session_sysvars_tracker : public State_tracker
150149
Two objects of vars_list type are maintained to manage
151150
various operations.
152151
*/
153-
vars_list *orig_list, *tool_list;
152+
vars_list orig_list;
154153

155154
public:
156-
Session_sysvars_tracker()
157-
{
158-
orig_list= new (std::nothrow) vars_list();
159-
tool_list= new (std::nothrow) vars_list();
160-
}
161-
162-
~Session_sysvars_tracker()
163-
{
164-
if (orig_list)
165-
delete orig_list;
166-
if (tool_list)
167-
delete tool_list;
168-
}
169-
170155
size_t get_buffer_length()
171156
{
172-
return orig_list->get_buffer_length();
157+
return orig_list.get_buffer_length();
173158
}
174159
bool construct_var_list(char *buf, size_t buf_len)
175160
{
176-
return orig_list->construct_var_list(buf, buf_len);
161+
return orig_list.construct_var_list(buf, buf_len);
177162
}
178163

179164
bool enable(THD *thd);
@@ -249,7 +234,6 @@ void Session_sysvars_tracker::vars_list::reinit()
249234

250235
void Session_sysvars_tracker::vars_list::copy(vars_list* from, THD *thd)
251236
{
252-
reinit();
253237
track_all= from->track_all;
254238
free_hash();
255239
buffer_length= from->buffer_length;
@@ -271,10 +255,7 @@ bool Session_sysvars_tracker::vars_list::insert(const sys_var *svar)
271255
sysvar_node_st *node;
272256
if (!(node= (sysvar_node_st *) my_malloc(sizeof(sysvar_node_st),
273257
MYF(MY_WME | m_mem_flag))))
274-
{
275-
reinit();
276258
return true;
277-
}
278259

279260
node->m_svar= (sys_var *)svar;
280261
node->test_load= node->m_svar->test_load;
@@ -285,7 +266,6 @@ bool Session_sysvars_tracker::vars_list::insert(const sys_var *svar)
285266
if (!search((sys_var *)svar))
286267
{
287268
//EOF (error is already reported)
288-
reinit();
289269
return true;
290270
}
291271
}
@@ -322,7 +302,6 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
322302
const char separator= ',';
323303
char *token, *lasts= NULL;
324304
size_t rest= var_list.length;
325-
reinit();
326305

327306
if (!var_list.str || var_list.length == 0)
328307
{
@@ -573,14 +552,13 @@ bool Session_sysvars_tracker::enable(THD *thd)
573552
LEX_STRING tmp;
574553
tmp.str= global_system_variables.session_track_system_variables;
575554
tmp.length= safe_strlen(tmp.str);
576-
if (tool_list->parse_var_list(thd, tmp,
577-
true, thd->charset(), false) == true)
555+
if (orig_list.parse_var_list(thd, tmp, true, thd->charset(), false) == true)
578556
{
579557
mysql_mutex_unlock(&LOCK_plugin);
558+
orig_list.reinit();
580559
return true;
581560
}
582561
mysql_mutex_unlock(&LOCK_plugin);
583-
orig_list->copy(tool_list, thd);
584562
m_enabled= true;
585563

586564
return false;
@@ -593,6 +571,9 @@ bool Session_sysvars_tracker::enable(THD *thd)
593571
Session_sysvars_tracker::vars_list::copy updating the hash in orig_list
594572
which represents the system variables to be tracked.
595573
574+
We are doing via tool list because there possible errors with memory
575+
in this case value will be unchanged.
576+
596577
@note This function is called from the ON_UPDATE() function of the
597578
session_track_system_variables' sys_var class.
598579
@@ -604,15 +585,11 @@ bool Session_sysvars_tracker::enable(THD *thd)
604585

605586
bool Session_sysvars_tracker::update(THD *thd, set_var *var)
606587
{
607-
/*
608-
We are doing via tool list because there possible errors with memory
609-
in this case value will be unchanged.
610-
*/
611-
tool_list->reinit();
612-
if (tool_list->parse_var_list(thd, var->save_result.string_value, true,
613-
thd->charset(), true))
588+
vars_list tool_list;
589+
if (tool_list.parse_var_list(thd, var->save_result.string_value, true,
590+
thd->charset(), true))
614591
return true;
615-
orig_list->copy(tool_list, thd);
592+
orig_list.copy(&tool_list, thd);
616593
return false;
617594
}
618595

@@ -694,13 +671,13 @@ bool Session_sysvars_tracker::vars_list::store(THD *thd, String *buf)
694671

695672
bool Session_sysvars_tracker::store(THD *thd, String *buf)
696673
{
697-
if (!orig_list->is_enabled())
674+
if (!orig_list.is_enabled())
698675
return false;
699676

700-
if (orig_list->store(thd, buf))
677+
if (orig_list.store(thd, buf))
701678
return true;
702679

703-
orig_list->reset();
680+
orig_list.reset();
704681

705682
return false;
706683
}
@@ -721,7 +698,7 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd,
721698
Check if the specified system variable is being tracked, if so
722699
mark it as changed and also set the class's m_changed flag.
723700
*/
724-
if (orig_list->is_enabled() && (node= orig_list->insert_or_search(svar)))
701+
if (orig_list.is_enabled() && (node= orig_list.insert_or_search(svar)))
725702
{
726703
node->m_changed= true;
727704
State_tracker::mark_as_changed(thd, var);

0 commit comments

Comments
 (0)