Allocate Transaction_state_tracker statically
One less new/delete per connection. Part of MDEV-14984 - regression in connect performance
This commit is contained in:
parent
47bd06d55e
commit
a7adc2ce16
11
sql/lock.cc
11
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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[]=
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user