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