diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-03-18 19:18:54 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2019-05-03 16:40:58 +0400 |
commit | a7adc2ce1680f00635b8241202066fd5542d286f (patch) | |
tree | 78888bd51d3a47ce3393a4b3aa6728832a7167cc | |
parent | 47bd06d55ec211bc4d05d616a0833629504c7edf (diff) | |
download | mariadb-git-a7adc2ce1680f00635b8241202066fd5542d286f.tar.gz |
Allocate Transaction_state_tracker statically
One less new/delete per connection.
Part of MDEV-14984 - regression in connect performance
-rw-r--r-- | sql/lock.cc | 11 | ||||
-rw-r--r-- | sql/session_tracker.cc | 4 | ||||
-rw-r--r-- | sql/session_tracker.h | 139 | ||||
-rw-r--r-- | sql/sys_vars.cc | 11 | ||||
-rw-r--r-- | sql/sys_vars.ic | 18 | ||||
-rw-r--r-- | sql/transaction.cc | 37 |
6 files changed, 94 insertions, 126 deletions
diff --git a/sql/lock.cc b/sql/lock.cc index 5420e9f42b5..aeba6cc7504 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -252,16 +252,11 @@ static void track_table_access(THD *thd, TABLE **tables, size_t count) { if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) { - Transaction_state_tracker *tst= (Transaction_state_tracker *) - thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER); - while (count--) { - TABLE *t= tables[count]; - - if (t) - tst->add_trx_state(thd, t->reginfo.lock_type, - t->file->has_transaction_manager()); + if (TABLE *t= tables[count]) + thd->session_tracker.transaction_info.add_trx_state(thd, + t->reginfo.lock_type, t->file->has_transaction_manager()); } } } diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index 868e8295294..2f72b7198f9 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -1345,7 +1345,7 @@ Session_tracker::Session_tracker() 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; + m_trackers[TRANSACTION_INFO_TRACKER]= &transaction_info; } @@ -1367,8 +1367,6 @@ void Session_tracker::enable(THD *thd) deinit(); m_trackers[SESSION_SYSVARS_TRACKER]= new (std::nothrow) Session_sysvars_tracker(); - m_trackers[TRANSACTION_INFO_TRACKER]= - new (std::nothrow) Transaction_state_tracker; for (int i= 0; i < SESSION_TRACKER_END; i++) m_trackers[i]->enable(thd); diff --git a/sql/session_tracker.h b/sql/session_tracker.h index ec6d21bd344..faa34e88c74 100644 --- a/sql/session_tracker.h +++ b/sql/session_tracker.h @@ -154,65 +154,6 @@ public: }; -/** - Session_tracker - - This class holds an object each for all tracker classes and provides - methods necessary for systematic detection and generation of session - state change information. -*/ - -class Session_tracker -{ - State_tracker *m_trackers[SESSION_TRACKER_END]; - - /* The following two functions are private to disable copying. */ - Session_tracker(Session_tracker const &other) - { - DBUG_ASSERT(FALSE); - } - Session_tracker& operator= (Session_tracker const &rhs) - { - DBUG_ASSERT(FALSE); - return *this; - } - -public: - Current_schema_tracker current_schema; - Session_state_change_tracker state_change; - - Session_tracker(); - ~Session_tracker() { deinit(); } - - /* trick to make happy memory accounting system */ - void deinit() - { - 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); - - /** Returns the pointer to the tracker object for the specified tracker. */ - inline State_tracker *get_tracker(enum_session_tracker tracker) const - { - return m_trackers[tracker]; - } - - inline void mark_as_changed(THD *thd, enum enum_session_tracker tracker, - LEX_CSTRING *data) - { - if (m_trackers[tracker]->is_enabled()) - m_trackers[tracker]->mark_as_changed(thd, data); - } - - - void store(THD *thd, String *main_buf); -}; - - /* Transaction_state_tracker */ @@ -277,12 +218,17 @@ class Transaction_state_tracker : public State_tracker /** Helper function: turn table info into table access flag */ enum_tx_state calc_trx_state(THD *thd, thr_lock_type l, bool has_trx); public: - /** Constructor */ - Transaction_state_tracker(): tx_changed(TX_CHG_NONE), - tx_curr_state(TX_EMPTY), - tx_reported_state(TX_EMPTY), - tx_read_flags(TX_READ_INHERIT), - tx_isol_level(TX_ISOL_INHERIT) {} + + bool enable(THD *thd) + { + m_enabled= false; + tx_changed= TX_CHG_NONE; + tx_curr_state= TX_EMPTY; + tx_reported_state= TX_EMPTY; + tx_read_flags= TX_READ_INHERIT; + tx_isol_level= TX_ISOL_INHERIT; + return State_tracker::enable(thd); + } bool update(THD *thd, set_var *var); bool store(THD *thd, String *buf); @@ -332,12 +278,69 @@ private: #define TRANSACT_TRACKER(X) \ do { if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) \ - {((Transaction_state_tracker *) \ - thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER)) \ - ->X; } } while(0) + thd->session_tracker.transaction_info.X; } while(0) #define SESSION_TRACKER_CHANGED(A,B,C) \ thd->session_tracker.mark_as_changed(A,B,C) + +/** + Session_tracker + + This class holds an object each for all tracker classes and provides + methods necessary for systematic detection and generation of session + state change information. +*/ + +class Session_tracker +{ + State_tracker *m_trackers[SESSION_TRACKER_END]; + + /* The following two functions are private to disable copying. */ + Session_tracker(Session_tracker const &other) + { + DBUG_ASSERT(FALSE); + } + Session_tracker& operator= (Session_tracker const &rhs) + { + DBUG_ASSERT(FALSE); + return *this; + } + +public: + Current_schema_tracker current_schema; + Session_state_change_tracker state_change; + Transaction_state_tracker transaction_info; + + Session_tracker(); + ~Session_tracker() { deinit(); } + + /* trick to make happy memory accounting system */ + void deinit() + { + delete m_trackers[SESSION_SYSVARS_TRACKER]; + m_trackers[SESSION_SYSVARS_TRACKER]= 0; + } + + void enable(THD *thd); + + /** Returns the pointer to the tracker object for the specified tracker. */ + inline State_tracker *get_tracker(enum_session_tracker tracker) const + { + return m_trackers[tracker]; + } + + inline void mark_as_changed(THD *thd, enum enum_session_tracker tracker, + LEX_CSTRING *data) + { + if (m_trackers[tracker]->is_enabled()) + m_trackers[tracker]->mark_as_changed(thd, data); + } + + + void store(THD *thd, String *main_buf); +}; + + int session_tracker_init(); #else diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index bea46578148..004fd4baecb 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -3743,14 +3743,12 @@ bool Sys_var_tx_read_only::session_update(THD *thd, set_var *var) #ifndef EMBEDDED_LIBRARY if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) { - Transaction_state_tracker *tst= (Transaction_state_tracker *) - thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER); - if (var->type == OPT_DEFAULT) - tst->set_read_flags(thd, + thd->session_tracker.transaction_info.set_read_flags(thd, thd->tx_read_only ? TX_READ_ONLY : TX_READ_WRITE); else - tst->set_read_flags(thd, TX_READ_INHERIT); + thd->session_tracker.transaction_info.set_read_flags(thd, + TX_READ_INHERIT); } #endif //EMBEDDED_LIBRARY } @@ -6145,8 +6143,7 @@ static bool update_session_track_tx_info(sys_var *self, THD *thd, enum_var_type type) { DBUG_ENTER("update_session_track_tx_info"); - DBUG_RETURN(thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER)-> - update(thd, NULL)); + DBUG_RETURN(thd->session_tracker.transaction_info.update(thd, NULL)); } static const char *session_track_transaction_info_names[]= diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic index 7c375f16cdd..042b7c75da7 100644 --- a/sql/sys_vars.ic +++ b/sql/sys_vars.ic @@ -2219,14 +2219,6 @@ public: return TRUE; if (var->type == OPT_DEFAULT || !thd->in_active_multi_stmt_transaction()) { -#ifndef EMBEDDED_LIBRARY - Transaction_state_tracker *tst= NULL; - - if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) - tst= (Transaction_state_tracker *) - thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER); -#endif //EMBEDDED_LIBRARY - thd->tx_isolation= (enum_tx_isolation) var->save_result.ulonglong_value; #ifndef EMBEDDED_LIBRARY @@ -2250,13 +2242,11 @@ public: DBUG_ASSERT(0); return TRUE; } - if (tst) - tst->set_isol_level(thd, l); - } - else if (tst) - { - tst->set_isol_level(thd, TX_ISOL_INHERIT); + if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) + thd->session_tracker.transaction_info.set_isol_level(thd, l); } + else if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) + thd->session_tracker.transaction_info.set_isol_level(thd, TX_ISOL_INHERIT); #endif //EMBEDDED_LIBRARY } return FALSE; diff --git a/sql/transaction.cc b/sql/transaction.cc index 1c2820200d1..74f4eda881b 100644 --- a/sql/transaction.cc +++ b/sql/transaction.cc @@ -32,10 +32,7 @@ static void trans_track_end_trx(THD *thd) { if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) - { - ((Transaction_state_tracker *) - thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER))->end_trx(thd); - } + thd->session_tracker.transaction_info.end_trx(thd); } #else #define trans_track_end_trx(A) do{}while(0) @@ -51,11 +48,8 @@ void trans_reset_one_shot_chistics(THD *thd) #ifndef EMBEDDED_LIBRARY if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) { - Transaction_state_tracker *tst= (Transaction_state_tracker *) - thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER); - - tst->set_read_flags(thd, TX_READ_INHERIT); - tst->set_isol_level(thd, TX_ISOL_INHERIT); + thd->session_tracker.transaction_info.set_read_flags(thd, TX_READ_INHERIT); + thd->session_tracker.transaction_info.set_isol_level(thd, TX_ISOL_INHERIT); } #endif //EMBEDDED_LIBRARY thd->tx_isolation= (enum_tx_isolation) thd->variables.tx_isolation; @@ -162,20 +156,11 @@ static bool xa_trans_force_rollback(THD *thd) bool trans_begin(THD *thd, uint flags) { int res= FALSE; -#ifndef EMBEDDED_LIBRARY - Transaction_state_tracker *tst= NULL; -#endif //EMBEDDED_LIBRARY DBUG_ENTER("trans_begin"); if (trans_check(thd)) DBUG_RETURN(TRUE); -#ifndef EMBEDDED_LIBRARY - if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) - tst= (Transaction_state_tracker *) - thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER); -#endif //EMBEDDED_LIBRARY - thd->locked_tables_list.unlock_locked_tables(thd); DBUG_ASSERT(!thd->locked_tables_mode); @@ -221,8 +206,8 @@ bool trans_begin(THD *thd, uint flags) { thd->tx_read_only= true; #ifndef EMBEDDED_LIBRARY - if (tst) - tst->set_read_flags(thd, TX_READ_ONLY); + if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) + thd->session_tracker.transaction_info.set_read_flags(thd, TX_READ_ONLY); #endif //EMBEDDED_LIBRARY } else if (flags & MYSQL_START_TRANS_OPT_READ_WRITE) @@ -246,8 +231,8 @@ bool trans_begin(THD *thd, uint flags) just from the session's default. */ #ifndef EMBEDDED_LIBRARY - if (tst) - tst->set_read_flags(thd, TX_READ_WRITE); + if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) + thd->session_tracker.transaction_info.set_read_flags(thd, TX_READ_WRITE); #endif //EMBEDDED_LIBRARY } @@ -264,16 +249,16 @@ bool trans_begin(THD *thd, uint flags) DBUG_PRINT("info", ("setting SERVER_STATUS_IN_TRANS")); #ifndef EMBEDDED_LIBRARY - if (tst) - tst->add_trx_state(thd, TX_EXPLICIT); + if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) + thd->session_tracker.transaction_info.add_trx_state(thd, TX_EXPLICIT); #endif //EMBEDDED_LIBRARY /* ha_start_consistent_snapshot() relies on OPTION_BEGIN flag set. */ if (flags & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) { #ifndef EMBEDDED_LIBRARY - if (tst) - tst->add_trx_state(thd, TX_WITH_SNAPSHOT); + if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) + thd->session_tracker.transaction_info.add_trx_state(thd, TX_WITH_SNAPSHOT); #endif //EMBEDDED_LIBRARY res= ha_start_consistent_snapshot(thd); } |