Skip to content

Commit 269f0a6

Browse files
author
Sergei Golubchik
committed
MDEV-6619 SHOW PROCESSLIST returns empty result set after KILL QUERY
don't send an OK packet if the SHOW PROCESSLIST was killed
1 parent 3d94523 commit 269f0a6

File tree

3 files changed

+96
-65
lines changed

3 files changed

+96
-65
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
connect con1,localhost,root,,;
2+
SHOW PROCESSLIST;
3+
Id User Host db Command Time State Info Progress
4+
# root # test Sleep # # NULL 0.000
5+
# root # test Query # # SHOW PROCESSLIST 0.000
6+
connection default;
7+
KILL QUERY con_id;
8+
connection con1;
9+
SHOW PROCESSLIST;
10+
ERROR 70100: Query execution was interrupted
11+
SHOW PROCESSLIST;
12+
Id User Host db Command Time State Info Progress
13+
# root # test Sleep # # NULL 0.000
14+
# root # test Query # # SHOW PROCESSLIST 0.000
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# MDEV-6619 SHOW PROCESSLIST returns empty result set after KILL QUERY
3+
#
4+
--source include/not_embedded.inc
5+
--enable_connect_log
6+
--connect (con1,localhost,root,,)
7+
--let $con_id = `SELECT CONNECTION_ID()`
8+
--replace_column 1 # 3 # 6 # 7 #
9+
SHOW PROCESSLIST;
10+
--connection default
11+
--replace_result $con_id con_id
12+
eval KILL QUERY $con_id;
13+
--connection con1
14+
--error ER_QUERY_INTERRUPTED
15+
SHOW PROCESSLIST;
16+
--replace_column 1 # 3 # 6 # 7 #
17+
SHOW PROCESSLIST;

sql/sql_show.cc

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,77 +2178,77 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
21782178
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
21792179
DBUG_VOID_RETURN;
21802180

2181+
if (thd->killed)
2182+
DBUG_VOID_RETURN;
2183+
21812184
mysql_mutex_lock(&LOCK_thread_count); // For unlink from list
2182-
if (!thd->killed)
2185+
I_List_iterator<THD> it(threads);
2186+
THD *tmp;
2187+
while ((tmp=it++))
21832188
{
2184-
I_List_iterator<THD> it(threads);
2185-
THD *tmp;
2186-
while ((tmp=it++))
2189+
Security_context *tmp_sctx= tmp->security_ctx;
2190+
struct st_my_thread_var *mysys_var;
2191+
if ((tmp->vio_ok() || tmp->system_thread) &&
2192+
(!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
21872193
{
2188-
Security_context *tmp_sctx= tmp->security_ctx;
2189-
struct st_my_thread_var *mysys_var;
2190-
if ((tmp->vio_ok() || tmp->system_thread) &&
2191-
(!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
2194+
thread_info *thd_info= new thread_info;
2195+
2196+
thd_info->thread_id=tmp->thread_id;
2197+
thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
2198+
(tmp->system_thread ?
2199+
"system user" : "unauthenticated user"));
2200+
if (tmp->peer_port && (tmp_sctx->host || tmp_sctx->ip) &&
2201+
thd->security_ctx->host_or_ip[0])
21922202
{
2193-
thread_info *thd_info= new thread_info;
2194-
2195-
thd_info->thread_id=tmp->thread_id;
2196-
thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
2197-
(tmp->system_thread ?
2198-
"system user" : "unauthenticated user"));
2199-
if (tmp->peer_port && (tmp_sctx->host || tmp_sctx->ip) &&
2200-
thd->security_ctx->host_or_ip[0])
2201-
{
2202-
if ((thd_info->host= (char*) thd->alloc(LIST_PROCESS_HOST_LEN+1)))
2203-
my_snprintf((char *) thd_info->host, LIST_PROCESS_HOST_LEN,
2204-
"%s:%u", tmp_sctx->host_or_ip, tmp->peer_port);
2205-
}
2206-
else
2207-
thd_info->host= thd->strdup(tmp_sctx->host_or_ip[0] ?
2208-
tmp_sctx->host_or_ip :
2209-
tmp_sctx->host ? tmp_sctx->host : "");
2210-
thd_info->command=(int) tmp->command;
2211-
mysql_mutex_lock(&tmp->LOCK_thd_data);
2212-
if ((thd_info->db= tmp->db)) // Safe test
2213-
thd_info->db= thd->strdup(thd_info->db);
2214-
if ((mysys_var= tmp->mysys_var))
2215-
mysql_mutex_lock(&mysys_var->mutex);
2216-
thd_info->proc_info= (char*) (tmp->killed >= KILL_QUERY ?
2217-
"Killed" : 0);
2218-
thd_info->state_info= thread_state_info(tmp);
2219-
if (mysys_var)
2220-
mysql_mutex_unlock(&mysys_var->mutex);
2221-
2222-
/* Lock THD mutex that protects its data when looking at it. */
2223-
if (tmp->query())
2224-
{
2225-
uint length= min(max_query_length, tmp->query_length());
2226-
char *q= thd->strmake(tmp->query(),length);
2227-
/* Safety: in case strmake failed, we set length to 0. */
2228-
thd_info->query_string=
2229-
CSET_STRING(q, q ? length : 0, tmp->query_charset());
2230-
}
2203+
if ((thd_info->host= (char*) thd->alloc(LIST_PROCESS_HOST_LEN+1)))
2204+
my_snprintf((char *) thd_info->host, LIST_PROCESS_HOST_LEN,
2205+
"%s:%u", tmp_sctx->host_or_ip, tmp->peer_port);
2206+
}
2207+
else
2208+
thd_info->host= thd->strdup(tmp_sctx->host_or_ip[0] ?
2209+
tmp_sctx->host_or_ip :
2210+
tmp_sctx->host ? tmp_sctx->host : "");
2211+
thd_info->command=(int) tmp->command;
2212+
mysql_mutex_lock(&tmp->LOCK_thd_data);
2213+
if ((thd_info->db= tmp->db)) // Safe test
2214+
thd_info->db= thd->strdup(thd_info->db);
2215+
if ((mysys_var= tmp->mysys_var))
2216+
mysql_mutex_lock(&mysys_var->mutex);
2217+
thd_info->proc_info= (char*) (tmp->killed >= KILL_QUERY ?
2218+
"Killed" : 0);
2219+
thd_info->state_info= thread_state_info(tmp);
2220+
if (mysys_var)
2221+
mysql_mutex_unlock(&mysys_var->mutex);
22312222

2232-
/*
2233-
Progress report. We need to do this under a lock to ensure that all
2234-
is from the same stage.
2235-
*/
2236-
if (tmp->progress.max_counter)
2237-
{
2238-
uint max_stage= max(tmp->progress.max_stage, 1);
2239-
thd_info->progress= (((tmp->progress.stage / (double) max_stage) +
2240-
((tmp->progress.counter /
2241-
(double) tmp->progress.max_counter) /
2242-
(double) max_stage)) *
2243-
100.0);
2244-
set_if_smaller(thd_info->progress, 100);
2245-
}
2246-
else
2247-
thd_info->progress= 0.0;
2248-
thd_info->start_time= tmp->start_time;
2249-
mysql_mutex_unlock(&tmp->LOCK_thd_data);
2250-
thread_infos.append(thd_info);
2223+
/* Lock THD mutex that protects its data when looking at it. */
2224+
if (tmp->query())
2225+
{
2226+
uint length= min(max_query_length, tmp->query_length());
2227+
char *q= thd->strmake(tmp->query(),length);
2228+
/* Safety: in case strmake failed, we set length to 0. */
2229+
thd_info->query_string=
2230+
CSET_STRING(q, q ? length : 0, tmp->query_charset());
22512231
}
2232+
2233+
/*
2234+
Progress report. We need to do this under a lock to ensure that all
2235+
is from the same stage.
2236+
*/
2237+
if (tmp->progress.max_counter)
2238+
{
2239+
uint max_stage= max(tmp->progress.max_stage, 1);
2240+
thd_info->progress= (((tmp->progress.stage / (double) max_stage) +
2241+
((tmp->progress.counter /
2242+
(double) tmp->progress.max_counter) /
2243+
(double) max_stage)) *
2244+
100.0);
2245+
set_if_smaller(thd_info->progress, 100);
2246+
}
2247+
else
2248+
thd_info->progress= 0.0;
2249+
thd_info->start_time= tmp->start_time;
2250+
mysql_mutex_unlock(&tmp->LOCK_thd_data);
2251+
thread_infos.append(thd_info);
22522252
}
22532253
}
22542254
mysql_mutex_unlock(&LOCK_thread_count);

0 commit comments

Comments
 (0)