summaryrefslogtreecommitdiff
blob: 2e68888c06065fc9f15418709921c780f35f6233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
diff -r e3b747e556c8 mysql-test/r/information_schema.result
--- a/mysql-test/r/information_schema.result	Mon May 18 18:44:04 2009 -0700
+++ b/mysql-test/r/information_schema.result	Mon May 18 18:48:11 2009 -0700
@@ -44,6 +44,7 @@
 COLUMN_PRIVILEGES
 INDEX_STATISTICS
 KEY_COLUMN_USAGE
+PROCESSLIST
 PROFILING
 ROUTINES
 SCHEMATA
@@ -740,7 +741,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(*)
-106
+107
 drop view a2, a1;
 drop table t_crashme;
 select table_schema,table_name, column_name from
@@ -749,6 +750,7 @@
 table_schema	table_name	column_name
 information_schema	COLUMNS	COLUMN_DEFAULT
 information_schema	COLUMNS	COLUMN_TYPE
+information_schema	PROCESSLIST	INFO
 information_schema	ROUTINES	ROUTINE_DEFINITION
 information_schema	ROUTINES	SQL_MODE
 information_schema	TRIGGERS	ACTION_CONDITION
@@ -813,7 +815,7 @@
 flush privileges;
 SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA;
 table_schema	count(*)
-information_schema	21
+information_schema	22
 mysql	17
 create table t1 (i int, j int);
 create trigger trg1 before insert on t1 for each row
@@ -1206,6 +1208,7 @@
 COLUMN_PRIVILEGES	TABLE_SCHEMA
 INDEX_STATISTICS	TABLE_SCHEMA
 KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA
+PROCESSLIST	ID
 PROFILING	QUERY_ID
 ROUTINES	ROUTINE_SCHEMA
 SCHEMATA	SCHEMA_NAME
@@ -1242,6 +1245,7 @@
 COLUMN_PRIVILEGES	TABLE_SCHEMA
 INDEX_STATISTICS	TABLE_SCHEMA
 KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA
+PROCESSLIST	ID
 PROFILING	QUERY_ID
 ROUTINES	ROUTINE_SCHEMA
 SCHEMATA	SCHEMA_NAME
@@ -1329,6 +1333,7 @@
 COLUMN_PRIVILEGES	information_schema.COLUMN_PRIVILEGES	1
 INDEX_STATISTICS	information_schema.INDEX_STATISTICS	1
 KEY_COLUMN_USAGE	information_schema.KEY_COLUMN_USAGE	1
+PROCESSLIST	information_schema.PROCESSLIST	1
 PROFILING	information_schema.PROFILING	1
 ROUTINES	information_schema.ROUTINES	1
 SCHEMATA	information_schema.SCHEMATA	1
diff -r e3b747e556c8 mysql-test/r/information_schema_db.result
--- a/mysql-test/r/information_schema_db.result	Mon May 18 18:44:04 2009 -0700
+++ b/mysql-test/r/information_schema_db.result	Mon May 18 18:48:11 2009 -0700
@@ -13,6 +13,7 @@
 COLUMN_PRIVILEGES
 INDEX_STATISTICS
 KEY_COLUMN_USAGE
+PROCESSLIST
 PROFILING
 ROUTINES
 SCHEMATA
diff -r e3b747e556c8 mysql-test/r/mysqlshow.result
--- a/mysql-test/r/mysqlshow.result	Mon May 18 18:44:04 2009 -0700
+++ b/mysql-test/r/mysqlshow.result	Mon May 18 18:48:11 2009 -0700
@@ -87,6 +87,7 @@
 | COLUMN_PRIVILEGES                     |
 | INDEX_STATISTICS                      |
 | KEY_COLUMN_USAGE                      |
+| PROCESSLIST                           |
 | PROFILING                             |
 | ROUTINES                              |
 | SCHEMATA                              |
@@ -113,6 +114,7 @@
 | COLUMN_PRIVILEGES                     |
 | INDEX_STATISTICS                      |
 | KEY_COLUMN_USAGE                      |
+| PROCESSLIST                           |
 | PROFILING                             |
 | ROUTINES                              |
 | SCHEMATA                              |
diff -r e3b747e556c8 patch_info/microsec_process.info
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patch_info/microsec_process.info	Mon May 18 18:48:11 2009 -0700
@@ -0,0 +1,6 @@
+File=microsec_process.patch
+Name=Adds INFOMATION_SCHEMA.PROCESSLIST with TIME_MS column
+Version=1.0
+Author=Percona <info@percona.com>
+License=GPL
+Comment=
diff -r e3b747e556c8 sql/mysql_priv.h
--- a/sql/mysql_priv.h	Mon May 18 18:44:04 2009 -0700
+++ b/sql/mysql_priv.h	Mon May 18 18:48:11 2009 -0700
@@ -249,6 +249,8 @@
 
 /* Characters shown for the command in 'show processlist' */
 #define PROCESS_LIST_WIDTH 100
+/* Characters shown for the command in 'information_schema.processlist' */
+#define PROCESS_LIST_INFO_WIDTH 65535
 
 #define PRECISION_FOR_DOUBLE 53
 #define PRECISION_FOR_FLOAT  24
diff -r e3b747e556c8 sql/sql_show.cc
--- a/sql/sql_show.cc	Mon May 18 18:44:04 2009 -0700
+++ b/sql/sql_show.cc	Mon May 18 18:48:11 2009 -0700
@@ -1480,6 +1480,122 @@
   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;
+  ulonglong current_timer= my_timer(&current_timer, frequency);
+  DBUG_ENTER("fill_process_list");
+
+  user= thd->security_ctx->master_access & PROCESS_ACL ?
+        NullS : thd->security_ctx->priv_user;
+
+  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],
+                               strlen(command_name[tmp->command]), cs);
+      /* MYSQL_TIME */
+      ulonglong utime= (tmp->start_timer && current_timer) ? current_timer - tmp->start_timer : 0; 
+      /* correction for negative time */
+      if (utime > 2629743) utime= 0; 
+      table->field[5]->store(utime / 1000000, 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(PROCESS_LIST_INFO_WIDTH,
+                                   tmp->query_length), cs);
+        table->field[7]->set_notnull();
+      }
+
+      /* TIME_MS */
+      table->field[8]->store((double)(utime / 1000.0));
+
+      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
 *****************************************************************************/
@@ -4849,6 +4965,22 @@
   {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
 };
 
+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", 7, MYSQL_TYPE_LONG, 0, 0, "Time"},
+  {"STATE", 64, MYSQL_TYPE_STRING, 0, 1, "State"},
+  {"INFO", PROCESS_LIST_INFO_WIDTH, MYSQL_TYPE_STRING, 0, 1, "Info"},
+  {"TIME_MS", 100 * (MY_INT64_NUM_DECIMAL_DIGITS + 1) + 3, MYSQL_TYPE_DECIMAL,
+    0, 0, "Time_ms"},
+  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
+};
+
+
 /*
   Description of ST_FIELD_INFO in table.h
 */
@@ -4873,6 +5005,8 @@
     get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0},
   {"OPEN_TABLES", open_tables_fields_info, create_schema_table,
    fill_open_tables, make_old_format, 0, -1, -1, 1},
+  {"PROCESSLIST", processlist_fields_info, create_schema_table,
+   fill_schema_processlist, make_old_format, 0, -1, -1, 0},
   {"PROFILING", query_profile_statistics_info, create_schema_table,
    fill_query_profile_statistics_info, make_profile_table_for_show, 
    NULL, -1, -1, false},
diff -r e3b747e556c8 sql/table.h
--- a/sql/table.h	Mon May 18 18:44:04 2009 -0700
+++ b/sql/table.h	Mon May 18 18:48:11 2009 -0700
@@ -379,6 +379,7 @@
   SCH_INDEX_STATS,
   SCH_KEY_COLUMN_USAGE,
   SCH_OPEN_TABLES,
+  SCH_PROCESSLIST,
   SCH_PROFILES,
   SCH_PROCEDURES,
   SCH_SCHEMATA,