diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2012-08-08 21:24:00 +0400 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2012-08-08 21:24:00 +0400 |
commit | 0e5193435ae01ae9323448aa32570a50b23c8658 (patch) | |
tree | d7e47f04b1b9c88a7da346b86781e6f2f01b0b3e | |
parent | b71f7d97db491a7dc09f3b27336da214dd64b8f2 (diff) | |
download | mariadb-git-0e5193435ae01ae9323448aa32570a50b23c8658.tar.gz |
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)
-rw-r--r-- | sql/sql_lex.h | 1 | ||||
-rw-r--r-- | sql/sql_parse.cc | 42 | ||||
-rw-r--r-- | sql/sql_show.cc | 21 | ||||
-rw-r--r-- | sql/sql_show.h | 1 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 5 |
5 files changed, 35 insertions, 35 deletions
diff --git a/sql/sql_lex.h b/sql/sql_lex.h index eac41a9f0c0..54f8740e210 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -2360,7 +2360,6 @@ struct LEX: public Query_tables_list char* to_log; /* For PURGE MASTER LOGS TO */ char* x509_subject,*x509_issuer,*ssl_cipher; String *wild; /* Wildcard in SHOW {something} LIKE 'wild'*/ - Item *show_explain_for_thread; /* id in SHOW EXPLAIN FOR id */ sql_exchange *exchange; select_result *result; Item *default_value, *on_update_value; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 73dbe328761..16f195c44cd 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2165,7 +2165,7 @@ mysql_execute_command(THD *thd) 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)) || (*it)->check_cols(1)) { @@ -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 Thread id - @param only_kill_query Should it kill the query or the connection + @param id Identifier of the thread we're looking for - @note - This is written such that we have a short lock on LOCK_thread_count + @return NULL - not found + 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; - 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 I_List_iterator<THD> it(threads); while ((tmp=it++)) @@ -6616,7 +6610,29 @@ uint kill_one_thread(THD *thd, ulong id, killed_state kill_signal) } } 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. diff --git a/sql/sql_show.cc b/sql/sql_show.cc index b08d49b3f28..167e099baf9 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2056,28 +2056,11 @@ int fill_show_explain(THD *thd, TABLE_LIST *table, COND *cond) DBUG_ENTER("fill_show_explain"); 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 : 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; /* diff --git a/sql/sql_show.h b/sql/sql_show.h index 6ccb6e03872..12da9713e21 100644 --- a/sql/sql_show.h +++ b/sql/sql_show.h @@ -132,6 +132,7 @@ enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table); /* These functions were under INNODB_COMPATIBILITY_HOOKS */ 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; /* diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 50d87497d8c..0d9cb9622f1 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -11618,10 +11618,11 @@ show_param: } | describe_command FOR_SYM expr { + THD *thd= YYTHD; 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; - Lex->show_explain_for_thread= $3; + add_value_to_list(thd, $3); } ; |