diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-03-18 17:13:00 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2019-05-03 16:36:48 +0400 |
commit | 47bd06d55ec211bc4d05d616a0833629504c7edf (patch) | |
tree | 3c7b6cf75bace272be211e8354da3bbb081a5eb7 | |
parent | 01e8f3c52b349a0374c04f0765a625b5ac03a652 (diff) | |
download | mariadb-git-47bd06d55ec211bc4d05d616a0833629504c7edf.tar.gz |
Static current schema and state change trackers
Saves 2 new/delete per connection.
Part of MDEV-14984 - regression in connect performance
-rw-r--r-- | sql/session_tracker.cc | 47 | ||||
-rw-r--r-- | sql/session_tracker.h | 69 | ||||
-rw-r--r-- | sql/sys_vars.cc | 6 |
3 files changed, 63 insertions, 59 deletions
diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index 1af1c8de05a..868e8295294 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -173,43 +173,6 @@ public: }; - -/** - 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]= ¤t_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; diff --git a/sql/session_tracker.h b/sql/session_tracker.h index 8265e638f1b..ec6d21bd344 100644 --- a/sql/session_tracker.h +++ b/sql/session_tracker.h @@ -88,8 +88,18 @@ public: 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,12 +111,50 @@ public: 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 This class holds an object each for all tracker classes and provides @@ -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); diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index ac245d1ee54..bea46578148 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -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( |