summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/log_event.cc5
-rw-r--r--sql/sp_head.cc4
-rw-r--r--sql/sql_class.cc20
-rw-r--r--sql/sql_class.h5
-rw-r--r--sql/sql_cursor.cc2
-rw-r--r--sql/sql_parse.cc8
6 files changed, 32 insertions, 12 deletions
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 58ed5aa6a60..608f4d25cf4 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -3055,8 +3055,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
rpl_filter->db_ok(thd->db))
{
thd->set_time((time_t)when);
- thd->set_query((char*)query_arg, q_len_arg);
- thd->query_id = next_query_id();
+ thd->set_query_and_id((char*)query_arg, q_len_arg, next_query_id());
thd->variables.pseudo_thread_id= thread_id; // for temp tables
DBUG_PRINT("query",("%s", thd->query()));
@@ -8068,7 +8067,7 @@ int Table_map_log_event::do_apply_event(Relay_log_info const *rli)
DBUG_ASSERT(rli->sql_thd == thd);
/* 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),
&table_list, (uint) sizeof(RPL_TABLE_LIST),
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 705fd2f702b..dae4a03c7f5 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -1338,7 +1338,7 @@ sp_head::execute(THD *thd)
/* To avoid wiping out thd->change_list on old_change_list destruction */
old_change_list.empty();
thd->lex= old_lex;
- thd->query_id= old_query_id;
+ thd->set_query_id(old_query_id);
DBUG_ASSERT(!thd->derived_tables);
thd->derived_tables= old_derived_tables;
thd->variables.sql_mode= save_sql_mode;
@@ -2736,7 +2736,7 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp,
*/
thd->lex= m_lex;
- thd->query_id= next_query_id();
+ thd->set_query_id(next_query_id());
if (thd->prelocked_mode == NON_PRELOCKED)
{
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 60aed4ce53b..d8fb64878aa 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -3273,6 +3273,26 @@ void THD::set_query(char *query_arg, uint32 query_length_arg)
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.
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 2dd45997ee1..79e87a5ca3d 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -2324,10 +2324,13 @@ public:
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.
*/
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:
/** The current internal error handler for this thread, or NULL. */
Internal_error_handler *m_internal_handler;
diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc
index ffc3fafe55f..533b47e61da 100644
--- a/sql/sql_cursor.cc
+++ b/sql/sql_cursor.cc
@@ -438,7 +438,7 @@ Sensitive_cursor::fetch(ulong num_rows)
thd->derived_tables= derived_tables;
thd->open_tables= open_tables;
thd->lock= lock;
- thd->query_id= query_id;
+ thd->set_query_id(query_id);
thd->change_list= change_list;
/* save references to memory allocated during fetch */
thd->set_n_backup_active_arena(this, &backup_arena);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 83a54d1a59f..f2b9d613e3a 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -484,7 +484,7 @@ static void handle_bootstrap_impl(THD *thd)
query= (char *) thd->memdup_w_gap(buff, length + 1,
thd->db_length + 1 +
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()));
#if defined(ENABLED_PROFILING)
thd->profiling.start_new_query();
@@ -495,7 +495,6 @@ static void handle_bootstrap_impl(THD *thd)
We don't need to obtain LOCK_thread_count here because in bootstrap
mode we have only one thread.
*/
- thd->query_id=next_query_id();
thd->set_time();
mysql_parse(thd, thd->query(), length, & found_semicolon);
close_thread_tables(thd); // Free tables
@@ -1008,7 +1007,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
statistic_increment(thd->status_var.questions, &LOCK_status);
query_id= next_query_id() - 1;
}
- thd->query_id= query_id;
+ thd->set_query_id(query_id);
}
inc_thread_running();
@@ -1275,12 +1274,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->security_ctx->priv_user,
(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.
*/
statistic_increment(thd->status_var.questions, &LOCK_status);
- thd->query_id= next_query_id();
thd->set_time(); /* Reset the query start time. */
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);