Commit 0e91e0c3 authored by Sergey Vojtovich's avatar Sergey Vojtovich

A proper State_tracker::m_changed enacpsulation

Note: preserved original behaviour, where remaining trackers are not reset
on error from store(). This effectively means subsequent statements will
start tracking from unclean state.

Part of MDEV-14984 - regression in connect performance
parent 879878e4
...@@ -209,7 +209,6 @@ class Session_sysvars_tracker : public State_tracker ...@@ -209,7 +209,6 @@ class Session_sysvars_tracker : public State_tracker
return result; return result;
} }
void reset();
bool enable(THD *thd); bool enable(THD *thd);
bool check_str(THD *thd, LEX_STRING *val); bool check_str(THD *thd, LEX_STRING *val);
bool update(THD *thd, set_var *var); bool update(THD *thd, set_var *var);
...@@ -241,7 +240,6 @@ class Current_schema_tracker : public State_tracker ...@@ -241,7 +240,6 @@ class Current_schema_tracker : public State_tracker
{ {
private: private:
bool schema_track_inited; bool schema_track_inited;
void reset();
public: public:
...@@ -272,17 +270,11 @@ class Current_schema_tracker : public State_tracker ...@@ -272,17 +270,11 @@ class Current_schema_tracker : public State_tracker
class Session_state_change_tracker : public State_tracker class Session_state_change_tracker : public State_tracker
{ {
private:
void reset();
public: public:
Session_state_change_tracker();
bool enable(THD *thd) bool enable(THD *thd)
{ return update(thd, NULL); }; { return update(thd, NULL); };
bool update(THD *thd, set_var *var); bool update(THD *thd, set_var *var);
bool store(THD *thd, String *buf); bool store(THD *thd, String *buf);
bool is_state_changed(THD*);
}; };
...@@ -829,7 +821,7 @@ bool Session_sysvars_tracker::store(THD *thd, String *buf) ...@@ -829,7 +821,7 @@ bool Session_sysvars_tracker::store(THD *thd, String *buf)
if (orig_list->store(thd, buf)) if (orig_list->store(thd, buf))
return true; return true;
reset(); orig_list->reset();
return false; return false;
} }
...@@ -892,17 +884,6 @@ void Session_sysvars_tracker::vars_list::reset() ...@@ -892,17 +884,6 @@ void Session_sysvars_tracker::vars_list::reset()
my_hash_iterate(&m_registered_sysvars, &reset_variable, NULL); my_hash_iterate(&m_registered_sysvars, &reset_variable, NULL);
} }
/**
Prepare/reset the m_registered_sysvars hash for next statement.
*/
void Session_sysvars_tracker::reset()
{
orig_list->reset();
m_changed= false;
}
static Session_sysvars_tracker* sysvar_tracker(THD *thd) static Session_sysvars_tracker* sysvar_tracker(THD *thd)
{ {
return (Session_sysvars_tracker*) return (Session_sysvars_tracker*)
...@@ -991,24 +972,10 @@ bool Current_schema_tracker::store(THD *thd, String *buf) ...@@ -991,24 +972,10 @@ bool Current_schema_tracker::store(THD *thd, String *buf)
/* Length and current schema name */ /* Length and current schema name */
buf->q_net_store_data((const uchar *)thd->db.str, thd->db.length); buf->q_net_store_data((const uchar *)thd->db.str, thd->db.length);
reset();
return false; return false;
} }
/**
Reset the m_changed flag for next statement.
@return void
*/
void Current_schema_tracker::reset()
{
m_changed= false;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -1331,24 +1298,13 @@ bool Transaction_state_tracker::store(THD *thd, String *buf) ...@@ -1331,24 +1298,13 @@ bool Transaction_state_tracker::store(THD *thd, String *buf)
} }
} }
reset(); tx_reported_state= tx_curr_state;
tx_changed= TX_CHG_NONE;
return false; return false;
} }
/**
Reset the m_changed flag for next statement.
*/
void Transaction_state_tracker::reset()
{
m_changed= false;
tx_reported_state= tx_curr_state;
tx_changed= TX_CHG_NONE;
}
/** /**
Helper function: turn table info into table access flag. Helper function: turn table info into table access flag.
Accepts table lock type and engine type flag (transactional/ Accepts table lock type and engine type flag (transactional/
...@@ -1518,11 +1474,6 @@ void Transaction_state_tracker::set_isol_level(THD *thd, ...@@ -1518,11 +1474,6 @@ void Transaction_state_tracker::set_isol_level(THD *thd,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
Session_state_change_tracker::Session_state_change_tracker()
{
m_changed= false;
}
/** /**
@Enable/disable the tracker based on @@session_track_state_change value. @Enable/disable the tracker based on @@session_track_state_change value.
...@@ -1560,34 +1511,12 @@ bool Session_state_change_tracker::store(THD *thd, String *buf) ...@@ -1560,34 +1511,12 @@ bool Session_state_change_tracker::store(THD *thd, String *buf)
/* Length of the overall entity (1 byte) */ /* Length of the overall entity (1 byte) */
buf->q_append('\1'); buf->q_append('\1');
DBUG_ASSERT(is_state_changed(thd)); DBUG_ASSERT(is_changed());
buf->q_append('1'); buf->q_append('1');
reset();
return false; return false;
} }
/**
Reset the m_changed flag for next statement.
*/
void Session_state_change_tracker::reset()
{
m_changed= false;
}
/**
Find if there is a session state change.
*/
bool Session_state_change_tracker::is_state_changed(THD *)
{
return m_changed;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/** /**
...@@ -1682,11 +1611,15 @@ void Session_tracker::store(THD *thd, String *buf) ...@@ -1682,11 +1611,15 @@ void Session_tracker::store(THD *thd, String *buf)
/* Get total length. */ /* Get total length. */
for (int i= 0; i < SESSION_TRACKER_END; i++) for (int i= 0; i < SESSION_TRACKER_END; i++)
{ {
if (m_trackers[i]->is_changed() && if (m_trackers[i]->is_changed())
m_trackers[i]->store(thd, buf))
{ {
buf->length(start); // it is safer to have 0-length block in case of error if (m_trackers[i]->store(thd, buf))
return; {
// it is safer to have 0-length block in case of error
buf->length(start);
return;
}
m_trackers[i]->reset_changed();
} }
} }
......
...@@ -67,6 +67,7 @@ class State_tracker ...@@ -67,6 +67,7 @@ class State_tracker
*/ */
bool m_enabled; bool m_enabled;
private:
/** Has the session state type changed ? */ /** Has the session state type changed ? */
bool m_changed; bool m_changed;
...@@ -86,6 +87,8 @@ class State_tracker ...@@ -86,6 +87,8 @@ class State_tracker
bool is_changed() const bool is_changed() const
{ return m_changed; } { return m_changed; }
void reset_changed() { m_changed= false; }
/** Called in the constructor of THD*/ /** Called in the constructor of THD*/
virtual bool enable(THD *thd)= 0; virtual bool enable(THD *thd)= 0;
...@@ -276,8 +279,6 @@ class Transaction_state_tracker : public State_tracker ...@@ -276,8 +279,6 @@ class Transaction_state_tracker : public State_tracker
/** isolation level */ /** isolation level */
enum enum_tx_isol_level tx_isol_level; enum enum_tx_isol_level tx_isol_level;
void reset();
inline void update_change_flags(THD *thd) inline void update_change_flags(THD *thd)
{ {
tx_changed &= uint(~TX_CHG_STATE); tx_changed &= uint(~TX_CHG_STATE);
......
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