Commit 01e8f3c5 authored by Sergey Vojtovich's avatar Sergey Vojtovich

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
parent 55bdd7f7
...@@ -98,8 +98,7 @@ class Session_sysvars_tracker : public State_tracker ...@@ -98,8 +98,7 @@ class Session_sysvars_tracker : public State_tracker
my_hash_element(&m_registered_sysvars, i)); my_hash_element(&m_registered_sysvars, i));
} }
public: public:
vars_list() : vars_list(): buffer_length(0), track_all(false)
buffer_length(0)
{ {
m_mem_flag= current_thd ? MY_THREAD_SPECIFIC : 0; m_mem_flag= current_thd ? MY_THREAD_SPECIFIC : 0;
init(); init();
...@@ -150,30 +149,16 @@ class Session_sysvars_tracker : public State_tracker ...@@ -150,30 +149,16 @@ class Session_sysvars_tracker : public State_tracker
Two objects of vars_list type are maintained to manage Two objects of vars_list type are maintained to manage
various operations. various operations.
*/ */
vars_list *orig_list, *tool_list; vars_list orig_list;
public: public:
Session_sysvars_tracker()
{
orig_list= new (std::nothrow) vars_list();
tool_list= new (std::nothrow) vars_list();
}
~Session_sysvars_tracker()
{
if (orig_list)
delete orig_list;
if (tool_list)
delete tool_list;
}
size_t get_buffer_length() size_t get_buffer_length()
{ {
return orig_list->get_buffer_length(); return orig_list.get_buffer_length();
} }
bool construct_var_list(char *buf, size_t buf_len) bool construct_var_list(char *buf, size_t buf_len)
{ {
return orig_list->construct_var_list(buf, buf_len); return orig_list.construct_var_list(buf, buf_len);
} }
bool enable(THD *thd); bool enable(THD *thd);
...@@ -249,7 +234,6 @@ void Session_sysvars_tracker::vars_list::reinit() ...@@ -249,7 +234,6 @@ void Session_sysvars_tracker::vars_list::reinit()
void Session_sysvars_tracker::vars_list::copy(vars_list* from, THD *thd) void Session_sysvars_tracker::vars_list::copy(vars_list* from, THD *thd)
{ {
reinit();
track_all= from->track_all; track_all= from->track_all;
free_hash(); free_hash();
buffer_length= from->buffer_length; buffer_length= from->buffer_length;
...@@ -271,10 +255,7 @@ bool Session_sysvars_tracker::vars_list::insert(const sys_var *svar) ...@@ -271,10 +255,7 @@ bool Session_sysvars_tracker::vars_list::insert(const sys_var *svar)
sysvar_node_st *node; sysvar_node_st *node;
if (!(node= (sysvar_node_st *) my_malloc(sizeof(sysvar_node_st), if (!(node= (sysvar_node_st *) my_malloc(sizeof(sysvar_node_st),
MYF(MY_WME | m_mem_flag)))) MYF(MY_WME | m_mem_flag))))
{
reinit();
return true; return true;
}
node->m_svar= (sys_var *)svar; node->m_svar= (sys_var *)svar;
node->test_load= node->m_svar->test_load; node->test_load= node->m_svar->test_load;
...@@ -285,7 +266,6 @@ bool Session_sysvars_tracker::vars_list::insert(const sys_var *svar) ...@@ -285,7 +266,6 @@ bool Session_sysvars_tracker::vars_list::insert(const sys_var *svar)
if (!search((sys_var *)svar)) if (!search((sys_var *)svar))
{ {
//EOF (error is already reported) //EOF (error is already reported)
reinit();
return true; return true;
} }
} }
...@@ -322,7 +302,6 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd, ...@@ -322,7 +302,6 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
const char separator= ','; const char separator= ',';
char *token, *lasts= NULL; char *token, *lasts= NULL;
size_t rest= var_list.length; size_t rest= var_list.length;
reinit();
if (!var_list.str || var_list.length == 0) if (!var_list.str || var_list.length == 0)
{ {
...@@ -573,14 +552,13 @@ bool Session_sysvars_tracker::enable(THD *thd) ...@@ -573,14 +552,13 @@ bool Session_sysvars_tracker::enable(THD *thd)
LEX_STRING tmp; LEX_STRING tmp;
tmp.str= global_system_variables.session_track_system_variables; tmp.str= global_system_variables.session_track_system_variables;
tmp.length= safe_strlen(tmp.str); tmp.length= safe_strlen(tmp.str);
if (tool_list->parse_var_list(thd, tmp, if (orig_list.parse_var_list(thd, tmp, true, thd->charset(), false) == true)
true, thd->charset(), false) == true)
{ {
mysql_mutex_unlock(&LOCK_plugin); mysql_mutex_unlock(&LOCK_plugin);
orig_list.reinit();
return true; return true;
} }
mysql_mutex_unlock(&LOCK_plugin); mysql_mutex_unlock(&LOCK_plugin);
orig_list->copy(tool_list, thd);
m_enabled= true; m_enabled= true;
return false; return false;
...@@ -593,6 +571,9 @@ bool Session_sysvars_tracker::enable(THD *thd) ...@@ -593,6 +571,9 @@ bool Session_sysvars_tracker::enable(THD *thd)
Session_sysvars_tracker::vars_list::copy updating the hash in orig_list Session_sysvars_tracker::vars_list::copy updating the hash in orig_list
which represents the system variables to be tracked. which represents the system variables to be tracked.
We are doing via tool list because there possible errors with memory
in this case value will be unchanged.
@note This function is called from the ON_UPDATE() function of the @note This function is called from the ON_UPDATE() function of the
session_track_system_variables' sys_var class. session_track_system_variables' sys_var class.
...@@ -604,15 +585,11 @@ bool Session_sysvars_tracker::enable(THD *thd) ...@@ -604,15 +585,11 @@ bool Session_sysvars_tracker::enable(THD *thd)
bool Session_sysvars_tracker::update(THD *thd, set_var *var) bool Session_sysvars_tracker::update(THD *thd, set_var *var)
{ {
/* vars_list tool_list;
We are doing via tool list because there possible errors with memory if (tool_list.parse_var_list(thd, var->save_result.string_value, true,
in this case value will be unchanged. thd->charset(), true))
*/
tool_list->reinit();
if (tool_list->parse_var_list(thd, var->save_result.string_value, true,
thd->charset(), true))
return true; return true;
orig_list->copy(tool_list, thd); orig_list.copy(&tool_list, thd);
return false; return false;
} }
...@@ -694,13 +671,13 @@ bool Session_sysvars_tracker::vars_list::store(THD *thd, String *buf) ...@@ -694,13 +671,13 @@ bool Session_sysvars_tracker::vars_list::store(THD *thd, String *buf)
bool Session_sysvars_tracker::store(THD *thd, String *buf) bool Session_sysvars_tracker::store(THD *thd, String *buf)
{ {
if (!orig_list->is_enabled()) if (!orig_list.is_enabled())
return false; return false;
if (orig_list->store(thd, buf)) if (orig_list.store(thd, buf))
return true; return true;
orig_list->reset(); orig_list.reset();
return false; return false;
} }
...@@ -721,7 +698,7 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd, ...@@ -721,7 +698,7 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd,
Check if the specified system variable is being tracked, if so Check if the specified system variable is being tracked, if so
mark it as changed and also set the class's m_changed flag. mark it as changed and also set the class's m_changed flag.
*/ */
if (orig_list->is_enabled() && (node= orig_list->insert_or_search(svar))) if (orig_list.is_enabled() && (node= orig_list.insert_or_search(svar)))
{ {
node->m_changed= true; node->m_changed= true;
State_tracker::mark_as_changed(thd, var); State_tracker::mark_as_changed(thd, var);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment