Commit 7cfa803d authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-8001 - mysql_reset_thd_for_next_command() takes 0.04% in OLTP RO

Removed mysql_reset_thd_for_next_command(). Call THD::reset_for_next_command()
directly instead.

mysql_reset_thd_for_next_command() overhead dropped 0.04% -> out of radar.
THD::reset_for_next_command() overhead didn't increase.
parent 5cfb6b47
...@@ -1337,7 +1337,7 @@ Event_job_data::execute(THD *thd, bool drop) ...@@ -1337,7 +1337,7 @@ Event_job_data::execute(THD *thd, bool drop)
DBUG_ENTER("Event_job_data::execute"); DBUG_ENTER("Event_job_data::execute");
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
/* /*
MySQL parser currently assumes that current database is either MySQL parser currently assumes that current database is either
......
...@@ -5796,7 +5796,7 @@ int Load_log_event::do_apply_event(NET* net, rpl_group_info *rgi, ...@@ -5796,7 +5796,7 @@ int Load_log_event::do_apply_event(NET* net, rpl_group_info *rgi,
*/ */
lex_start(thd); lex_start(thd);
thd->lex->local_file= local_fname; thd->lex->local_file= local_fname;
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
/* /*
We test replicate_*_db rules. Note that we have already prepared We test replicate_*_db rules. Note that we have already prepared
...@@ -6539,7 +6539,7 @@ Gtid_log_event::do_apply_event(rpl_group_info *rgi) ...@@ -6539,7 +6539,7 @@ Gtid_log_event::do_apply_event(rpl_group_info *rgi)
thd->variables.gtid_domain_id= this->domain_id; thd->variables.gtid_domain_id= this->domain_id;
thd->variables.gtid_seq_no= this->seq_no; thd->variables.gtid_seq_no= this->seq_no;
rgi->gtid_ev_flags2= flags2; rgi->gtid_ev_flags2= flags2;
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
if (opt_gtid_strict_mode && opt_bin_log && opt_log_slave_updates) if (opt_gtid_strict_mode && opt_bin_log && opt_log_slave_updates)
{ {
...@@ -7347,9 +7347,9 @@ int Xid_log_event::do_apply_event(rpl_group_info *rgi) ...@@ -7347,9 +7347,9 @@ int Xid_log_event::do_apply_event(rpl_group_info *rgi)
mysql.gtid_slave_pos table with the GTID of the current transaction. mysql.gtid_slave_pos table with the GTID of the current transaction.
Therefore, it acts much like a normal SQL statement, so we need to do Therefore, it acts much like a normal SQL statement, so we need to do
mysql_reset_thd_for_next_command() as if starting a new statement. THD::reset_for_next_command() as if starting a new statement.
*/ */
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
/* /*
Record any GTID in the same transaction, so slave state is transactionally Record any GTID in the same transaction, so slave state is transactionally
consistent. consistent.
...@@ -8578,7 +8578,7 @@ int Append_block_log_event::do_apply_event(rpl_group_info *rgi) ...@@ -8578,7 +8578,7 @@ int Append_block_log_event::do_apply_event(rpl_group_info *rgi)
as the present method does not call mysql_parse(). as the present method does not call mysql_parse().
*/ */
lex_start(thd); lex_start(thd);
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
/* old copy may exist already */ /* old copy may exist already */
mysql_file_delete(key_file_log_event_data, fname, MYF(0)); mysql_file_delete(key_file_log_event_data, fname, MYF(0));
if ((fd= mysql_file_create(key_file_log_event_data, if ((fd= mysql_file_create(key_file_log_event_data,
...@@ -9640,18 +9640,18 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) ...@@ -9640,18 +9640,18 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi)
Lock_tables() reads the contents of thd->lex, so they must be Lock_tables() reads the contents of thd->lex, so they must be
initialized. initialized.
We also call the mysql_reset_thd_for_next_command(), since this We also call the THD::reset_for_next_command(), since this
is the logical start of the next "statement". Note that this is the logical start of the next "statement". Note that this
call might reset the value of current_stmt_binlog_format, so call might reset the value of current_stmt_binlog_format, so
we need to do any changes to that value after this function. we need to do any changes to that value after this function.
*/ */
delete_explain_query(thd->lex); delete_explain_query(thd->lex);
lex_start(thd); lex_start(thd);
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
/* /*
The current statement is just about to begin and The current statement is just about to begin and
has not yet modified anything. Note, all.modified is reset has not yet modified anything. Note, all.modified is reset
by mysql_reset_thd_for_next_command. by THD::reset_for_next_command().
*/ */
thd->transaction.stmt.modified_non_trans_table= FALSE; thd->transaction.stmt.modified_non_trans_table= FALSE;
thd->transaction.stmt.m_unsafe_rollback_flags&= ~THD_TRANS::DID_WAIT; thd->transaction.stmt.m_unsafe_rollback_flags&= ~THD_TRANS::DID_WAIT;
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "sql_base.h" // close_tables_for_reopen #include "sql_base.h" // close_tables_for_reopen
#include "key.h" // key_copy #include "key.h" // key_copy
#include "lock.h" // mysql_unlock_tables #include "lock.h" // mysql_unlock_tables
#include "sql_parse.h" // mysql_reset_thd_for_next_command
#include "rpl_rli.h" #include "rpl_rli.h"
#include "rpl_utility.h" #include "rpl_utility.h"
#endif #endif
...@@ -82,14 +81,14 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, rpl_group_info *rgi) ...@@ -82,14 +81,14 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, rpl_group_info *rgi)
Lock_tables() reads the contents of ev_thd->lex, so they must be Lock_tables() reads the contents of ev_thd->lex, so they must be
initialized. initialized.
We also call the mysql_reset_thd_for_next_command(), since this We also call the THD::reset_for_next_command(), since this
is the logical start of the next "statement". Note that this is the logical start of the next "statement". Note that this
call might reset the value of current_stmt_binlog_format, so call might reset the value of current_stmt_binlog_format, so
we need to do any changes to that value after this function. we need to do any changes to that value after this function.
*/ */
delete_explain_query(thd->lex); delete_explain_query(thd->lex);
lex_start(ev_thd); lex_start(ev_thd);
mysql_reset_thd_for_next_command(ev_thd); ev_thd->reset_for_next_command();
/* /*
This is a row injection, so we flag the "statement" as This is a row injection, so we flag the "statement" as
......
...@@ -533,7 +533,7 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, ...@@ -533,7 +533,7 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id,
} }
if (!in_statement) if (!in_statement)
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
DBUG_EXECUTE_IF("gtid_inject_record_gtid", DBUG_EXECUTE_IF("gtid_inject_record_gtid",
{ {
......
...@@ -1485,7 +1485,7 @@ rpl_load_gtid_slave_state(THD *thd) ...@@ -1485,7 +1485,7 @@ rpl_load_gtid_slave_state(THD *thd)
goto end; goto end;
array_inited= true; array_inited= true;
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
tlist.init_one_table(STRING_WITH_LEN("mysql"), tlist.init_one_table(STRING_WITH_LEN("mysql"),
rpl_gtid_slave_state_table_name.str, rpl_gtid_slave_state_table_name.str,
......
...@@ -2685,7 +2685,7 @@ public: ...@@ -2685,7 +2685,7 @@ public:
can not continue. In particular, disables activation of can not continue. In particular, disables activation of
CONTINUE or EXIT handlers of stored routines. CONTINUE or EXIT handlers of stored routines.
Reset in the end of processing of the current user request, in Reset in the end of processing of the current user request, in
@see mysql_reset_thd_for_next_command(). @see THD::reset_for_next_command().
*/ */
bool is_fatal_error; bool is_fatal_error;
/** /**
......
...@@ -1593,7 +1593,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1593,7 +1593,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
break; break;
} }
packet= arg_end + 1; packet= arg_end + 1;
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
lex_start(thd); lex_start(thd);
/* Must be before we init the table list. */ /* Must be before we init the table list. */
if (lower_case_table_names) if (lower_case_table_names)
...@@ -6723,15 +6723,8 @@ bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize) ...@@ -6723,15 +6723,8 @@ bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize)
(prepared or conventional). It is not called by substatements of (prepared or conventional). It is not called by substatements of
routines. routines.
@todo Remove mysql_reset_thd_for_next_command and only use the
member function.
@todo Call it after we use THD for queries, not before. @todo Call it after we use THD for queries, not before.
*/ */
void mysql_reset_thd_for_next_command(THD *thd)
{
thd->reset_for_next_command();
}
void THD::reset_for_next_command() void THD::reset_for_next_command()
{ {
...@@ -7005,7 +6998,7 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, ...@@ -7005,7 +6998,7 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length,
if (thd->wsrep_conflict_state == ABORTED || if (thd->wsrep_conflict_state == ABORTED ||
thd->wsrep_conflict_state == CERT_FAILURE) thd->wsrep_conflict_state == CERT_FAILURE)
{ {
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
thd->killed= NOT_KILLED; thd->killed= NOT_KILLED;
if (is_autocommit && if (is_autocommit &&
thd->lex->sql_command != SQLCOM_SELECT && thd->lex->sql_command != SQLCOM_SELECT &&
...@@ -7101,13 +7094,13 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, ...@@ -7101,13 +7094,13 @@ void mysql_parse(THD *thd, char *rawbuf, uint length,
of (among others) lex->safe_to_cache_query and thd->server_status, of (among others) lex->safe_to_cache_query and thd->server_status,
which are reset respectively in which are reset respectively in
- lex_start() - lex_start()
- mysql_reset_thd_for_next_command() - THD::reset_for_next_command()
So, initializing the lexical analyser *before* using the query cache So, initializing the lexical analyser *before* using the query cache
is required for the cache to work properly. is required for the cache to work properly.
FIXME: cleanup the dependencies in the code to simplify this. FIXME: cleanup the dependencies in the code to simplify this.
*/ */
lex_start(thd); lex_start(thd);
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
if (query_cache_send_result_to_client(thd, rawbuf, length) <= 0) if (query_cache_send_result_to_client(thd, rawbuf, length) <= 0)
{ {
...@@ -7221,7 +7214,7 @@ bool mysql_test_parse_for_slave(THD *thd, char *rawbuf, uint length) ...@@ -7221,7 +7214,7 @@ bool mysql_test_parse_for_slave(THD *thd, char *rawbuf, uint length)
if (!(error= parser_state.init(thd, rawbuf, length))) if (!(error= parser_state.init(thd, rawbuf, length)))
{ {
lex_start(thd); lex_start(thd);
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
if (!parse_sql(thd, & parser_state, NULL, true) && if (!parse_sql(thd, & parser_state, NULL, true) &&
all_tables_not_ok(thd, lex->select_lex.table_list.first)) all_tables_not_ok(thd, lex->select_lex.table_list.first))
......
...@@ -88,7 +88,6 @@ bool alloc_query(THD *thd, const char *packet, uint packet_length); ...@@ -88,7 +88,6 @@ bool alloc_query(THD *thd, const char *packet, uint packet_length);
void mysql_init_select(LEX *lex); void mysql_init_select(LEX *lex);
void mysql_parse(THD *thd, char *rawbuf, uint length, void mysql_parse(THD *thd, char *rawbuf, uint length,
Parser_state *parser_state); Parser_state *parser_state);
void mysql_reset_thd_for_next_command(THD *thd);
bool mysql_new_select(LEX *lex, bool move_down); bool mysql_new_select(LEX *lex, bool move_down);
void create_select_for_variable(const char *var_name); void create_select_for_variable(const char *var_name);
void create_table_set_open_action_and_adjust_tables(LEX *lex); void create_table_set_open_action_and_adjust_tables(LEX *lex);
......
...@@ -2309,7 +2309,7 @@ void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length) ...@@ -2309,7 +2309,7 @@ void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length)
DBUG_PRINT("prep_query", ("%s", packet)); DBUG_PRINT("prep_query", ("%s", packet));
/* First of all clear possible warnings from the previous command */ /* First of all clear possible warnings from the previous command */
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
if (! (stmt= new Prepared_statement(thd))) if (! (stmt= new Prepared_statement(thd)))
goto end; /* out of memory: error is set in Sql_alloc */ goto end; /* out of memory: error is set in Sql_alloc */
...@@ -2700,7 +2700,7 @@ void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length) ...@@ -2700,7 +2700,7 @@ void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
packet+= 9; /* stmt_id + 5 bytes of flags */ packet+= 9; /* stmt_id + 5 bytes of flags */
/* First of all clear possible warnings from the previous command */ /* First of all clear possible warnings from the previous command */
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
if (!(stmt= find_prepared_statement(thd, stmt_id))) if (!(stmt= find_prepared_statement(thd, stmt_id)))
{ {
...@@ -2799,7 +2799,7 @@ void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length) ...@@ -2799,7 +2799,7 @@ void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length)
DBUG_ENTER("mysqld_stmt_fetch"); DBUG_ENTER("mysqld_stmt_fetch");
/* First of all clear possible warnings from the previous command */ /* First of all clear possible warnings from the previous command */
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
status_var_increment(thd->status_var.com_stmt_fetch); status_var_increment(thd->status_var.com_stmt_fetch);
if (!(stmt= find_prepared_statement(thd, stmt_id))) if (!(stmt= find_prepared_statement(thd, stmt_id)))
...@@ -2859,7 +2859,7 @@ void mysqld_stmt_reset(THD *thd, char *packet) ...@@ -2859,7 +2859,7 @@ void mysqld_stmt_reset(THD *thd, char *packet)
DBUG_ENTER("mysqld_stmt_reset"); DBUG_ENTER("mysqld_stmt_reset");
/* First of all clear possible warnings from the previous command */ /* First of all clear possible warnings from the previous command */
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
status_var_increment(thd->status_var.com_stmt_reset); status_var_increment(thd->status_var.com_stmt_reset);
if (!(stmt= find_prepared_statement(thd, stmt_id))) if (!(stmt= find_prepared_statement(thd, stmt_id)))
......
...@@ -192,7 +192,7 @@ void wsrep_replay_transaction(THD *thd) ...@@ -192,7 +192,7 @@ void wsrep_replay_transaction(THD *thd)
thd->wsrep_conflict_state= REPLAYING; thd->wsrep_conflict_state= REPLAYING;
mysql_mutex_unlock(&thd->LOCK_wsrep_thd); mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
mysql_reset_thd_for_next_command(thd); thd->reset_for_next_command();
thd->killed= NOT_KILLED; thd->killed= NOT_KILLED;
close_thread_tables(thd); close_thread_tables(thd);
if (thd->locked_tables_mode && thd->lock) if (thd->locked_tables_mode && thd->lock)
......
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