Commit 0e519343 authored by Sergey Petrunya's avatar Sergey Petrunya

MWL#182: Explain running statements: Address feedback:

- Use LEX::value_list instead of LEX::show_explain_for_thread
- Factor out common code into find_thread_by_id(ulong id)
parent b71f7d97
...@@ -2360,7 +2360,6 @@ struct LEX: public Query_tables_list ...@@ -2360,7 +2360,6 @@ struct LEX: public Query_tables_list
char* to_log; /* For PURGE MASTER LOGS TO */ char* to_log; /* For PURGE MASTER LOGS TO */
char* x509_subject,*x509_issuer,*ssl_cipher; char* x509_subject,*x509_issuer,*ssl_cipher;
String *wild; /* Wildcard in SHOW {something} LIKE 'wild'*/ String *wild; /* Wildcard in SHOW {something} LIKE 'wild'*/
Item *show_explain_for_thread; /* id in SHOW EXPLAIN FOR id */
sql_exchange *exchange; sql_exchange *exchange;
select_result *result; select_result *result;
Item *default_value, *on_update_value; Item *default_value, *on_update_value;
......
...@@ -2165,7 +2165,7 @@ mysql_execute_command(THD *thd) ...@@ -2165,7 +2165,7 @@ mysql_execute_command(THD *thd)
goto error; goto error;
} }
Item **it= &(lex->show_explain_for_thread); Item **it= lex->value_list.head_ref();
if ((!(*it)->fixed && (*it)->fix_fields(lex->thd, it)) || if ((!(*it)->fixed && (*it)->fix_fields(lex->thd, it)) ||
(*it)->check_cols(1)) (*it)->check_cols(1))
{ {
...@@ -6586,23 +6586,17 @@ void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields, ...@@ -6586,23 +6586,17 @@ void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields,
/** /**
kill on thread. Find a thread by id and return it, locking it LOCK_thd_data
@param thd Thread class @param id Identifier of the thread we're looking for
@param id Thread id
@param only_kill_query Should it kill the query or the connection
@note @return NULL - not found
This is written such that we have a short lock on LOCK_thread_count pointer - thread found, and its LOCK_thd_data is locked.
*/ */
uint kill_one_thread(THD *thd, ulong id, killed_state kill_signal) THD *find_thread_by_id(ulong id)
{ {
THD *tmp; THD *tmp;
uint error=ER_NO_SUCH_THREAD;
DBUG_ENTER("kill_one_thread");
DBUG_PRINT("enter", ("id: %lu signal: %u", id, (uint) kill_signal));
mysql_mutex_lock(&LOCK_thread_count); // For unlink from list mysql_mutex_lock(&LOCK_thread_count); // For unlink from list
I_List_iterator<THD> it(threads); I_List_iterator<THD> it(threads);
while ((tmp=it++)) while ((tmp=it++))
...@@ -6616,7 +6610,29 @@ uint kill_one_thread(THD *thd, ulong id, killed_state kill_signal) ...@@ -6616,7 +6610,29 @@ uint kill_one_thread(THD *thd, ulong id, killed_state kill_signal)
} }
} }
mysql_mutex_unlock(&LOCK_thread_count); mysql_mutex_unlock(&LOCK_thread_count);
if (tmp) return tmp;
}
/**
kill on thread.
@param thd Thread class
@param id Thread id
@param only_kill_query Should it kill the query or the connection
@note
This is written such that we have a short lock on LOCK_thread_count
*/
uint kill_one_thread(THD *thd, ulong id, killed_state kill_signal)
{
THD *tmp;
uint error=ER_NO_SUCH_THREAD;
DBUG_ENTER("kill_one_thread");
DBUG_PRINT("enter", ("id: %lu signal: %u", id, (uint) kill_signal));
if ((tmp= find_thread_by_id(id)))
{ {
/* /*
If we're SUPER, we can KILL anything, including system-threads. If we're SUPER, we can KILL anything, including system-threads.
......
...@@ -2056,28 +2056,11 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond) ...@@ -2056,28 +2056,11 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond)
DBUG_ENTER("fill_show_explain"); DBUG_ENTER("fill_show_explain");
DBUG_ASSERT(cond==NULL); DBUG_ASSERT(cond==NULL);
thread_id= thd->lex->show_explain_for_thread->val_int(); thread_id= thd->lex->value_list.head()->val_int();
calling_user= (thd->security_ctx->master_access & PROCESS_ACL) ? NullS : calling_user= (thd->security_ctx->master_access & PROCESS_ACL) ? NullS :
thd->security_ctx->priv_user; thd->security_ctx->priv_user;
/*
Find the thread we need EXPLAIN for. Thread search code was copied from
kill_one_thread()
*/
mysql_mutex_lock(&LOCK_thread_count); // For unlink from list
I_List_iterator<THD> it(threads);
while ((tmp=it++))
{
if (tmp->command == COM_DAEMON)
continue;
if (tmp->thread_id == thread_id)
{
mysql_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete
break;
}
}
mysql_mutex_unlock(&LOCK_thread_count);
if (tmp) if ((tmp= find_thread_by_id(thread_id)))
{ {
Security_context *tmp_sctx= tmp->security_ctx; Security_context *tmp_sctx= tmp->security_ctx;
/* /*
......
...@@ -132,6 +132,7 @@ enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table); ...@@ -132,6 +132,7 @@ enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
/* These functions were under INNODB_COMPATIBILITY_HOOKS */ /* These functions were under INNODB_COMPATIBILITY_HOOKS */
int get_quote_char_for_identifier(THD *thd, const char *name, uint length); int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
THD *find_thread_by_id(ulong id);
class select_result_explain_buffer; class select_result_explain_buffer;
/* /*
......
...@@ -11618,10 +11618,11 @@ show_param: ...@@ -11618,10 +11618,11 @@ show_param:
} }
| describe_command FOR_SYM expr | describe_command FOR_SYM expr
{ {
THD *thd= YYTHD;
Lex->sql_command= SQLCOM_SHOW_EXPLAIN; Lex->sql_command= SQLCOM_SHOW_EXPLAIN;
if (prepare_schema_table(YYTHD, Lex, 0, SCH_EXPLAIN)) if (prepare_schema_table(thd, Lex, 0, SCH_EXPLAIN))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->show_explain_for_thread= $3; add_value_to_list(thd, $3);
} }
; ;
......
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