Commit 47bd06d5 authored by Sergey Vojtovich's avatar Sergey Vojtovich

Static current schema and state change trackers

Saves 2 new/delete per connection.

Part of MDEV-14984 - regression in connect performance
parent 01e8f3c5
......@@ -173,43 +173,6 @@ class Session_sysvars_tracker : public State_tracker
};
/**
Current_schema_tracker,
This is a tracker class that enables & manages the tracking of current
schema for a particular connection.
*/
class Current_schema_tracker : public State_tracker
{
public:
bool update(THD *thd, set_var *var);
bool store(THD *thd, String *buf);
};
/*
Session_state_change_tracker
This is a boolean tracker class that will monitor any change that contributes
to a session state change.
Attributes that contribute to session state change include:
- Successful change to System variables
- User defined variables assignments
- temporary tables created, altered or deleted
- prepared statements added or removed
- change in current database
- change of current role
*/
class Session_state_change_tracker : public State_tracker
{
public:
bool update(THD *thd, set_var *var);
bool store(THD *thd, String *buf);
};
/* To be used in expanding the buffer. */
static const unsigned int EXTRA_ALLOC= 1024;
......@@ -1379,8 +1342,10 @@ Session_tracker::Session_tracker()
compile_time_assert((uint)SESSION_TRACK_always_at_the_end >=
(uint)SESSION_TRACKER_END);
for (int i= 0; i < SESSION_TRACKER_END; i++)
m_trackers[i]= NULL;
m_trackers[SESSION_SYSVARS_TRACKER]= 0;
m_trackers[CURRENT_SCHEMA_TRACKER]= &current_schema;
m_trackers[SESSION_STATE_CHANGE_TRACKER]= &state_change;
m_trackers[TRANSACTION_INFO_TRACKER]= 0;
}
......@@ -1402,10 +1367,6 @@ void Session_tracker::enable(THD *thd)
deinit();
m_trackers[SESSION_SYSVARS_TRACKER]=
new (std::nothrow) Session_sysvars_tracker();
m_trackers[CURRENT_SCHEMA_TRACKER]=
new (std::nothrow) Current_schema_tracker;
m_trackers[SESSION_STATE_CHANGE_TRACKER]=
new (std::nothrow) Session_state_change_tracker;
m_trackers[TRANSACTION_INFO_TRACKER]=
new (std::nothrow) Transaction_state_tracker;
......
......@@ -88,8 +88,18 @@ class State_tracker
void reset_changed() { m_changed= false; }
/** Called in the constructor of THD*/
virtual bool enable(THD *thd) { return update(thd, 0); }
/**
Called by THD::init() when new connection is being created
We may inherit m_changed from previous connection served by this THD if
connection was broken or client didn't have session tracking capability.
Thus we have to reset it here.
*/
virtual bool enable(THD *thd)
{
reset_changed();
return update(thd, 0);
}
/** To be invoked when the tracker's system variable is updated (ON_UPDATE).*/
virtual bool update(THD *thd, set_var *var)= 0;
......@@ -101,11 +111,49 @@ class State_tracker
virtual void mark_as_changed(THD *thd, LEX_CSTRING *name);
};
bool sysvartrack_validate_value(THD *thd, const char *str, size_t len);
bool sysvartrack_global_update(THD *thd, char *str, size_t len);
uchar *sysvartrack_session_value_ptr(THD *thd, const LEX_CSTRING *base);
/**
Current_schema_tracker,
This is a tracker class that enables & manages the tracking of current
schema for a particular connection.
*/
class Current_schema_tracker: public State_tracker
{
public:
bool update(THD *thd, set_var *var);
bool store(THD *thd, String *buf);
};
/*
Session_state_change_tracker
This is a boolean tracker class that will monitor any change that contributes
to a session state change.
Attributes that contribute to session state change include:
- Successful change to System variables
- User defined variables assignments
- temporary tables created, altered or deleted
- prepared statements added or removed
- change in current database
- change of current role
*/
class Session_state_change_tracker: public State_tracker
{
public:
bool update(THD *thd, set_var *var);
bool store(THD *thd, String *buf);
};
/**
Session_tracker
......@@ -130,22 +178,19 @@ class Session_tracker
}
public:
Current_schema_tracker current_schema;
Session_state_change_tracker state_change;
Session_tracker();
~Session_tracker()
{
deinit();
}
~Session_tracker() { deinit(); }
/* trick to make happy memory accounting system */
void deinit()
{
for (int i= 0; i < SESSION_TRACKER_END; i++)
{
if (m_trackers[i])
delete m_trackers[i];
m_trackers[i]= NULL;
}
delete m_trackers[SESSION_SYSVARS_TRACKER];
m_trackers[SESSION_SYSVARS_TRACKER]= 0;
delete m_trackers[TRANSACTION_INFO_TRACKER];
m_trackers[TRANSACTION_INFO_TRACKER]= 0;
}
void enable(THD *thd);
......
......@@ -6128,8 +6128,7 @@ static bool update_session_track_schema(sys_var *self, THD *thd,
enum_var_type type)
{
DBUG_ENTER("update_session_track_schema");
DBUG_RETURN(thd->session_tracker.get_tracker(CURRENT_SCHEMA_TRACKER)->
update(thd, NULL));
DBUG_RETURN(thd->session_tracker.current_schema.update(thd, NULL));
}
static Sys_var_mybool Sys_session_track_schema(
......@@ -6172,8 +6171,7 @@ static bool update_session_track_state_change(sys_var *self, THD *thd,
enum_var_type type)
{
DBUG_ENTER("update_session_track_state_change");
DBUG_RETURN(thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER)->
update(thd, NULL));
DBUG_RETURN(thd->session_tracker.state_change.update(thd, NULL));
}
static Sys_var_mybool Sys_session_track_state_change(
......
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