Commit 4fd771ce authored by Mikael Ronstrom's avatar Mikael Ronstrom

WL#5138, Fixed according to code review comments from Davi

parent 9d625dca
...@@ -3055,8 +3055,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli, ...@@ -3055,8 +3055,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
rpl_filter->db_ok(thd->db)) rpl_filter->db_ok(thd->db))
{ {
thd->set_time((time_t)when); thd->set_time((time_t)when);
thd->set_query((char*)query_arg, q_len_arg); thd->set_query_and_id((char*)query_arg, q_len_arg, next_query_id());
thd->query_id = next_query_id();
thd->variables.pseudo_thread_id= thread_id; // for temp tables thd->variables.pseudo_thread_id= thread_id; // for temp tables
DBUG_PRINT("query",("%s", thd->query())); DBUG_PRINT("query",("%s", thd->query()));
...@@ -8068,7 +8067,7 @@ int Table_map_log_event::do_apply_event(Relay_log_info const *rli) ...@@ -8068,7 +8067,7 @@ int Table_map_log_event::do_apply_event(Relay_log_info const *rli)
DBUG_ASSERT(rli->sql_thd == thd); DBUG_ASSERT(rli->sql_thd == thd);
/* Step the query id to mark what columns that are actually used. */ /* Step the query id to mark what columns that are actually used. */
thd->query_id= next_query_id(); thd->set_query_id(next_query_id());
if (!(memory= my_multi_malloc(MYF(MY_WME), if (!(memory= my_multi_malloc(MYF(MY_WME),
&table_list, (uint) sizeof(RPL_TABLE_LIST), &table_list, (uint) sizeof(RPL_TABLE_LIST),
......
...@@ -1338,7 +1338,7 @@ sp_head::execute(THD *thd) ...@@ -1338,7 +1338,7 @@ sp_head::execute(THD *thd)
/* To avoid wiping out thd->change_list on old_change_list destruction */ /* To avoid wiping out thd->change_list on old_change_list destruction */
old_change_list.empty(); old_change_list.empty();
thd->lex= old_lex; thd->lex= old_lex;
thd->query_id= old_query_id; thd->set_query_id(old_query_id);
DBUG_ASSERT(!thd->derived_tables); DBUG_ASSERT(!thd->derived_tables);
thd->derived_tables= old_derived_tables; thd->derived_tables= old_derived_tables;
thd->variables.sql_mode= save_sql_mode; thd->variables.sql_mode= save_sql_mode;
...@@ -2736,7 +2736,7 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp, ...@@ -2736,7 +2736,7 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp,
*/ */
thd->lex= m_lex; thd->lex= m_lex;
thd->query_id= next_query_id(); thd->set_query_id(next_query_id());
if (thd->prelocked_mode == NON_PRELOCKED) if (thd->prelocked_mode == NON_PRELOCKED)
{ {
......
...@@ -3273,6 +3273,26 @@ void THD::set_query(char *query_arg, uint32 query_length_arg) ...@@ -3273,6 +3273,26 @@ void THD::set_query(char *query_arg, uint32 query_length_arg)
pthread_mutex_unlock(&LOCK_thd_data); pthread_mutex_unlock(&LOCK_thd_data);
} }
/** Assign a new value to thd->query and thd->query_id. */
void THD::set_query_and_id(char *query_arg, uint32 query_length_arg,
query_id_t new_query_id)
{
pthread_mutex_lock(&LOCK_thd_data);
set_query_inner(query_arg, query_length_arg);
query_id= new_query_id;
pthread_mutex_unlock(&LOCK_thd_data);
}
/** Assign a new value to thd->query_id. */
void THD::set_query_id(query_id_t new_query_id)
{
pthread_mutex_lock(&LOCK_thd_data);
query_id= new_query_id;
pthread_mutex_unlock(&LOCK_thd_data);
}
/** /**
Mark transaction to rollback and mark error as fatal to a sub-statement. Mark transaction to rollback and mark error as fatal to a sub-statement.
......
...@@ -2324,10 +2324,13 @@ public: ...@@ -2324,10 +2324,13 @@ public:
virtual void set_statement(Statement *stmt); virtual void set_statement(Statement *stmt);
/** /**
Assign a new value to thd->query. Assign a new value to thd->query and thd->query_id.
Protected with LOCK_thd_data mutex. Protected with LOCK_thd_data mutex.
*/ */
void set_query(char *query_arg, uint32 query_length_arg); void set_query(char *query_arg, uint32 query_length_arg);
void set_query_and_id(char *query_arg, uint32 query_length_arg,
query_id_t new_query_id);
void set_query_id(query_id_t new_query_id);
private: private:
/** The current internal error handler for this thread, or NULL. */ /** The current internal error handler for this thread, or NULL. */
Internal_error_handler *m_internal_handler; Internal_error_handler *m_internal_handler;
......
...@@ -438,7 +438,7 @@ Sensitive_cursor::fetch(ulong num_rows) ...@@ -438,7 +438,7 @@ Sensitive_cursor::fetch(ulong num_rows)
thd->derived_tables= derived_tables; thd->derived_tables= derived_tables;
thd->open_tables= open_tables; thd->open_tables= open_tables;
thd->lock= lock; thd->lock= lock;
thd->query_id= query_id; thd->set_query_id(query_id);
thd->change_list= change_list; thd->change_list= change_list;
/* save references to memory allocated during fetch */ /* save references to memory allocated during fetch */
thd->set_n_backup_active_arena(this, &backup_arena); thd->set_n_backup_active_arena(this, &backup_arena);
......
...@@ -484,7 +484,7 @@ static void handle_bootstrap_impl(THD *thd) ...@@ -484,7 +484,7 @@ static void handle_bootstrap_impl(THD *thd)
query= (char *) thd->memdup_w_gap(buff, length + 1, query= (char *) thd->memdup_w_gap(buff, length + 1,
thd->db_length + 1 + thd->db_length + 1 +
QUERY_CACHE_FLAGS_SIZE); QUERY_CACHE_FLAGS_SIZE);
thd->set_query(query, length); thd->set_query_and_id(query, length, next_query_id());
DBUG_PRINT("query",("%-.4096s",thd->query())); DBUG_PRINT("query",("%-.4096s",thd->query()));
#if defined(ENABLED_PROFILING) #if defined(ENABLED_PROFILING)
thd->profiling.start_new_query(); thd->profiling.start_new_query();
...@@ -495,7 +495,6 @@ static void handle_bootstrap_impl(THD *thd) ...@@ -495,7 +495,6 @@ static void handle_bootstrap_impl(THD *thd)
We don't need to obtain LOCK_thread_count here because in bootstrap We don't need to obtain LOCK_thread_count here because in bootstrap
mode we have only one thread. mode we have only one thread.
*/ */
thd->query_id=next_query_id();
thd->set_time(); thd->set_time();
mysql_parse(thd, thd->query(), length, & found_semicolon); mysql_parse(thd, thd->query(), length, & found_semicolon);
close_thread_tables(thd); // Free tables close_thread_tables(thd); // Free tables
...@@ -1008,7 +1007,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1008,7 +1007,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
statistic_increment(thd->status_var.questions, &LOCK_status); statistic_increment(thd->status_var.questions, &LOCK_status);
query_id= next_query_id() - 1; query_id= next_query_id() - 1;
} }
thd->query_id= query_id; thd->set_query_id(query_id);
} }
inc_thread_running(); inc_thread_running();
...@@ -1275,12 +1274,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1275,12 +1274,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->security_ctx->priv_user, thd->security_ctx->priv_user,
(char *) thd->security_ctx->host_or_ip); (char *) thd->security_ctx->host_or_ip);
thd->set_query(beginning_of_next_stmt, length); thd->set_query_and_id(beginning_of_next_stmt, length, next_query_id());
/* /*
Count each statement from the client. Count each statement from the client.
*/ */
statistic_increment(thd->status_var.questions, &LOCK_status); statistic_increment(thd->status_var.questions, &LOCK_status);
thd->query_id= next_query_id();
thd->set_time(); /* Reset the query start time. */ thd->set_time(); /* Reset the query start time. */
/* TODO: set thd->lex->sql_command to SQLCOM_END here */ /* TODO: set thd->lex->sql_command to SQLCOM_END here */
mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt); mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);
......
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