]> git.pld-linux.org Git - packages/mysql.git/blob - mysql-microslow.patch
- resurrect more options, bconds, post-fix mysql_config
[packages/mysql.git] / mysql-microslow.patch
1 diff -r 0b1f42e1aacf sql/event_scheduler.cc
2 --- a/sql/event_scheduler.cc    Thu Dec 04 08:55:22 2008 -0800
3 +++ b/sql/event_scheduler.cc    Thu Dec 04 08:55:29 2008 -0800
4 @@ -192,6 +192,7 @@
5    thd->client_capabilities|= CLIENT_MULTI_RESULTS;
6    pthread_mutex_lock(&LOCK_thread_count);
7    thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
8 +  thd->write_to_slow_log = TRUE;
9    pthread_mutex_unlock(&LOCK_thread_count);
10  
11    /*
12 diff -r 0b1f42e1aacf sql/filesort.cc
13 --- a/sql/filesort.cc   Thu Dec 04 08:55:22 2008 -0800
14 +++ b/sql/filesort.cc   Thu Dec 04 08:55:29 2008 -0800
15 @@ -188,6 +188,7 @@
16    {
17      status_var_increment(thd->status_var.filesort_scan_count);
18    }
19 +  thd->query_plan_flags|= QPLAN_FILESORT;
20  #ifdef CAN_TRUST_RANGE
21    if (select && select->quick && select->quick->records > 0L)
22    {
23 @@ -253,6 +254,7 @@
24    }
25    else
26    {
27 +    thd->query_plan_flags|= QPLAN_FILESORT_DISK;
28      if (table_sort.buffpek && table_sort.buffpek_len < maxbuffer)
29      {
30        x_free(table_sort.buffpek);
31 @@ -1202,6 +1204,7 @@
32    DBUG_ENTER("merge_buffers");
33  
34    status_var_increment(current_thd->status_var.filesort_merge_passes);
35 +  current_thd->query_plan_fsort_passes++;
36    if (param->not_killable)
37    {
38      killed= &not_killable;
39 diff -r 0b1f42e1aacf sql/log.cc
40 --- a/sql/log.cc        Thu Dec 04 08:55:22 2008 -0800
41 +++ b/sql/log.cc        Thu Dec 04 08:55:29 2008 -0800
42 @@ -963,7 +963,7 @@
43      /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
44      user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
45                               sctx->priv_user ? sctx->priv_user : "", "[",
46 -                             sctx->user ? sctx->user : "", "] @ ",
47 +                             sctx->user ? sctx->user : (thd->slave_thread ? "SQL_SLAVE" : ""), "] @ ",
48                               sctx->host ? sctx->host : "", " [",
49                               sctx->ip ? sctx->ip : "", "]", NullS) -
50                      user_host_buff);
51 @@ -985,6 +985,13 @@
52        query= command_name[thd->command].str;
53        query_length= command_name[thd->command].length;
54      }
55 +
56 +    if (!query_length) 
57 +    { 
58 +      thd->sent_row_count= thd->examined_row_count= 0; 
59 +      thd->query_plan_flags= QPLAN_NONE; 
60 +      thd->query_plan_fsort_passes= 0; 
61 +    } 
62  
63      for (current_handler= slow_log_handler_list; *current_handler ;)
64        error= (*current_handler++)->log_slow(thd, current_time, thd->start_time,
65 @@ -2242,16 +2249,31 @@
66        if (my_b_write(&log_file, (uchar*) "\n", 1))
67          tmp_errno= errno;
68      }
69 +    
70      /* For slow query log */
71      sprintf(query_time_buff, "%.6f", ulonglong2double(query_utime)/1000000.0);
72      sprintf(lock_time_buff,  "%.6f", ulonglong2double(lock_utime)/1000000.0);
73      if (my_b_printf(&log_file,
74 -                    "# Query_time: %s  Lock_time: %s"
75 -                    " Rows_sent: %lu  Rows_examined: %lu\n",
76 +                    "# Thread_id: %lu  Schema: %s\n" \
77 +                    "# Query_time: %s  Lock_time: %s  Rows_sent: %lu  Rows_examined: %lu\n",
78 +                    (ulong) thd->thread_id, (thd->db ? thd->db : ""),
79                      query_time_buff, lock_time_buff,
80                      (ulong) thd->sent_row_count,
81                      (ulong) thd->examined_row_count) == (uint) -1)
82        tmp_errno= errno;
83 +     if ((thd->variables.log_slow_verbosity & SLOG_V_QUERY_PLAN) && 
84 +         my_b_printf(&log_file, 
85 +                     "# QC_Hit: %s  Full_scan: %s  Full_join: %s  Tmp_table: %s  Tmp_table_on_disk: %s\n" \
86 +                     "# Filesort: %s  Filesort_on_disk: %s  Merge_passes: %lu\n", 
87 +                     ((thd->query_plan_flags & QPLAN_QC) ? "Yes" : "No"), 
88 +                     ((thd->query_plan_flags & QPLAN_FULL_SCAN) ? "Yes" : "No"), 
89 +                     ((thd->query_plan_flags & QPLAN_FULL_JOIN) ? "Yes" : "No"), 
90 +                     ((thd->query_plan_flags & QPLAN_TMP_TABLE) ? "Yes" : "No"), 
91 +                     ((thd->query_plan_flags & QPLAN_TMP_DISK) ? "Yes" : "No"), 
92 +                     ((thd->query_plan_flags & QPLAN_FILESORT) ? "Yes" : "No"), 
93 +                     ((thd->query_plan_flags & QPLAN_FILESORT_DISK) ? "Yes" : "No"), 
94 +                     thd->query_plan_fsort_passes) == (uint) -1) 
95 +       tmp_errno=errno; 
96      if (thd->db && strcmp(thd->db, db))
97      {                                          // Database changed
98        if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1)
99 diff -r 0b1f42e1aacf sql/mysql_priv.h
100 --- a/sql/mysql_priv.h  Thu Dec 04 08:55:22 2008 -0800
101 +++ b/sql/mysql_priv.h  Thu Dec 04 08:55:29 2008 -0800
102 @@ -597,6 +597,73 @@
103  #define WEEK_FIRST_WEEKDAY   4
104  
105  #define STRING_BUFFER_USUAL_SIZE 80
106 +
107 +/* Slow log */
108 +
109 +struct msl_opts
110 +{
111 +  ulong val;
112 +  const char *name;
113 +};
114 +
115 +#define SLOG_V_QUERY_PLAN     1 << 1
116 +/* ... */
117 +#define SLOG_V_INVALID        1 << 31
118 +#define SLOG_V_NONE           1 << 0
119 +
120 +static const struct msl_opts slog_verb[]= 
121 +{
122 +  /* Basic flags */
123 +
124 +  { SLOG_V_QUERY_PLAN, "query_plan" },
125 +
126 +  /* End of baisc flags */
127 +
128 +  { 0, "" },
129 +
130 +  /* Complex flags */
131 +
132 +  { SLOG_V_QUERY_PLAN, "standard" },
133 +  { SLOG_V_INVALID, "full" },
134 +
135 +  /* End of complex flags */
136 +
137 +  { SLOG_V_INVALID, (char *)0 }
138 +};
139 +
140 +#define QPLAN_NONE            0
141 +#define QPLAN_QC              1 << 0
142 +#define QPLAN_QC_NO           1 << 1
143 +#define QPLAN_FULL_SCAN       1 << 2
144 +#define QPLAN_FULL_JOIN       1 << 3
145 +#define QPLAN_TMP_TABLE       1 << 4
146 +#define QPLAN_TMP_DISK        1 << 5
147 +#define QPLAN_FILESORT        1 << 6
148 +#define QPLAN_FILESORT_DISK   1 << 7
149 +/* ... */
150 +#define QPLAN_MAX             1 << 31
151 +
152 +#define SLOG_F_QC_NO          QPLAN_QC_NO
153 +#define SLOG_F_FULL_SCAN      QPLAN_FULL_SCAN
154 +#define SLOG_F_FULL_JOIN      QPLAN_FULL_JOIN
155 +#define SLOG_F_TMP_TABLE      QPLAN_TMP_TABLE
156 +#define SLOG_F_TMP_DISK       QPLAN_TMP_DISK
157 +#define SLOG_F_FILESORT       QPLAN_FILESORT
158 +#define SLOG_F_FILESORT_DISK  QPLAN_FILESORT_DISK
159 +#define SLOG_F_INVALID        1 << 31
160 +#define SLOG_F_NONE           0
161 +
162 +static const struct msl_opts slog_filter[]= 
163 +{
164 +  { SLOG_F_QC_NO,         "qc_miss" },
165 +  { SLOG_F_FULL_SCAN,     "full_scan" },
166 +  { SLOG_F_FULL_JOIN,     "full_join" },
167 +  { SLOG_F_TMP_TABLE,     "tmp_table" },
168 +  { SLOG_F_TMP_DISK,      "tmp_table_on_disk" },
169 +  { SLOG_F_FILESORT,      "filesort" },
170 +  { SLOG_F_FILESORT_DISK, "filesort_on_disk" },
171 +  { SLOG_F_INVALID,       (char *)0 }
172 +};
173  
174  /*
175    Some defines for exit codes for ::is_equal class functions.
176 --- mysql-5.1.49/sql/mysqld.cc~ 2010-07-24 15:19:16.000000000 +0300
177 +++ mysql-5.1.49/sql/mysqld.cc  2010-07-24 15:22:23.181784212 +0300
178 @@ -5553,6 +5553,9 @@
179    OPT_SECURE_FILE_PRIV,
180    OPT_MIN_EXAMINED_ROW_LIMIT,
181    OPT_LOG_SLOW_SLAVE_STATEMENTS,
182 +  OPT_LOG_SLOW_RATE_LIMIT, 
183 +  OPT_LOG_SLOW_VERBOSITY, 
184 +  OPT_LOG_SLOW_FILTER, 
185  #if defined(ENABLED_DEBUG_SYNC)
186    OPT_DEBUG_SYNC_TIMEOUT,
187  #endif /* defined(ENABLED_DEBUG_SYNC) */
188 @@ -6819,6 +6819,17 @@
189     "The minimum percentage of warm blocks in key cache.",
190     &dflt_key_cache_var.param_division_limit, NULL, NULL,
191     (GET_ULONG | GET_ASK_ADDR) , REQUIRED_ARG, 100, 1, 100, 0, 1, 0},
192 +  {"log_slow_filter", OPT_LOG_SLOW_FILTER,
193 +   "Log only the queries that followed certain execution plan. Multiple flags allowed in a comma-separated string. [qc_miss, full_scan, full_join, tmp_table, tmp_table_on_disk, filesort, filesort_on_disk]",
194 +   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, SLOG_F_NONE, 0, 0},
195 +  {"log_slow_rate_limit", OPT_LOG_SLOW_RATE_LIMIT,
196 +   "Rate limit statement writes to slow log to only those from every (1/log_slow_rate_limit) session.",
197 +   (uchar**) &global_system_variables.log_slow_rate_limit,
198 +   (uchar**) &max_system_variables.log_slow_rate_limit, 0, GET_ULONG,
199 +   REQUIRED_ARG, 1, 1, ~0L, 0, 1L, 0},
200 +  {"log_slow_verbosity", OPT_LOG_SLOW_VERBOSITY,
201 +   "Choose how verbose the messages to your slow log will be. Multiple flags allowed in a comma-separated string. [microtime, query_plan, innodb]",
202 +   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, SLOG_V_NONE, 0, 0},
203    {"long_query_time", OPT_LONG_QUERY_TIME,
204     "Log all queries that have taken more than long_query_time seconds to "
205     "execute. The argument will be treated as a decimal value with "
206 @@ -7556,6 +7570,10 @@
207    global_system_variables.old_passwords= 0;
208    global_system_variables.old_alter_table= 0;
209    global_system_variables.binlog_format= BINLOG_FORMAT_UNSPEC;
210 +  
211 +  global_system_variables.log_slow_verbosity= SLOG_V_NONE; 
212 +  global_system_variables.log_slow_filter= SLOG_F_NONE; 
213 +  
214    /*
215      Default behavior for 4.1 and 5.0 is to treat NULL values as unequal
216      when collecting index statistics for MyISAM tables.
217 @@ -8007,6 +8025,24 @@
218    case OPT_BOOTSTRAP:
219      opt_noacl=opt_bootstrap=1;
220      break;
221 +  case OPT_LOG_SLOW_FILTER: 
222 +    if ((global_system_variables.log_slow_filter=  
223 +          msl_flag_resolve_by_name(slog_filter, argument, 
224 +                                   SLOG_F_NONE, SLOG_F_INVALID)) == SLOG_F_INVALID) 
225 +    { 
226 +      fprintf(stderr,"Invalid argument to log_slow_filter\n"); 
227 +      exit(1); 
228 +    } 
229 +    break; 
230 +  case OPT_LOG_SLOW_VERBOSITY: 
231 +    if ((global_system_variables.log_slow_verbosity=  
232 +         msl_flag_resolve_by_name(slog_verb, argument, 
233 +                                  SLOG_V_NONE, SLOG_V_INVALID)) == SLOG_V_INVALID) 
234 +    { 
235 +      fprintf(stderr,"Invalid argument to log_slow_verbosity\n"); 
236 +      exit(1); 
237 +    } 
238 +    break; 
239    case OPT_SERVER_ID:
240      server_id_supplied = 1;
241      break;
242 diff -r 0b1f42e1aacf sql/set_var.cc
243 --- a/sql/set_var.cc    Thu Dec 04 08:55:22 2008 -0800
244 +++ b/sql/set_var.cc    Thu Dec 04 08:55:29 2008 -0800
245 @@ -336,6 +336,20 @@
246                                               &SV::max_join_size,
247                                               fix_max_join_size);
248  #endif
249 +static sys_var_thd_ulong  sys_log_slow_rate_limit(&vars, "log_slow_rate_limit", 
250 +              &SV::log_slow_rate_limit); 
251 +static sys_var_thd_msl_flag sys_log_slow_filter(&vars, "log_slow_filter", 
252 +              &SV::log_slow_filter, 
253 +                                       SLOG_F_NONE, 
254 +                                       SLOG_F_NONE, 
255 +                                       SLOG_F_INVALID, 
256 +                                       slog_filter); 
257 +static sys_var_thd_msl_flag sys_log_slow_verbosity(&vars, "log_slow_verbosity", 
258 +              &SV::log_slow_verbosity, 
259 +                                       SLOG_V_NONE, 
260 +                                       SLOG_V_NONE, 
261 +                                       SLOG_V_INVALID, 
262 +                                       slog_verb); 
263  static sys_var_long_ptr_global
264  sys_max_prepared_stmt_count(&vars, "max_prepared_stmt_count",
265                              &max_prepared_stmt_count,
266 @@ -3631,6 +3645,192 @@
267  #endif
268  }
269  
270 +/* Slow log stuff */
271 +
272 +ulong msl_option_resolve_by_name(const struct msl_opts *opts, const char *name, ulong len)
273 +{
274 +  ulong i;
275 +  
276 +  for (i=0; opts[i].name; i++)
277 +  {
278 +    if (!my_strnncoll(&my_charset_latin1,
279 +                      (const uchar *)name, len,
280 +                      (const uchar *)opts[i].name, strlen(opts[i].name)))
281 +      return opts[i].val;
282 +  }
283 +  return opts[i].val;
284 +}
285 +
286 +ulong msl_flag_resolve_by_name(const struct msl_opts *opts, const char *names_list, 
287 +                               const ulong none_val, const ulong invalid_val)
288 +{
289 +  const char *p, *e;
290 +  ulong val= none_val;
291 +  
292 +  if (!*names_list)
293 +    return val;
294 +  
295 +  for (p= e= names_list; ; e++)
296 +  {
297 +    ulong i;
298 +    
299 +    if (*e != ',' && *e)
300 +      continue;
301 +    for (i=0; opts[i].name; i++)
302 +    {
303 +      if (!my_strnncoll(&my_charset_latin1,
304 +                        (const uchar *)p, e - p,
305 +                        (const uchar *)opts[i].name, strlen(opts[i].name)))
306 +      {
307 +        val= val | opts[i].val;
308 +        break;
309 +      }
310 +    }
311 +    if (opts[i].val == invalid_val)
312 +      return invalid_val;
313 +    if (!*e)
314 +      break;
315 +    p= e + 1;
316 +  }
317 +  return val;
318 +}
319 +
320 +const char *msl_option_get_name(const struct msl_opts *opts, ulong val)
321 +{
322 +  for (ulong i=0; opts[i].name && opts[i].name[0]; i++)
323 +  {
324 +    if (opts[i].val == val)
325 +      return opts[i].name;
326 +  }
327 +  return "*INVALID*";
328 +}
329 +
330 +char *msl_flag_get_name(const struct msl_opts *opts, char *buf, ulong val)
331 +{
332 +  uint offset= 0;
333 +  
334 +  *buf= '\0';
335 +  for (ulong i=0; opts[i].name && opts[i].name[0]; i++)
336 +  {
337 +    if (opts[i].val & val)
338 +      offset+= snprintf(buf+offset, STRING_BUFFER_USUAL_SIZE - offset - 1,
339 +                        "%s%s", (offset ? "," : ""), opts[i].name);
340 +  }
341 +  return buf;
342 +}
343 +
344 +/****************************************************************************
345 + Functions to handle log_slow_verbosity
346 +****************************************************************************/
347 +
348 +/* Based upon sys_var::check_enum() */
349 +
350 +bool sys_var_thd_msl_option::check(THD *thd, set_var *var)
351 +{
352 +  char buff[STRING_BUFFER_USUAL_SIZE];
353 +  String str(buff, sizeof(buff), &my_charset_latin1), *res;
354 +
355 +  if (var->value->result_type() == STRING_RESULT)
356 +  {
357 +    ulong verb= this->invalid_val;
358 +    if (!(res=var->value->val_str(&str)) ||
359 +             (var->save_result.ulong_value=
360 +          (ulong) (verb= msl_option_resolve_by_name(this->opts, res->ptr(), res->length()))) == this->invalid_val)
361 +      goto err;
362 +    return 0;
363 +  }
364 +
365 +err:
366 +  my_error(ER_WRONG_ARGUMENTS, MYF(0), var->var->name);
367 +  return 1;
368 +}
369 +
370 +uchar *sys_var_thd_msl_option::value_ptr(THD *thd, enum_var_type type,
371 +                                       LEX_STRING *base)
372 +{
373 +  ulong val;
374 +  val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
375 +        thd->variables.*offset);
376 +  const char *verbosity= msl_option_get_name(this->opts, val);
377 +  return (uchar *) verbosity;
378 +}
379 +
380 +
381 +void sys_var_thd_msl_option::set_default(THD *thd, enum_var_type type)
382 +{
383 +  if (type == OPT_GLOBAL)
384 +    global_system_variables.*offset= (ulong) this->default_val;
385 +  else
386 +    thd->variables.*offset= (ulong) (global_system_variables.*offset);
387 +}
388 +
389 +
390 +bool sys_var_thd_msl_option::update(THD *thd, set_var *var)
391 +{
392 +  if (var->type == OPT_GLOBAL)
393 +    global_system_variables.*offset= var->save_result.ulong_value;
394 +  else
395 +    thd->variables.*offset= var->save_result.ulong_value;
396 +  return 0;
397 +}
398 +
399 +/****************************************************************************
400 + Functions to handle log_slow_filter
401 +****************************************************************************/
402 +  
403 +/* Based upon sys_var::check_enum() */
404 +
405 +bool sys_var_thd_msl_flag::check(THD *thd, set_var *var)
406 +{
407 +  char buff[2 * STRING_BUFFER_USUAL_SIZE];
408 +  String str(buff, sizeof(buff), &my_charset_latin1), *res;
409 +
410 +  if (var->value->result_type() == STRING_RESULT)
411 +  {
412 +    ulong filter= this->none_val;
413 +    if (!(res=var->value->val_str(&str)) ||
414 +        (var->save_result.ulong_value=
415 +          (ulong) (filter= msl_flag_resolve_by_name(this->flags, res->ptr(), this->none_val, 
416 +                                                    this->invalid_val))) == this->invalid_val)
417 +      goto err;
418 +    return 0;
419 +  }
420 +
421 +err:
422 +  my_error(ER_WRONG_ARGUMENTS, MYF(0), var->var->name);
423 +  return 1;
424 +}
425 +
426 +uchar *sys_var_thd_msl_flag::value_ptr(THD *thd, enum_var_type type,
427 +                                       LEX_STRING *base)
428 +{
429 +  ulong val;
430 +  val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
431 +        thd->variables.*offset);
432 +  msl_flag_get_name(this->flags, this->flags_string, val);
433 +  return (uchar *) this->flags_string;
434 +}
435 +
436 +
437 +void sys_var_thd_msl_flag::set_default(THD *thd, enum_var_type type)
438 +{
439 +  if (type == OPT_GLOBAL)
440 +    global_system_variables.*offset= (ulong) this->default_val;
441 +  else
442 +    thd->variables.*offset= (ulong) (global_system_variables.*offset);
443 +}
444 +
445 +
446 +bool sys_var_thd_msl_flag::update(THD *thd, set_var *var)
447 +{
448 +  if (var->type == OPT_GLOBAL)
449 +    global_system_variables.*offset= var->save_result.ulong_value;
450 +  else
451 +    thd->variables.*offset= var->save_result.ulong_value;
452 +  return 0;
453 +}
454 +
455 +
456  /****************************************************************************
457   Functions to handle table_type
458  ****************************************************************************/
459 diff -r 0b1f42e1aacf sql/set_var.h
460 --- a/sql/set_var.h     Thu Dec 04 08:55:22 2008 -0800
461 +++ b/sql/set_var.h     Thu Dec 04 08:55:29 2008 -0800
462 @@ -1057,6 +1057,68 @@
463    bool update(THD *thd, set_var *var);
464  };
465  
466 +class sys_var_thd_msl_option :public sys_var_thd
467 +{
468 +protected:
469 +  ulong SV::*offset;
470 +  const ulong none_val;
471 +  const ulong default_val;
472 +  const ulong invalid_val;
473 +  const struct msl_opts *opts;
474 +public:
475 +  sys_var_thd_msl_option(sys_var_chain *chain, const char *name_arg,
476 +                         ulong SV::*offset_arg,
477 +                         const ulong none_val_arg,
478 +                         const ulong default_val_arg,
479 +                         const ulong invalid_val_arg,
480 +                         const struct msl_opts *opts_arg)
481 +    :sys_var_thd(name_arg), offset(offset_arg), none_val(none_val_arg),
482 +     default_val(default_val_arg), invalid_val(invalid_val_arg), 
483 +     opts(opts_arg)
484 +  { chain_sys_var(chain); }
485 +  bool check(THD *thd, set_var *var);
486 +  SHOW_TYPE show_type() { return SHOW_CHAR; }
487 +  bool check_update_type(Item_result type)
488 +  {
489 +    return type != STRING_RESULT;              /* Only accept strings */
490 +  }
491 +  void set_default(THD *thd, enum_var_type type);
492 +  bool update(THD *thd, set_var *var);
493 +  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
494 +};
495 +
496 +
497 +class sys_var_thd_msl_flag :public sys_var_thd
498 +{
499 +protected:
500 +  char flags_string[2 * STRING_BUFFER_USUAL_SIZE];
501 +  ulong SV::*offset;
502 +  const ulong none_val;
503 +  const ulong default_val;
504 +  const ulong invalid_val;
505 +  const struct msl_opts *flags;
506 +public:
507 +  sys_var_thd_msl_flag(sys_var_chain *chain, const char *name_arg,
508 +                       ulong SV::*offset_arg, 
509 +                       const ulong none_val_arg, 
510 +                       const ulong default_val_arg, 
511 +                       const ulong invalid_val_arg,
512 +                       const struct msl_opts *flags_arg)
513 +    :sys_var_thd(name_arg), offset(offset_arg), none_val(none_val_arg),
514 +     default_val(default_val_arg), invalid_val(invalid_val_arg), 
515 +     flags(flags_arg)
516 +  { chain_sys_var(chain); }
517 +  bool check(THD *thd, set_var *var);
518 +  SHOW_TYPE show_type() { return SHOW_CHAR; }
519 +  bool check_update_type(Item_result type)
520 +  {
521 +    return type != STRING_RESULT;              /* Only accept strings */
522 +  }
523 +  void set_default(THD *thd, enum_var_type type);
524 +  bool update(THD *thd, set_var *var);
525 +  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
526 +};
527 +
528  
529  /**
530    Handler for setting the system variable --read-only.
531 @@ -1323,3 +1385,10 @@
532  bool process_key_caches(process_key_cache_t func);
533  void delete_elements(I_List<NAMED_LIST> *list,
534                      void (*free_element)(const char*, uchar*));
535 +
536 +/* Slow log functions */
537 +ulong msl_option_resolve_by_name(const struct msl_opts *opts, const char *name, ulong len);
538 +ulong msl_flag_resolve_by_name(const struct msl_opts *opts, const char *names_list, 
539 +                               const ulong none_val, const ulong invalid_val);
540 +const char *msl_option_get_name(const struct msl_opts *opts, ulong val);
541 +char *msl_flag_get_name(const struct msl_opts *opts, char *buf, ulong val);
542 diff -r 0b1f42e1aacf sql/slave.cc
543 --- a/sql/slave.cc      Thu Dec 04 08:55:22 2008 -0800
544 +++ b/sql/slave.cc      Thu Dec 04 08:55:29 2008 -0800
545 @@ -1561,6 +1561,7 @@
546      + MAX_LOG_EVENT_HEADER;  /* note, incr over the global not session var */
547    thd->slave_thread = 1;
548    thd->enable_slow_log= opt_log_slow_slave_statements;
549 +  thd->write_to_slow_log= opt_log_slow_slave_statements;
550    set_slave_thread_options(thd);
551    thd->client_capabilities = CLIENT_LOCAL_FILES;
552    pthread_mutex_lock(&LOCK_thread_count);
553 diff -r 0b1f42e1aacf sql/sql_cache.cc
554 --- a/sql/sql_cache.cc  Thu Dec 04 08:55:22 2008 -0800
555 +++ b/sql/sql_cache.cc  Thu Dec 04 08:55:29 2008 -0800
556 @@ -1465,6 +1465,7 @@
557  
558    thd->limit_found_rows = query->found_rows();
559    thd->status_var.last_query_cost= 0.0;
560 +  thd->query_plan_flags|= QPLAN_QC;
561    if (!thd->main_da.is_set())
562      thd->main_da.disable_status();
563  
564 @@ -1473,6 +1474,7 @@
565  err_unlock:
566    STRUCT_UNLOCK(&structure_guard_mutex);
567  err:
568 +  thd->query_plan_flags|= QPLAN_QC_NO;
569    DBUG_RETURN(0);                              // Query was not cached
570  }
571  
572 diff -r 0b1f42e1aacf sql/sql_class.h
573 --- a/sql/sql_class.h   Thu Dec 04 08:55:22 2008 -0800
574 +++ b/sql/sql_class.h   Thu Dec 04 08:55:29 2008 -0800
575 @@ -396,6 +396,11 @@
576    DATE_TIME_FORMAT *datetime_format;
577    DATE_TIME_FORMAT *time_format;
578    my_bool sysdate_is_now;
579 +
580 +  ulong log_slow_rate_limit; 
581 +  ulong log_slow_filter; 
582 +  ulong log_slow_verbosity; 
583 +            
584  };
585  
586  
587 @@ -1339,6 +1344,11 @@
588    
589    thr_lock_type update_lock_default;
590    Delayed_insert *di;
591 +
592 +  bool       write_to_slow_log; 
593
594 +  ulong      query_plan_flags; 
595 +  ulong      query_plan_fsort_passes; 
596  
597    /* <> 0 if we are inside of trigger or stored function. */
598    uint in_sub_stmt;
599 diff -r 0b1f42e1aacf sql/sql_connect.cc
600 --- a/sql/sql_connect.cc        Thu Dec 04 08:55:22 2008 -0800
601 +++ b/sql/sql_connect.cc        Thu Dec 04 08:55:29 2008 -0800
602 @@ -1124,6 +1124,15 @@
603  
604      prepare_new_connection_state(thd);
605  
606 +    /* 
607 +      If rate limiting of slow log writes is enabled, decide whether to log this 
608 +      new thread's queries or not. Uses extremely simple algorithm. :) 
609 +    */ 
610 +    thd->write_to_slow_log= FALSE; 
611 +    if (thd->variables.log_slow_rate_limit <= 1 ||  
612 +        (thd->thread_id % thd->variables.log_slow_rate_limit) == 0) 
613 +         thd->write_to_slow_log= TRUE; 
614 +
615      while (!net->error && net->vio != 0 &&
616             !(thd->killed == THD::KILL_CONNECTION))
617      {
618 diff -r 0b1f42e1aacf sql/sql_parse.cc
619 --- a/sql/sql_parse.cc  Thu Dec 04 08:55:22 2008 -0800
620 +++ b/sql/sql_parse.cc  Thu Dec 04 08:55:29 2008 -0800
621 @@ -1692,6 +1692,27 @@
622    if (unlikely(thd->in_sub_stmt))
623      DBUG_VOID_RETURN;                           // Don't set time for sub stmt
624  
625 +  /* Follow the slow log filter configuration. */ 
626 +  if (thd->variables.log_slow_filter != SLOG_F_NONE &&  
627 +      (!(thd->variables.log_slow_filter & thd->query_plan_flags) || 
628 +       ((thd->variables.log_slow_filter & SLOG_F_QC_NO) &&  
629 +        (thd->query_plan_flags & QPLAN_QC)))) 
630 +    DBUG_VOID_RETURN; 
631
632 +  /* 
633 +    Low long_query_time value most likely means user is debugging stuff and even  
634 +    though some thread's queries are not supposed to be logged b/c of the rate  
635 +    limit, if one of them takes long enough (>= 1 second) it will be sensible  
636 +    to make an exception and write to slow log anyway. 
637 +  */ 
638 +  if (thd->write_to_slow_log != TRUE && thd->variables.long_query_time < 1000000 && 
639 +      (ulong) (thd->start_utime - thd->utime_after_lock) >= 1000000) 
640 +    thd->write_to_slow_log= TRUE; 
641
642 +  /* Do not log this thread's queries due to rate limiting. */ 
643 +  if (thd->write_to_slow_log != TRUE) 
644 +    DBUG_VOID_RETURN; 
645 +
646    /*
647      Do not log administrative statements unless the appropriate option is
648      set; do not log into slow log if reading from backup.
649 @@ -5773,6 +5794,9 @@
650    thd->total_warn_count=0;                     // Warnings for this query
651    thd->rand_used= 0;
652    thd->sent_row_count= thd->examined_row_count= 0;
653 +
654 +  thd->query_plan_flags= QPLAN_NONE; 
655 +  thd->query_plan_fsort_passes= 0; 
656  
657    /*
658      Because we come here only for start of top-statements, binlog format is
659 diff -r 0b1f42e1aacf sql/sql_select.cc
660 --- a/sql/sql_select.cc Thu Dec 04 08:55:22 2008 -0800
661 +++ b/sql/sql_select.cc Thu Dec 04 08:55:29 2008 -0800
662 @@ -6480,7 +6480,10 @@
663           {
664             join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
665             if (statistics)
666 +           {
667               status_var_increment(join->thd->status_var.select_scan_count);
668 +             join->thd->query_plan_flags|= QPLAN_FULL_SCAN;
669 +           }
670           }
671         }
672         else
673 @@ -6494,7 +6497,10 @@
674           {
675             join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
676             if (statistics)
677 +           {
678               status_var_increment(join->thd->status_var.select_full_join_count);
679 +             join->thd->query_plan_flags|= QPLAN_FULL_JOIN;
680 +           }
681           }
682         }
683         if (!table->no_keyread)
684 @@ -9638,6 +9644,7 @@
685                (ulong) rows_limit,test(group)));
686  
687    status_var_increment(thd->status_var.created_tmp_tables);
688 +  thd->query_plan_flags|= QPLAN_TMP_TABLE;
689  
690    if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
691      temp_pool_slot = bitmap_lock_set_next(&temp_pool);
692 @@ -10508,6 +10515,7 @@
693      goto err;
694    }
695    status_var_increment(table->in_use->status_var.created_tmp_disk_tables);
696 +  table->in_use->query_plan_flags|= QPLAN_TMP_DISK;
697    share->db_record_offset= 1;
698    DBUG_RETURN(0);
699   err:
This page took 0.08181 seconds and 3 git commands to generate.