List:Commits« Previous MessageNext Message »
From:Alex Ivanov Notebook Date:February 16 2006 2:45pm
Subject:bk commit into 5.1 tree (aivanov:1.2092)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of alexi. When alexi does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2092 06/02/16 16:45:05 aivanov@stripped +5 -0
  The patch adds PROCESSLIST information schema

  sql/table.h
    1.130 06/02/16 16:45:00 aivanov@stripped +1 -0
    Added for PROCESSLIST informarion schema

  sql/sql_show.cc
    1.303 06/02/16 16:45:00 aivanov@stripped +129 -0
    Code for PROCESSLIST information schema

  mysql-test/t/information_schema.test
    1.71 06/02/16 16:44:59 aivanov@stripped +13 -0
    Test case to check PROCESSLIST information schema.
      (Note that selecting other fields from PROCESSLIST
      can make the test unstable).

  mysql-test/r/information_schema_db.result
    1.13 06/02/16 16:44:59 aivanov@stripped +1 -0
    Fixing results after PROCESSLIST information schema is added.

  mysql-test/r/information_schema.result
    1.110 06/02/16 16:44:59 aivanov@stripped +8 -2
    Fixing results after PROCESSLIST information schema is added.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	aivanov
# Host:	mysqld.creware.com
# Root:	/home/alexi/dev/mysql-5.1-wl3148

--- 1.302/sql/sql_show.cc	2006-02-12 04:24:25 +03:00
+++ 1.303/sql/sql_show.cc	2006-02-16 16:45:00 +03:00
@@ -1519,6 +1519,119 @@
   DBUG_VOID_RETURN;
 }
 
+int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
+{
+  TABLE *table= tables->table;
+  CHARSET_INFO *cs= system_charset_info;
+  char *user;
+  bool verbose;
+  ulong max_query_length;
+  time_t now= time(0);
+  DBUG_ENTER("fill_process_list");
+
+  user= thd->security_ctx->master_access & PROCESS_ACL ?
+        NullS : thd->security_ctx->priv_user;
+  verbose= thd->lex->verbose;
+  max_query_length= PROCESS_LIST_WIDTH;
+
+  VOID(pthread_mutex_lock(&LOCK_thread_count));
+
+  if (!thd->killed)
+  {
+    I_List_iterator<THD> it(threads);
+    THD* tmp;
+
+    while ((tmp= it++))
+    {
+      Security_context *tmp_sctx= tmp->security_ctx;
+      struct st_my_thread_var *mysys_var;
+      const char *val;
+
+      if ((!tmp->vio_ok() && !tmp->system_thread) ||
+          (user && (!tmp_sctx->user || strcmp(tmp_sctx->user, user))))
+        continue;
+
+      restore_record(table, s->default_values);
+      /* ID */
+      table->field[0]->store((longlong) tmp->thread_id, TRUE);
+      /* USER */
+      val= tmp_sctx->user ? tmp_sctx->user :
+            (tmp->system_thread ? "system user" : "unauthenticated user");
+      table->field[1]->store(val, strlen(val), cs);
+      /* HOST */
+      if (tmp->peer_port && (tmp_sctx->host || tmp_sctx->ip) &&
+          thd->security_ctx->host_or_ip[0])
+      {
+        char host[LIST_PROCESS_HOST_LEN + 1];
+        my_snprintf(host, LIST_PROCESS_HOST_LEN, "%s:%u",
+                    tmp_sctx->host_or_ip, tmp->peer_port);
+        table->field[2]->store(host, strlen(host), cs);
+      }
+      else
+        table->field[2]->store(tmp_sctx->host_or_ip,
+                               strlen(tmp_sctx->host_or_ip), cs);
+      /* DB */
+      if (tmp->db)
+      {
+        table->field[3]->store(tmp->db, strlen(tmp->db), cs);
+        table->field[3]->set_notnull();
+      }
+
+      if ((mysys_var= tmp->mysys_var))
+        pthread_mutex_lock(&mysys_var->mutex);
+      /* COMMAND */
+      if ((val= (char *) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0)))
+        table->field[4]->store(val, strlen(val), cs);
+      else
+        table->field[4]->store(command_name[tmp->command].str,
+                               command_name[tmp->command].length, cs);
+      /* TIME */
+      table->field[5]->store((uint32)(tmp->start_time ?
+                                      now - tmp->start_time : 0), TRUE);
+      /* STATE */
+#ifndef EMBEDDED_LIBRARY
+      val= (char*) (tmp->locked ? "Locked" :
+                    tmp->net.reading_or_writing ?
+                    (tmp->net.reading_or_writing == 2 ?
+                     "Writing to net" :
+                     tmp->command == COM_SLEEP ? "" :
+                     "Reading from net") :
+                    tmp->proc_info ? tmp->proc_info :
+                    tmp->mysys_var &&
+                    tmp->mysys_var->current_cond ?
+                    "Waiting on cond" : NullS);
+#else
+      val= (char *) "Writing to net";
+#endif
+      if (val)
+      {
+        table->field[6]->store(val, strlen(val), cs);
+        table->field[6]->set_notnull();
+      }
+
+      if (mysys_var)
+        pthread_mutex_unlock(&mysys_var->mutex);
+
+      /* INFO */
+      if (tmp->query)
+      {
+        table->field[7]->store(tmp->query,
+                               min(max_query_length, tmp->query_length), cs);
+        table->field[7]->set_notnull();
+      }
+
+      if (schema_table_store_record(thd, table))
+      {
+        VOID(pthread_mutex_unlock(&LOCK_thread_count));
+        DBUG_RETURN(1);
+      }
+    }
+  }
+
+  VOID(pthread_mutex_unlock(&LOCK_thread_count));
+  DBUG_RETURN(0);
+}
+
 /*****************************************************************************
   Status functions
 *****************************************************************************/
@@ -4945,6 +5058,20 @@
 };
 
 
+ST_FIELD_INFO processlist_fields_info[]=
+{
+  {"ID", 4, MYSQL_TYPE_LONG, 0, 0, "Id"},
+  {"USER", 16, MYSQL_TYPE_STRING, 0, 0, "User"},
+  {"HOST", LIST_PROCESS_HOST_LEN,  MYSQL_TYPE_STRING, 0, 0, "Host"},
+  {"DB", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Db"},
+  {"COMMAND", 16, MYSQL_TYPE_STRING, 0, 0, "Command"},
+  {"TIME", 4, MYSQL_TYPE_LONG, 0, 0, "Time"},
+  {"STATE", 30, MYSQL_TYPE_STRING, 0, 1, "State"},
+  {"INFO", PROCESS_LIST_WIDTH, MYSQL_TYPE_STRING, 0, 1, "Info"},
+  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
+};
+
+
 ST_FIELD_INFO plugin_fields_info[]=
 {
   {"PLUGIN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Name"},
@@ -5035,6 +5162,8 @@
    get_all_tables, 0, get_schema_partitions_record, 1, 2, 0},
   {"PLUGINS", plugin_fields_info, create_schema_table,
     fill_plugins, make_old_format, 0, -1, -1, 0},
+  {"PROCESSLIST", processlist_fields_info, create_schema_table,
+    fill_schema_processlist, make_old_format, 0, -1, -1, 0},
   {"ROUTINES", proc_fields_info, create_schema_table, 
     fill_schema_proc, make_proc_old_format, 0, -1, -1, 0},
   {"SCHEMATA", schema_fields_info, create_schema_table,

--- 1.129/sql/table.h	2006-02-07 15:26:16 +03:00
+++ 1.130/sql/table.h	2006-02-16 16:45:00 +03:00
@@ -344,6 +344,7 @@
   SCH_OPEN_TABLES,
   SCH_PARTITIONS,
   SCH_PLUGINS,
+  SCH_PROCESSLIST,
   SCH_PROCEDURES,
   SCH_SCHEMATA,
   SCH_SCHEMA_PRIVILEGES,

--- 1.109/mysql-test/r/information_schema.result	2006-02-07 15:26:53 +03:00
+++ 1.110/mysql-test/r/information_schema.result	2006-02-16 16:44:59 +03:00
@@ -49,6 +49,7 @@
 KEY_COLUMN_USAGE
 PARTITIONS
 PLUGINS
+PROCESSLIST
 ROUTINES
 SCHEMATA
 SCHEMA_PRIVILEGES
@@ -737,7 +738,7 @@
 CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
 CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
 count(*)
-111
+112
 drop view a2, a1;
 drop table t_crashme;
 select table_schema,table_name, column_name from
@@ -835,7 +836,7 @@
 SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA;
 table_schema	count(*)
 cluster_replication	1
-information_schema	21
+information_schema	22
 mysql	21
 create table t1 (i int, j int);
 create trigger trg1 before insert on t1 for each row
@@ -1142,3 +1143,8 @@
 select * from information_schema.engines WHERE ENGINE="MyISAM";
 ENGINE	SUPPORT	COMMENT	TRANSACTIONS	XA	SAVEPOINTS
 MyISAM	ENABLED	Default engine as of MySQL 3.23 with great performance	NO	NO	NO
+grant select on *.* to user3148@localhost;
+select user,db from information_schema.processlist;
+user	db
+user3148	test
+drop user user3148@localhost;

--- 1.70/mysql-test/t/information_schema.test	2006-02-07 22:54:34 +03:00
+++ 1.71/mysql-test/t/information_schema.test	2006-02-16 16:44:59 +03:00
@@ -821,3 +821,16 @@
 #
 
 select * from information_schema.engines WHERE ENGINE="MyISAM";
+
+#
+# INFORMATION_SCHEMA.PROCESSLIST
+#
+
+grant select on *.* to user3148@localhost;
+connect (con3148,localhost,user3148,,test);
+connection con3148;
+select user,db from information_schema.processlist;
+connection default;
+drop user user3148@localhost;
+
+

--- 1.12/mysql-test/r/information_schema_db.result	2006-02-07 15:26:15 +03:00
+++ 1.13/mysql-test/r/information_schema_db.result	2006-02-16 16:44:59 +03:00
@@ -12,6 +12,7 @@
 KEY_COLUMN_USAGE
 PARTITIONS
 PLUGINS
+PROCESSLIST
 ROUTINES
 SCHEMATA
 SCHEMA_PRIVILEGES
Thread
bk commit into 5.1 tree (aivanov:1.2092)Alex Ivanov Notebook16 Feb