mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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)
This commit is contained in:
@ -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)
|
|||||||
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))
|
||||||
{
|
{
|
||||||
@ -6585,6 +6585,35 @@ void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Find a thread by id and return it, locking it LOCK_thd_data
|
||||||
|
|
||||||
|
@param id Identifier of the thread we're looking for
|
||||||
|
|
||||||
|
@return NULL - not found
|
||||||
|
pointer - thread found, and its LOCK_thd_data is locked.
|
||||||
|
*/
|
||||||
|
|
||||||
|
THD *find_thread_by_id(ulong id)
|
||||||
|
{
|
||||||
|
THD *tmp;
|
||||||
|
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 == id)
|
||||||
|
{
|
||||||
|
mysql_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mysql_mutex_unlock(&LOCK_thread_count);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
kill on thread.
|
kill on thread.
|
||||||
|
|
||||||
@ -6603,20 +6632,7 @@ uint kill_one_thread(THD *thd, ulong id, killed_state kill_signal)
|
|||||||
DBUG_ENTER("kill_one_thread");
|
DBUG_ENTER("kill_one_thread");
|
||||||
DBUG_PRINT("enter", ("id: %lu signal: %u", id, (uint) kill_signal));
|
DBUG_PRINT("enter", ("id: %lu signal: %u", id, (uint) kill_signal));
|
||||||
|
|
||||||
mysql_mutex_lock(&LOCK_thread_count); // For unlink from list
|
if ((tmp= find_thread_by_id(id)))
|
||||||
I_List_iterator<THD> it(threads);
|
|
||||||
while ((tmp=it++))
|
|
||||||
{
|
|
||||||
if (tmp->command == COM_DAEMON)
|
|
||||||
continue;
|
|
||||||
if (tmp->thread_id == id)
|
|
||||||
{
|
|
||||||
mysql_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mysql_mutex_unlock(&LOCK_thread_count);
|
|
||||||
if (tmp)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
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)
|
|||||||
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);
|
|||||||
|
|
||||||
/* 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:
|
|||||||
}
|
}
|
||||||
| 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);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user