[Commits] Rev 3463: MWL#182: Explain running statements: Address feedback: in file:///home/psergey/dev2/5.5-show-explain-r30/

Sergey Petrunya psergey at askmonty.org
Wed Aug 8 20:24:05 EEST 2012


At file:///home/psergey/dev2/5.5-show-explain-r30/

------------------------------------------------------------
revno: 3463
revision-id: psergey at askmonty.org-20120808172400-l3lnfb1tu5tzy4iz
parent: psergey at askmonty.org-20120802131223-2tm24zmh1vfahg6y
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.5-show-explain-r30
timestamp: Wed 2012-08-08 21:24:00 +0400
message:
  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)
=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2012-07-25 16:53:49 +0000
+++ b/sql/sql_lex.h	2012-08-08 17:24:00 +0000
@@ -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;

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2012-07-25 16:53:49 +0000
+++ b/sql/sql_parse.cc	2012-08-08 17:24:00 +0000
@@ -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, TAB
 
 
 /**
-  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,
     }
   }
   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.

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2012-07-25 16:53:49 +0000
+++ b/sql/sql_show.cc	2012-08-08 17:24:00 +0000
@@ -2056,28 +2056,11 @@ int fill_show_explain(THD *thd, TABLE_LI
   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;
     /*

=== modified file 'sql/sql_show.h'
--- a/sql/sql_show.h	2012-07-17 17:52:08 +0000
+++ b/sql/sql_show.h	2012-08-08 17:24:00 +0000
@@ -132,6 +132,7 @@ enum enum_schema_tables get_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;
 /*

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2012-07-25 16:53:49 +0000
+++ b/sql/sql_yacc.yy	2012-08-08 17:24:00 +0000
@@ -11618,10 +11618,11 @@ select_var_ident:  
           }
         | 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);
           }
         ;
 



More information about the commits mailing list