]> git.pld-linux.org Git - packages/mysql.git/blob - slow_extended.patch
- mention innodb_file_per_table
[packages/mysql.git] / slow_extended.patch
1 # name       : slow_extended.patch
2 # introduced : 11 or before
3 # maintainer : Oleg
4 #
5 #!!! notice !!!
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 --- a/include/mysql/plugin_audit.h.pp
9 +++ b/include/mysql/plugin_audit.h.pp
10 @@ -185,6 +185,16 @@
11  char *thd_security_context(void* thd, char *buffer, unsigned int length,
12                             unsigned int max_query_len);
13  void thd_inc_row_count(void* thd);
14 +void increment_thd_innodb_stats(void* thd,
15 +                    unsigned long long trx_id,
16 +                    long io_reads,
17 +                    long long io_read,
18 +                    long io_reads_wait_timer,
19 +                    long lock_que_wait_timer,
20 +                    long que_wait_timer,
21 +                    long page_access);
22 +unsigned long thd_log_slow_verbosity(const void* thd);
23 +int thd_opt_slow_log();
24  int mysql_tmpfile(const char *prefix);
25  int thd_killed(const void* thd);
26  unsigned long thd_get_thread_id(const void* thd);
27 --- a/include/mysql/plugin_auth.h.pp
28 +++ b/include/mysql/plugin_auth.h.pp
29 @@ -185,6 +185,16 @@
30  char *thd_security_context(void* thd, char *buffer, unsigned int length,
31                             unsigned int max_query_len);
32  void thd_inc_row_count(void* thd);
33 +void increment_thd_innodb_stats(void* thd,
34 +                    unsigned long long trx_id,
35 +                    long io_reads,
36 +                    long long io_read,
37 +                    long io_reads_wait_timer,
38 +                    long lock_que_wait_timer,
39 +                    long que_wait_timer,
40 +                    long page_access);
41 +unsigned long thd_log_slow_verbosity(const void* thd);
42 +int thd_opt_slow_log();
43  int mysql_tmpfile(const char *prefix);
44  int thd_killed(const void* thd);
45  unsigned long thd_get_thread_id(const void* thd);
46 --- a/include/mysql/plugin_ftparser.h.pp
47 +++ b/include/mysql/plugin_ftparser.h.pp
48 @@ -138,6 +138,16 @@
49  char *thd_security_context(void* thd, char *buffer, unsigned int length,
50                             unsigned int max_query_len);
51  void thd_inc_row_count(void* thd);
52 +void increment_thd_innodb_stats(void* thd,
53 +                    unsigned long long trx_id,
54 +                    long io_reads,
55 +                    long long io_read,
56 +                    long io_reads_wait_timer,
57 +                    long lock_que_wait_timer,
58 +                    long que_wait_timer,
59 +                    long page_access);
60 +unsigned long thd_log_slow_verbosity(const void* thd);
61 +int thd_opt_slow_log();
62  int mysql_tmpfile(const char *prefix);
63  int thd_killed(const void* thd);
64  unsigned long thd_get_thread_id(const void* thd);
65 --- a/include/mysql/plugin.h
66 +++ b/include/mysql/plugin.h
67 @@ -536,6 +536,17 @@
68  /* Increments the row counter, see THD::row_count */
69  void thd_inc_row_count(MYSQL_THD thd);
70  
71 +void increment_thd_innodb_stats(MYSQL_THD thd,
72 +                    unsigned long long trx_id,
73 +                    long io_reads,
74 +                    long long io_read,
75 +                    long io_reads_wait_timer,
76 +                    long lock_que_wait_timer,
77 +                    long que_wait_timer,
78 +                    long page_access);
79 +unsigned long thd_log_slow_verbosity(const MYSQL_THD thd);
80 +int thd_opt_slow_log();
81 +#define EXTENDED_SLOWLOG
82  /**
83    Create a temporary file.
84  
85 --- /dev/null
86 +++ b/patch_info/slow_extended.info
87 @@ -0,0 +1,25 @@
88 +File=slow_extended.patch
89 +Name=Extended statistics in slow.log (not InnoDB part)
90 +Version=1.3
91 +Author=Percona <info@percona.com>
92 +License=GPL
93 +Comment=
94 +Changelog
95 +2008-11-26
96 +YK: Fix inefficient determination of trx, Make not to call useless gettimeofday when don't use slow log. Make log_slow_queries dynamic (bool).
97 +
98 +2008-11-07
99 +VT: Moved log_slow_rate_limit in SHOW VARIABLE into right place
100 +
101 +2008-11
102 +Arjen Lentz: Fixups (backward compatibility) by Arjen Lentz <arjen@openquery.com.au>
103 +
104 +2010-07
105 +1) Fix overflow of query time and lock time (Bug 600360) (slow_extended_fix_overflow.patch merged)
106 +2) Control global slow feature merged (control_global_slow.patch merged)
107 +3) Microseconds in slow query log merged (microseconds_in_slow_query_log.patch merged)
108 +4) Now use_global_long_query_time and use_global_log_slow_control are synonims. Add value "all" for use_global_log_slow_control (contol-global_slow-2.patch merged)
109 +5) Fix innodb_stats on replication (Bug 600684)
110 +6) Change variable types (system/command-line)
111 +2011-01
112 +Patch profiling_slow.patch was merged
113 --- a/scripts/mysqldumpslow.sh
114 +++ b/scripts/mysqldumpslow.sh
115 @@ -102,8 +102,8 @@
116      s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//;
117      my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('','');
118  
119 -    s/^# Query_time: ([0-9.]+)\s+Lock_time: ([0-9.]+)\s+Rows_sent: ([0-9.]+).*\n//;
120 -    my ($t, $l, $r) = ($1, $2, $3);
121 +    s/^# Query_time: (\d+(\.\d+)?)  Lock_time: (\d+(\.\d+)?)  Rows_sent: (\d+(\.\d+)?).*\n//;
122 +    my ($t, $l, $r) = ($1, $3, $5);
123      $t -= $l unless $opt{l};
124  
125      # remove fluff that mysqld writes to log when it (re)starts:
126 --- a/sql/event_scheduler.cc
127 +++ b/sql/event_scheduler.cc
128 @@ -195,6 +195,7 @@
129    thd->client_capabilities|= CLIENT_MULTI_RESULTS;
130    mysql_mutex_lock(&LOCK_thread_count);
131    thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
132 +  thd->write_to_slow_log = TRUE;
133    mysql_mutex_unlock(&LOCK_thread_count);
134  
135    /*
136 --- a/sql/filesort.cc
137 +++ b/sql/filesort.cc
138 @@ -195,6 +195,7 @@
139    {
140      status_var_increment(thd->status_var.filesort_scan_count);
141    }
142 +  thd->query_plan_flags|= QPLAN_FILESORT;
143  #ifdef CAN_TRUST_RANGE
144    if (select && select->quick && select->quick->records > 0L)
145    {
146 @@ -260,6 +261,7 @@
147    }
148    else
149    {
150 +    thd->query_plan_flags|= QPLAN_FILESORT_DISK;
151      if (table_sort.buffpek && table_sort.buffpek_len < maxbuffer)
152      {
153        my_free(table_sort.buffpek);
154 @@ -1219,6 +1221,7 @@
155    DBUG_ENTER("merge_buffers");
156  
157    status_var_increment(current_thd->status_var.filesort_merge_passes);
158 +  current_thd->query_plan_fsort_passes++;
159    if (param->not_killable)
160    {
161      killed= &not_killable;
162 --- a/sql/log.cc
163 +++ b/sql/log.cc
164 @@ -715,11 +715,13 @@
165  */
166  
167  bool Log_to_csv_event_handler::
168 -  log_slow(THD *thd, time_t current_time, time_t query_start_arg,
169 +  log_slow(THD *thd, ulonglong current_utime, time_t query_start_arg,
170             const char *user_host, uint user_host_len,
171             ulonglong query_utime, ulonglong lock_utime, bool is_command,
172             const char *sql_text, uint sql_text_len)
173  {
174 +  time_t current_time= my_time_possible_from_micro(current_utime);
175 +
176    TABLE_LIST table_list;
177    TABLE *table;
178    bool result= TRUE;
179 @@ -935,14 +937,14 @@
180  /** Wrapper around MYSQL_LOG::write() for slow log. */
181  
182  bool Log_to_file_event_handler::
183 -  log_slow(THD *thd, time_t current_time, time_t query_start_arg,
184 +  log_slow(THD *thd, ulonglong current_utime, time_t query_start_arg,
185             const char *user_host, uint user_host_len,
186             ulonglong query_utime, ulonglong lock_utime, bool is_command,
187             const char *sql_text, uint sql_text_len)
188  {
189    Silence_log_table_errors error_handler;
190    thd->push_internal_handler(&error_handler);
191 -  bool retval= mysql_slow_log.write(thd, current_time, query_start_arg,
192 +  bool retval= mysql_slow_log.write(thd, current_utime, query_start_arg,
193                                      user_host, user_host_len,
194                                      query_utime, lock_utime, is_command,
195                                      sql_text, sql_text_len);
196 @@ -1216,7 +1218,7 @@
197      /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
198      user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
199                               sctx->priv_user ? sctx->priv_user : "", "[",
200 -                             sctx->user ? sctx->user : "", "] @ ",
201 +                             sctx->user ? sctx->user : (thd->slave_thread ? "SQL_SLAVE" : ""), "] @ ",
202                               sctx->host ? sctx->host : "", " [",
203                               sctx->ip ? sctx->ip : "", "]", NullS) -
204                      user_host_buff);
205 @@ -1224,8 +1226,22 @@
206      current_time= my_time_possible_from_micro(current_utime);
207      if (thd->start_utime)
208      {
209 -      query_utime= (current_utime - thd->start_utime);
210 -      lock_utime=  (thd->utime_after_lock - thd->start_utime);
211 +      if(current_utime < thd->start_utime)
212 +      {
213 +        query_utime= 0;
214 +      }
215 +      else
216 +      {
217 +        query_utime= (current_utime - thd->start_utime);
218 +      }
219 +      if(thd->utime_after_lock < thd->start_utime)
220 +      {
221 +        lock_utime= 0;
222 +      }
223 +      else
224 +      {
225 +        lock_utime= (thd->utime_after_lock - thd->start_utime);
226 +      }
227      }
228      else
229      {
230 @@ -1239,8 +1255,20 @@
231        query_length= command_name[thd->command].length;
232      }
233  
234 +    if (!query_length)
235 +    {
236 +      thd->sent_row_count= thd->examined_row_count= 0;
237 +      thd->sent_row_count= 0;
238 +      thd->bytes_sent_old= thd->status_var.bytes_sent;
239 +      thd->tmp_tables_used= thd->tmp_tables_disk_used= 0;
240 +      thd->tmp_tables_size= 0;
241 +      thd->innodb_was_used= FALSE;
242 +      thd->query_plan_flags= QPLAN_NONE;
243 +      thd->query_plan_fsort_passes= 0;
244 +    }
245 +
246      for (current_handler= slow_log_handler_list; *current_handler ;)
247 -      error= (*current_handler++)->log_slow(thd, current_time, thd->start_time,
248 +      error= (*current_handler++)->log_slow(thd, current_utime, thd->start_time,
249                                              user_host_buff, user_host_len,
250                                              query_utime, lock_utime, is_command,
251                                              query, query_length) || error;
252 @@ -2656,12 +2684,13 @@
253      TRUE - error occured
254  */
255  
256 -bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
257 +bool MYSQL_QUERY_LOG::write(THD *thd, ulonglong current_utime,
258                              time_t query_start_arg, const char *user_host,
259                              uint user_host_len, ulonglong query_utime,
260                              ulonglong lock_utime, bool is_command,
261                              const char *sql_text, uint sql_text_len)
262  {
263 +  time_t current_time= my_time_possible_from_micro(current_utime);
264    bool error= 0;
265    DBUG_ENTER("MYSQL_QUERY_LOG::write");
266  
267 @@ -2683,17 +2712,28 @@
268  
269      if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
270      {
271 -      if (current_time != last_time)
272 +      if (opt_slow_query_log_timestamp_always || current_time != last_time)
273        {
274          last_time= current_time;
275          struct tm start;
276          localtime_r(&current_time, &start);
277 -
278 -        buff_len= my_snprintf(buff, sizeof buff,
279 -                              "# Time: %02d%02d%02d %2d:%02d:%02d\n",
280 -                              start.tm_year % 100, start.tm_mon + 1,
281 -                              start.tm_mday, start.tm_hour,
282 -                              start.tm_min, start.tm_sec);
283 +       if(opt_slow_query_log_timestamp_precision & SLOG_MICROSECOND)
284 +       {
285 +         ulonglong microsecond = current_utime % (1000 * 1000);
286 +         buff_len= snprintf(buff, sizeof buff,
287 +           "# Time: %02d%02d%02d %2d:%02d:%02d.%010lld\n",
288 +            start.tm_year % 100, start.tm_mon + 1,
289 +           start.tm_mday, start.tm_hour,
290 +           start.tm_min, start.tm_sec,microsecond);
291 +       }
292 +       else
293 +       {
294 +         buff_len= my_snprintf(buff, sizeof buff,
295 +           "# Time: %02d%02d%02d %2d:%02d:%02d\n",
296 +            start.tm_year % 100, start.tm_mon + 1,
297 +           start.tm_mday, start.tm_hour,
298 +           start.tm_min, start.tm_sec);
299 +       }
300  
301          /* Note that my_b_write() assumes it knows the length for this */
302          if (my_b_write(&log_file, (uchar*) buff, buff_len))
303 @@ -2711,12 +2751,69 @@
304      sprintf(query_time_buff, "%.6f", ulonglong2double(query_utime)/1000000.0);
305      sprintf(lock_time_buff,  "%.6f", ulonglong2double(lock_utime)/1000000.0);
306      if (my_b_printf(&log_file,
307 -                    "# Query_time: %s  Lock_time: %s"
308 -                    " Rows_sent: %lu  Rows_examined: %lu\n",
309 +                    "# Thread_id: %lu  Schema: %s  Last_errno: %u  Killed: %u\n" \
310 +                    "# Query_time: %s  Lock_time: %s  Rows_sent: %lu  Rows_examined: %lu  Rows_affected: %lu  Rows_read: %lu\n"
311 +                    "# Bytes_sent: %lu  Tmp_tables: %lu  Tmp_disk_tables: %lu  Tmp_table_sizes: %lu\n",
312 +                    (ulong) thd->thread_id, (thd->db ? thd->db : ""),
313 +                    thd->last_errno, (uint) thd->killed,
314                      query_time_buff, lock_time_buff,
315                      (ulong) thd->sent_row_count,
316 -                    (ulong) thd->examined_row_count) == (uint) -1)
317 +                    (ulong) thd->examined_row_count,
318 +                    ((long) thd->get_row_count_func() > 0 ) ? (ulong) thd->get_row_count_func() : 0,
319 +                    (ulong) thd->sent_row_count,
320 +                    (ulong) (thd->status_var.bytes_sent - thd->bytes_sent_old),
321 +                    (ulong) thd->tmp_tables_used,
322 +                    (ulong) thd->tmp_tables_disk_used,
323 +                    (ulong) thd->tmp_tables_size) == (uint) -1)
324        tmp_errno= errno;
325 +
326 +#if defined(ENABLED_PROFILING)
327 +    thd->profiling.print_current(&log_file);
328 +#endif
329 +    if (thd->innodb_was_used)
330 +    {
331 +      char buf[20];
332 +      snprintf(buf, 20, "%llX", thd->innodb_trx_id);
333 +      if (my_b_printf(&log_file,
334 +                    "# InnoDB_trx_id: %s\n", buf) == (uint) -1)
335 +        tmp_errno=errno;
336 +    }
337 +    if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_QUERY_PLAN)) &&
338 +         my_b_printf(&log_file,
339 +                    "# QC_Hit: %s  Full_scan: %s  Full_join: %s  Tmp_table: %s  Tmp_table_on_disk: %s\n" \
340 +                    "# Filesort: %s  Filesort_on_disk: %s  Merge_passes: %lu\n",
341 +                    ((thd->query_plan_flags & QPLAN_QC) ? "Yes" : "No"),
342 +                    ((thd->query_plan_flags & QPLAN_FULL_SCAN) ? "Yes" : "No"),
343 +                    ((thd->query_plan_flags & QPLAN_FULL_JOIN) ? "Yes" : "No"),
344 +                    ((thd->query_plan_flags & QPLAN_TMP_TABLE) ? "Yes" : "No"),
345 +                    ((thd->query_plan_flags & QPLAN_TMP_DISK) ? "Yes" : "No"),
346 +                    ((thd->query_plan_flags & QPLAN_FILESORT) ? "Yes" : "No"),
347 +                    ((thd->query_plan_flags & QPLAN_FILESORT_DISK) ? "Yes" : "No"),
348 +                    thd->query_plan_fsort_passes) == (uint) -1)
349 +      tmp_errno=errno;
350 +    if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_INNODB)) && thd->innodb_was_used)
351 +    {
352 +      char buf[3][20];
353 +      snprintf(buf[0], 20, "%.6f", thd->innodb_io_reads_wait_timer / 1000000.0);
354 +      snprintf(buf[1], 20, "%.6f", thd->innodb_lock_que_wait_timer / 1000000.0);
355 +      snprintf(buf[2], 20, "%.6f", thd->innodb_innodb_que_wait_timer / 1000000.0);
356 +      if (my_b_printf(&log_file,
357 +                      "#   InnoDB_IO_r_ops: %lu  InnoDB_IO_r_bytes: %lu  InnoDB_IO_r_wait: %s\n" \
358 +                      "#   InnoDB_rec_lock_wait: %s  InnoDB_queue_wait: %s\n" \
359 +                      "#   InnoDB_pages_distinct: %lu\n",
360 +                      (ulong) thd->innodb_io_reads,
361 +                      (ulong) thd->innodb_io_read,
362 +                      buf[0], buf[1], buf[2],
363 +                      (ulong) thd->innodb_page_access) == (uint) -1)
364 +        tmp_errno=errno;
365 +    } 
366 +    else
367 +    {
368 +      if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_INNODB)) &&
369 +          my_b_printf(&log_file,"# No InnoDB statistics available for this query\n") == (uint) -1)
370 +        tmp_errno=errno;
371 +    }
372 +
373      if (thd->db && strcmp(thd->db, db))
374      {                                          // Database changed
375        if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1)
376 --- a/sql/log.h
377 +++ b/sql/log.h
378 @@ -242,7 +242,7 @@
379               uint user_host_len, int thread_id,
380               const char *command_type, uint command_type_len,
381               const char *sql_text, uint sql_text_len);
382 -  bool write(THD *thd, time_t current_time, time_t query_start_arg,
383 +  bool write(THD *thd, ulonglong current_time, time_t query_start_arg,
384               const char *user_host, uint user_host_len,
385               ulonglong query_utime, ulonglong lock_utime, bool is_command,
386               const char *sql_text, uint sql_text_len);
387 @@ -515,7 +515,7 @@
388    virtual bool init()= 0;
389    virtual void cleanup()= 0;
390  
391 -  virtual bool log_slow(THD *thd, time_t current_time,
392 +  virtual bool log_slow(THD *thd, ulonglong current_time,
393                          time_t query_start_arg, const char *user_host,
394                          uint user_host_len, ulonglong query_utime,
395                          ulonglong lock_utime, bool is_command,
396 @@ -544,7 +544,7 @@
397    virtual bool init();
398    virtual void cleanup();
399  
400 -  virtual bool log_slow(THD *thd, time_t current_time,
401 +  virtual bool log_slow(THD *thd, ulonglong current_utime,
402                          time_t query_start_arg, const char *user_host,
403                          uint user_host_len, ulonglong query_utime,
404                          ulonglong lock_utime, bool is_command,
405 @@ -576,7 +576,7 @@
406    virtual bool init();
407    virtual void cleanup();
408  
409 -  virtual bool log_slow(THD *thd, time_t current_time,
410 +  virtual bool log_slow(THD *thd, ulonglong current_utime,
411                          time_t query_start_arg, const char *user_host,
412                          uint user_host_len, ulonglong query_utime,
413                          ulonglong lock_utime, bool is_command,
414 --- a/sql/mysqld.cc
415 +++ b/sql/mysqld.cc
416 @@ -421,6 +421,10 @@
417  char* opt_secure_file_priv;
418  my_bool opt_log_slow_admin_statements= 0;
419  my_bool opt_log_slow_slave_statements= 0;
420 +my_bool opt_log_slow_sp_statements= 0;
421 +my_bool opt_slow_query_log_timestamp_always= 0;
422 +ulonglong opt_slow_query_log_use_global_control= 0;
423 +ulong opt_slow_query_log_timestamp_precision= 0;
424  my_bool lower_case_file_system= 0;
425  my_bool opt_large_pages= 0;
426  my_bool opt_super_large_pages= 0;
427 @@ -5896,10 +5900,10 @@
428     "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to "
429     "the slow log if it is open.", &opt_log_slow_admin_statements,
430     &opt_log_slow_admin_statements, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
431 - {"log-slow-slave-statements", 0,
432 + /*{"log-slow-slave-statements", 0,
433    "Log slow statements executed by slave thread to the slow log if it is open.",
434    &opt_log_slow_slave_statements, &opt_log_slow_slave_statements,
435 -  0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
436 +  0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},*/
437    {"log-slow-queries", OPT_SLOW_QUERY_LOG,
438     "Log slow queries to a table or log file. Defaults logging to table "
439     "mysql.slow_log or hostname-slow.log if --log-output=file is used. "
440 @@ -7288,6 +7292,10 @@
441  
442  C_MODE_END
443  
444 +/* defined in sys_vars.cc */
445 +extern void init_log_slow_verbosity();
446 +extern void init_slow_query_log_use_global_control();
447 +
448  /**
449    Get server options from the command line,
450    and perform related server initializations.
451 @@ -7437,6 +7445,8 @@
452    global_system_variables.long_query_time= (ulonglong)
453      (global_system_variables.long_query_time_double * 1e6);
454  
455 +  init_log_slow_verbosity();
456 +  init_slow_query_log_use_global_control();
457    if (opt_short_log_format)
458      opt_specialflag|= SPECIAL_SHORT_LOG_FORMAT;
459  
460 --- a/sql/mysqld.h
461 +++ b/sql/mysqld.h
462 @@ -116,6 +116,10 @@
463  extern char* opt_secure_backup_file_priv;
464  extern size_t opt_secure_backup_file_priv_len;
465  extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements;
466 +extern my_bool opt_log_slow_sp_statements;
467 +extern my_bool opt_slow_query_log_timestamp_always;
468 +extern ulonglong opt_slow_query_log_use_global_control;
469 +extern ulong opt_slow_query_log_timestamp_precision;
470  extern my_bool sp_automatic_privileges, opt_noacl;
471  extern my_bool opt_old_style_user_limits, trust_function_creators;
472  extern uint opt_crash_binlog_innodb;
473 --- a/sql/slave.cc
474 +++ b/sql/slave.cc
475 @@ -2038,6 +2038,7 @@
476      + MAX_LOG_EVENT_HEADER;  /* note, incr over the global not session var */
477    thd->slave_thread = 1;
478    thd->enable_slow_log= opt_log_slow_slave_statements;
479 +  thd->write_to_slow_log= opt_log_slow_slave_statements;
480    set_slave_thread_options(thd);
481    thd->client_capabilities = CLIENT_LOCAL_FILES;
482    mysql_mutex_lock(&LOCK_thread_count);
483 --- a/sql/sp_head.cc
484 +++ b/sql/sp_head.cc
485 @@ -2152,7 +2152,7 @@
486      DBUG_PRINT("info",(" %.*s: eval args done", (int) m_name.length, 
487                         m_name.str));
488    }
489 -  if (!(m_flags & LOG_SLOW_STATEMENTS) && thd->enable_slow_log)
490 +  if (!(m_flags & LOG_SLOW_STATEMENTS || opt_log_slow_sp_statements) && thd->enable_slow_log)
491    {
492      DBUG_PRINT("info", ("Disabling slow log for the execution"));
493      save_enable_slow_log= true;
494 --- a/sql/sql_cache.cc
495 +++ b/sql/sql_cache.cc
496 @@ -1756,6 +1756,7 @@
497      response, we can't handle it anyway.
498    */
499    (void) trans_commit_stmt(thd);
500 +  thd->query_plan_flags|= QPLAN_QC;
501    if (!thd->stmt_da->is_set())
502      thd->stmt_da->disable_status();
503  
504 @@ -1766,6 +1767,7 @@
505  err_unlock:
506    unlock();
507  err:
508 +  thd->query_plan_flags|= QPLAN_QC_NO;
509    MYSQL_QUERY_CACHE_MISS(thd->query());
510    DBUG_RETURN(0);                              // Query was not cached
511  }
512 --- a/sql/sql_class.cc
513 +++ b/sql/sql_class.cc
514 @@ -616,6 +616,37 @@
515    thd->warning_info->inc_current_row_for_warning();
516  }
517  
518 +extern "C"
519 +void increment_thd_innodb_stats(THD* thd,
520 +                    unsigned long long trx_id,
521 +                    long io_reads,
522 +                    long long  io_read,
523 +                    long      io_reads_wait_timer,
524 +                    long      lock_que_wait_timer,
525 +                    long      que_wait_timer,
526 +                    long      page_access)
527 +{
528 +  thd->innodb_was_used = TRUE;
529 +  thd->innodb_trx_id = trx_id;
530 +  thd->innodb_io_reads += io_reads;
531 +  thd->innodb_io_read += io_read;
532 +  thd->innodb_io_reads_wait_timer += io_reads_wait_timer;
533 +  thd->innodb_lock_que_wait_timer += lock_que_wait_timer;
534 +  thd->innodb_innodb_que_wait_timer += que_wait_timer;
535 +  thd->innodb_page_access += page_access;
536 +}
537 +
538 +extern "C"
539 +unsigned long thd_log_slow_verbosity(const THD *thd)
540 +{
541 +  return (unsigned long) thd->variables.log_slow_verbosity;
542 +}
543 +
544 +extern "C"
545 +int thd_opt_slow_log()
546 +{
547 +  return (int) opt_slow_log;
548 +}
549  
550  /**
551    Dumps a text description of a thread, its security context
552 @@ -912,6 +943,7 @@
553      *cond_hdl= NULL;
554      return FALSE;
555    }
556 +  last_errno= sql_errno;
557  
558    for (Internal_error_handler *error_handler= m_internal_handler;
559         error_handler;
560 @@ -3656,6 +3688,12 @@
561      first_successful_insert_id_in_prev_stmt;
562    backup->first_successful_insert_id_in_cur_stmt= 
563      first_successful_insert_id_in_cur_stmt;
564 +  backup->innodb_io_reads= innodb_io_reads;
565 +  backup->innodb_io_read= innodb_io_read;
566 +  backup->innodb_io_reads_wait_timer= innodb_io_reads_wait_timer;
567 +  backup->innodb_lock_que_wait_timer= innodb_lock_que_wait_timer;
568 +  backup->innodb_innodb_que_wait_timer= innodb_innodb_que_wait_timer;
569 +  backup->innodb_page_access= innodb_page_access;
570  
571    if ((!lex->requires_prelocking() || is_update_query(lex->sql_command)) &&
572        !is_current_stmt_binlog_format_row())
573 @@ -3676,6 +3714,14 @@
574    cuted_fields= 0;
575    transaction.savepoints= 0;
576    first_successful_insert_id_in_cur_stmt= 0;
577 +  last_errno= 0;
578 +  innodb_trx_id= 0;
579 +  innodb_io_reads= 0;
580 +  innodb_io_read= 0;
581 +  innodb_io_reads_wait_timer= 0;
582 +  innodb_lock_que_wait_timer= 0;
583 +  innodb_innodb_que_wait_timer= 0;
584 +  innodb_page_access= 0;
585  }
586  
587  
588 @@ -3738,6 +3784,12 @@
589    */
590    examined_row_count+= backup->examined_row_count;
591    cuted_fields+=       backup->cuted_fields;
592 +  innodb_io_reads+= backup->innodb_io_reads;
593 +  innodb_io_read+= backup->innodb_io_read;
594 +  innodb_io_reads_wait_timer+= backup->innodb_io_reads_wait_timer;
595 +  innodb_lock_que_wait_timer+= backup->innodb_lock_que_wait_timer;
596 +  innodb_innodb_que_wait_timer+= backup->innodb_innodb_que_wait_timer;
597 +  innodb_page_access+= backup->innodb_page_access;
598    DBUG_VOID_RETURN;
599  }
600  
601 --- a/sql/sql_class.h
602 +++ b/sql/sql_class.h
603 @@ -60,6 +60,33 @@
604  enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
605  enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON,
606                             DELAY_KEY_WRITE_ALL };
607 +enum enum_slow_query_log_use_global_control {
608 +  SLOG_UG_LOG_SLOW_FILTER, SLOG_UG_LOG_SLOW_RATE_LIMIT
609 +  , SLOG_UG_LOG_SLOW_VERBOSITY, SLOG_UG_LONG_QUERY_TIME
610 +  , SLOG_UG_MIN_EXAMINED_ROW_LIMIT, SLOG_UG_ALL
611 +};
612 +enum enum_log_slow_verbosity { 
613 +  SLOG_V_MICROTIME, SLOG_V_QUERY_PLAN, SLOG_V_INNODB, 
614 +  SLOG_V_PROFILING, SLOG_V_PROFILING_USE_GETRUSAGE,
615 +  SLOG_V_MINIMAL, SLOG_V_STANDARD, SLOG_V_FULL
616 +};
617 +enum enum_slow_query_log_timestamp_precision {
618 +  SLOG_SECOND, SLOG_MICROSECOND
619 +};
620 +#define QPLAN_NONE            0
621 +#define QPLAN_QC              1 << 0
622 +#define QPLAN_QC_NO           1 << 1
623 +#define QPLAN_FULL_SCAN       1 << 2
624 +#define QPLAN_FULL_JOIN       1 << 3
625 +#define QPLAN_TMP_TABLE       1 << 4
626 +#define QPLAN_TMP_DISK        1 << 5
627 +#define QPLAN_FILESORT        1 << 6
628 +#define QPLAN_FILESORT_DISK   1 << 7
629 +enum enum_log_slow_filter {
630 +  SLOG_F_QC_NO, SLOG_F_FULL_SCAN, SLOG_F_FULL_JOIN,
631 +  SLOG_F_TMP_TABLE, SLOG_F_TMP_DISK, SLOG_F_FILESORT,
632 +  SLOG_F_FILESORT_DISK
633 +};
634  enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT,
635                              SLAVE_EXEC_MODE_IDEMPOTENT,
636                              SLAVE_EXEC_MODE_LAST_BIT};
637 @@ -508,6 +535,21 @@
638  
639    my_bool sysdate_is_now;
640  
641 +#ifndef DBUG_OFF
642 +  ulonglong query_exec_time;
643 +  double    query_exec_time_double;
644 +#endif
645 +  ulong log_slow_rate_limit;
646 +  ulonglong log_slow_filter;
647 +  ulonglong log_slow_verbosity;
648 +
649 +  ulong      innodb_io_reads;
650 +  ulonglong  innodb_io_read;
651 +  ulong      innodb_io_reads_wait_timer;
652 +  ulong      innodb_lock_que_wait_timer;
653 +  ulong      innodb_innodb_que_wait_timer;
654 +  ulong      innodb_page_access;
655 +
656    double long_query_time_double;
657  
658  } SV;
659 @@ -1140,6 +1182,14 @@
660    uint in_sub_stmt;
661    bool enable_slow_log;
662    bool last_insert_id_used;
663 +
664 +  ulong      innodb_io_reads;
665 +  ulonglong  innodb_io_read;
666 +  ulong      innodb_io_reads_wait_timer;
667 +  ulong      innodb_lock_que_wait_timer;
668 +  ulong      innodb_innodb_que_wait_timer;
669 +  ulong      innodb_page_access;
670 +
671    SAVEPOINT *savepoints;
672    enum enum_check_fields count_cuted_fields;
673  };
674 @@ -1588,6 +1638,26 @@
675    thr_lock_type update_lock_default;
676    Delayed_insert *di;
677  
678 +  bool       write_to_slow_log;
679 +
680 +  ulonglong  bytes_sent_old;
681 +  ulong      tmp_tables_used;
682 +  ulong      tmp_tables_disk_used;
683 +  ulonglong  tmp_tables_size;
684 +  bool       innodb_was_used;
685 +  ulonglong  innodb_trx_id;
686 +  ulong      innodb_io_reads;
687 +  ulonglong  innodb_io_read;
688 +  ulong      innodb_io_reads_wait_timer;
689 +  ulong      innodb_lock_que_wait_timer;
690 +  ulong      innodb_innodb_que_wait_timer;
691 +  ulong      innodb_page_access;
692 +
693 +  ulong      query_plan_flags;
694 +  ulong      query_plan_fsort_passes;
695 +
696 +  uint       last_errno;
697 +
698    /* <> 0 if we are inside of trigger or stored function. */
699    uint in_sub_stmt;
700  
701 --- a/sql/sql_connect.cc
702 +++ b/sql/sql_connect.cc
703 @@ -721,6 +721,15 @@
704    MYSQL_CONNECTION_START(thd->thread_id, &thd->security_ctx->priv_user[0],
705                           (char *) thd->security_ctx->host_or_ip);
706  
707 +    /* 
708 +      If rate limiting of slow log writes is enabled, decide whether to log this 
709 +      new thread's queries or not. Uses extremely simple algorithm. :) 
710 +    */ 
711 +    thd->write_to_slow_log= FALSE; 
712 +    if (thd->variables.log_slow_rate_limit <= 1 ||  
713 +        (thd->thread_id % thd->variables.log_slow_rate_limit) == 0) 
714 +         thd->write_to_slow_log= TRUE; 
715 +
716    prepare_new_connection_state(thd);
717    return FALSE;
718  }
719 --- a/sql/sql_parse.cc
720 +++ b/sql/sql_parse.cc
721 @@ -114,6 +114,7 @@
722  
723  static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
724  static void sql_kill(THD *thd, ulong id, bool only_kill_query);
725 +static inline ulonglong get_query_exec_time(THD *thd, ulonglong cur_utime);
726  
727  const char *any_db="*any*";    // Special symbol for check_access
728  
729 @@ -1430,6 +1431,60 @@
730    DBUG_RETURN(error);
731  }
732  
733 +/**
734 +   Calculate execution time for the current query.
735 +
736 +   For debug builds, check the session value of query_exec_time
737 +   and if it is not zero, return it instead of the actual execution time.
738 +
739 +   SET queries are ignored so that statements changing query_exec_time are not
740 +   affected by themselves.
741 +
742 +   @param thd              thread handle
743 +   @param lex              current relative time in microseconds
744 +
745 +   @return                 time in microseconds from utime_after_lock
746 +*/
747 +
748 +static inline ulonglong get_query_exec_time(THD *thd, ulonglong cur_utime)
749 +{
750 +  ulonglong res;
751 +#ifndef DBUG_OFF
752 +  if (thd->variables.query_exec_time != 0)
753 +    res= thd->lex->sql_command != SQLCOM_SET_OPTION ?
754 +      thd->variables.query_exec_time : 0;
755 +  else
756 +#endif
757 +
758 +  res= cur_utime - thd->utime_after_lock;
759 +
760 +  if (res > thd->variables.long_query_time)
761 +    thd->server_status|= SERVER_QUERY_WAS_SLOW;
762 +  else
763 +    thd->server_status&= ~SERVER_QUERY_WAS_SLOW;
764 +
765 +  return res;
766 +}
767 +
768 +
769 +static inline void copy_global_to_session(THD *thd, ulong flag,
770 +                                          const ulong *val)
771 +{
772 +  my_ptrdiff_t offset = ((char *)val - (char *)&global_system_variables);
773 +  if (opt_slow_query_log_use_global_control & (1ULL << flag))
774 +    *(ulong *)((char *) &thd->variables + offset) = *val;
775 +}
776 +
777 +
778 +static inline void copy_global_to_session(THD *thd, ulong flag,
779 +                                          const ulonglong *val)
780 +{
781 +  my_ptrdiff_t offset = ((char *)val - (char *)&global_system_variables);
782 +  if (opt_slow_query_log_use_global_control & (1ULL << flag))
783 +    *(ulonglong *)((char *) &thd->variables + offset) = *val;
784 +}
785 +
786 +
787  
788  void log_slow_statement(THD *thd)
789  {
790 @@ -1443,13 +1498,48 @@
791    if (unlikely(thd->in_sub_stmt))
792      DBUG_VOID_RETURN;                           // Don't set time for sub stmt
793  
794 +  /* Follow the slow log filter configuration. */
795 +  if (thd->variables.log_slow_filter != 0 &&
796 +      (!(thd->variables.log_slow_filter & thd->query_plan_flags) ||
797 +       ((thd->variables.log_slow_filter & SLOG_F_QC_NO) &&
798 +        (thd->query_plan_flags & QPLAN_QC))))
799 +    DBUG_VOID_RETURN;
800 +
801 +  ulonglong end_utime_of_query= thd->current_utime();
802 +  ulonglong query_exec_time= get_query_exec_time(thd, end_utime_of_query);
803 +
804 +  /*
805 +    Low long_query_time value most likely means user is debugging stuff and even
806 +    though some thread's queries are not supposed to be logged b/c of the rate
807 +    limit, if one of them takes long enough (>= 1 second) it will be sensible
808 +    to make an exception and write to slow log anyway.
809 +  */
810 +
811 +  system_variables const &g= global_system_variables;
812 +  copy_global_to_session(thd, SLOG_UG_LOG_SLOW_FILTER,
813 +                         &g.log_slow_filter);
814 +  copy_global_to_session(thd, SLOG_UG_LOG_SLOW_RATE_LIMIT,
815 +                         &g.log_slow_rate_limit);
816 +  copy_global_to_session(thd, SLOG_UG_LOG_SLOW_VERBOSITY,
817 +                         &g.log_slow_verbosity);
818 +  copy_global_to_session(thd, SLOG_UG_LONG_QUERY_TIME,
819 +                         &g.long_query_time);
820 +  copy_global_to_session(thd, SLOG_UG_MIN_EXAMINED_ROW_LIMIT,
821 +                         &g.min_examined_row_limit);
822 +
823 +  /* Do not log this thread's queries due to rate limiting. */
824 +  if (thd->write_to_slow_log != TRUE
825 +      && (thd->variables.long_query_time >= 1000000
826 +          || (ulong) query_exec_time < 1000000))
827 +    DBUG_VOID_RETURN;
828 +
829 +
830    /*
831      Do not log administrative statements unless the appropriate option is
832      set.
833    */
834    if (thd->enable_slow_log)
835    {
836 -    ulonglong end_utime_of_query= thd->current_utime();
837      thd_proc_info(thd, "logging slow query");
838  
839      if (((thd->server_status & SERVER_QUERY_WAS_SLOW) ||
840 @@ -1879,6 +1969,9 @@
841      context.resolve_in_table_list_only(select_lex->
842                                         table_list.first);
843  
844 +  /* Reset the counter at all cases for the extended slow query log */
845 +  thd->sent_row_count= 0;
846 +
847    /*
848      Reset warning count for each query that uses tables
849      A better approach would be to reset this for any commands
850 @@ -5297,6 +5390,21 @@
851    thd->rand_used= 0;
852    thd->sent_row_count= thd->examined_row_count= 0;
853  
854 +  thd->bytes_sent_old= thd->status_var.bytes_sent;
855 +  thd->tmp_tables_used= thd->tmp_tables_disk_used= 0;
856 +  thd->tmp_tables_size= 0;
857 +  thd->innodb_was_used= FALSE;
858 +  thd->innodb_trx_id= 0;
859 +  thd->innodb_io_reads= 0;
860 +  thd->innodb_io_read= 0;
861 +  thd->innodb_io_reads_wait_timer= 0;
862 +  thd->innodb_lock_que_wait_timer= 0;
863 +  thd->innodb_innodb_que_wait_timer= 0;
864 +  thd->innodb_page_access= 0;
865 +  thd->query_plan_flags= QPLAN_NONE;
866 +  thd->query_plan_fsort_passes= 0;
867 +  thd->last_errno= 0;
868 +
869    thd->reset_current_stmt_binlog_format_row();
870    thd->binlog_unsafe_warning_flags= 0;
871  
872 --- a/sql/sql_select.cc
873 +++ b/sql/sql_select.cc
874 @@ -6902,7 +6902,10 @@
875           {
876             join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
877             if (statistics)
878 +            {
879               status_var_increment(join->thd->status_var.select_scan_count);
880 +              join->thd->query_plan_flags|= QPLAN_FULL_SCAN;
881 +            }
882           }
883         }
884         else
885 @@ -6916,7 +6919,10 @@
886           {
887             join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
888             if (statistics)
889 +            {
890               status_var_increment(join->thd->status_var.select_full_join_count);
891 +              join->thd->query_plan_flags|= QPLAN_FULL_JOIN;
892 +            }
893           }
894         }
895         if (!table->no_keyread)
896 @@ -10264,6 +10270,7 @@
897                (ulong) rows_limit,test(group)));
898  
899    status_var_increment(thd->status_var.created_tmp_tables);
900 +  thd->query_plan_flags|= QPLAN_TMP_TABLE;
901  
902    if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
903      temp_pool_slot = bitmap_lock_set_next(&temp_pool);
904 @@ -11162,6 +11169,7 @@
905      goto err;
906    }
907    status_var_increment(table->in_use->status_var.created_tmp_disk_tables);
908 +  table->in_use->query_plan_flags|= QPLAN_TMP_DISK;
909    share->db_record_offset= 1;
910    DBUG_RETURN(0);
911   err:
912 @@ -11180,6 +11188,14 @@
913    save_proc_info=thd->proc_info;
914    thd_proc_info(thd, "removing tmp table");
915  
916 +  thd->tmp_tables_used++;
917 +  if (entry->file)
918 +  {
919 +    thd->tmp_tables_size += entry->file->stats.data_file_length;
920 +    if (entry->file->ht->db_type != DB_TYPE_HEAP)
921 +      thd->tmp_tables_disk_used++;
922 +  }
923 +
924    // Release latches since this can take a long time
925    ha_release_temporary_latches(thd);
926  
927 --- a/sql/sql_show.cc
928 +++ b/sql/sql_show.cc
929 @@ -1950,8 +1950,17 @@
930          table->field[4]->store(command_name[tmp->command].str,
931                                 command_name[tmp->command].length, cs);
932        /* MYSQL_TIME */
933 -      table->field[5]->store((longlong)(tmp->start_time ?
934 -                                      now - tmp->start_time : 0), FALSE);
935 +      longlong value_in_time_column= 0;
936 +      if(tmp->start_time)
937 +      {
938 +        value_in_time_column = (now - tmp->start_time);
939 +        if(value_in_time_column > now)
940 +        {
941 +          value_in_time_column= 0;
942 +        }
943 +      }
944 +      table->field[5]->store(value_in_time_column, FALSE);
945 +
946        /* STATE */
947        if ((val= thread_state_info(tmp)))
948        {
949 --- a/sql/sys_vars.cc
950 +++ b/sql/sys_vars.cc
951 @@ -972,6 +972,29 @@
952         NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
953         ON_UPDATE(update_cached_long_query_time));
954  
955 +#ifndef DBUG_OFF
956 +static bool update_cached_query_exec_time(sys_var *self, THD *thd,
957 +                                          enum_var_type type)
958 +{
959 +  if (type == OPT_SESSION)
960 +    thd->variables.query_exec_time=
961 +      double2ulonglong(thd->variables.query_exec_time_double * 1e6);
962 +  else
963 +    global_system_variables.query_exec_time=
964 +      double2ulonglong(global_system_variables.query_exec_time_double * 1e6);
965 +  return false;
966 +}
967 +
968 +static Sys_var_double Sys_query_exec_time(
969 +       "query_exec_time",
970 +       "Pretend queries take this many seconds. When 0 (the default) use the "
971 +       "actual execution time. Used only for debugging.",
972 +       SESSION_VAR(query_exec_time_double),
973 +       NO_CMD_LINE, VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(0),
974 +       NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
975 +       ON_UPDATE(update_cached_query_exec_time));
976 +#endif
977 +
978  static bool fix_low_prio_updates(sys_var *self, THD *thd, enum_var_type type)
979  {
980    if (type == OPT_SESSION)
981 @@ -2898,6 +2921,117 @@
982         DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
983         ON_UPDATE(fix_log_state));
984  
985 +const char *log_slow_filter_name[]= { "qc_miss", "full_scan", "full_join",
986 +                                      "tmp_table", "tmp_table_on_disk", "filesort", "filesort_on_disk", 0};
987 +static Sys_var_set Sys_log_slow_filter(
988 +       "log_slow_filter",
989 +       "Log only the queries that followed certain execution plan. "
990 +       "Multiple flags allowed in a comma-separated string. "
991 +       "[qc_miss, full_scan, full_join, tmp_table, tmp_table_on_disk, "
992 +       "filesort, filesort_on_disk]",
993 +       SESSION_VAR(log_slow_filter), CMD_LINE(REQUIRED_ARG),
994 +       log_slow_filter_name, DEFAULT(0));
995 +static Sys_var_ulong sys_log_slow_rate_limit(
996 +       "log_slow_rate_limit","Rate limit statement writes to slow log to only those from every (1/log_slow_rate_limit) session.",
997 +       SESSION_VAR(log_slow_rate_limit), CMD_LINE(REQUIRED_ARG),
998 +       VALID_RANGE(1, ULONG_MAX), DEFAULT(1), BLOCK_SIZE(1));
999 +const char* log_slow_verbosity_name[] = { 
1000 +  "microtime", "query_plan", "innodb", 
1001 +  "profiling", "profling_use_getrusage", 
1002 +  "minimal", "standard", "full", 0
1003 +};
1004 +static ulonglong update_log_slow_verbosity_replace(ulonglong value, ulonglong what, ulonglong by)
1005 +{
1006 +  if((value & what) == what)
1007 +  {
1008 +    value = value & (~what);
1009 +    value = value | by;
1010 +  }
1011 +  return value;
1012 +}
1013 +void update_log_slow_verbosity(ulonglong* value_ptr)
1014 +{
1015 +  ulonglong &value    = *value_ptr;
1016 +  ulonglong microtime= ULL(1) << SLOG_V_MICROTIME;
1017 +  ulonglong query_plan= ULL(1) << SLOG_V_QUERY_PLAN;
1018 +  ulonglong innodb= ULL(1) << SLOG_V_INNODB;
1019 +  ulonglong minimal= ULL(1) << SLOG_V_MINIMAL;
1020 +  ulonglong standard= ULL(1) << SLOG_V_STANDARD;
1021 +  ulonglong full= ULL(1) << SLOG_V_FULL;
1022 +  value= update_log_slow_verbosity_replace(value,minimal,microtime);
1023 +  value= update_log_slow_verbosity_replace(value,standard,microtime | query_plan);
1024 +  value= update_log_slow_verbosity_replace(value,full,microtime | query_plan | innodb);
1025 +}
1026 +static bool update_log_slow_verbosity_helper(sys_var */*self*/, THD *thd,
1027 +                                          enum_var_type type)
1028 +{
1029 +  if(type == OPT_SESSION)
1030 +  {
1031 +    update_log_slow_verbosity(&(thd->variables.log_slow_verbosity));
1032 +  }
1033 +  else
1034 +  {
1035 +    update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
1036 +  }
1037 +  return false;
1038 +}
1039 +void init_slow_query_log_use_global_control()
1040 +{
1041 +  update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
1042 +}
1043 +static Sys_var_set Sys_log_slow_verbosity(
1044 +        "log_slow_verbosity",
1045 +        "Choose how verbose the messages to your slow log will be. "
1046 +        "Multiple flags allowed in a comma-separated string. [microtime, query_plan, innodb, profiling, profiling_use_getrusage]",
1047 +        SESSION_VAR(log_slow_verbosity), CMD_LINE(REQUIRED_ARG),
1048 +        log_slow_verbosity_name, DEFAULT(SLOG_V_MICROTIME),
1049 +        NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1050 +        ON_UPDATE(update_log_slow_verbosity_helper));
1051 +static Sys_var_mybool Sys_log_slow_slave_statements(
1052 +       "log_slow_slave_statements",
1053 +       "Log queries replayed be the slave SQL thread",
1054 +       GLOBAL_VAR(opt_log_slow_slave_statements), CMD_LINE(OPT_ARG),
1055 +       DEFAULT(FALSE));
1056 +static Sys_var_mybool Sys_log_slow_sp_statements(
1057 +       "log_slow_sp_statements",
1058 +       "Log slow statements executed by stored procedure to the slow log if it is open.",
1059 +       GLOBAL_VAR(opt_log_slow_sp_statements), CMD_LINE(OPT_ARG),
1060 +       DEFAULT(TRUE));
1061 +static Sys_var_mybool Sys_slow_query_log_timestamp_always(
1062 +       "slow_query_log_timestamp_always",
1063 +       "Timestamp is printed for all records of the slow log even if they are same time.",
1064 +       GLOBAL_VAR(opt_slow_query_log_timestamp_always), CMD_LINE(OPT_ARG),
1065 +       DEFAULT(FALSE));
1066 +const char *slow_query_log_use_global_control_name[]= { "log_slow_filter", "log_slow_rate_limit", "log_slow_verbosity", "long_query_time", "min_examined_row_limit", "all", 0};
1067 +static bool update_slow_query_log_use_global_control(sys_var */*self*/, THD */*thd*/,
1068 +                                               enum_var_type /*type*/)
1069 +{
1070 +  if(opt_slow_query_log_use_global_control & (ULL(1) << SLOG_UG_ALL))
1071 +  {
1072 +    opt_slow_query_log_use_global_control=
1073 +      SLOG_UG_LOG_SLOW_FILTER | SLOG_UG_LOG_SLOW_RATE_LIMIT | SLOG_UG_LOG_SLOW_VERBOSITY |
1074 +      SLOG_UG_LONG_QUERY_TIME | SLOG_UG_MIN_EXAMINED_ROW_LIMIT;
1075 +  }
1076 +  return false;
1077 +}
1078 +void init_log_slow_verbosity()
1079 +{
1080 +  update_slow_query_log_use_global_control(0,0,OPT_GLOBAL);
1081 +}
1082 +static Sys_var_set Sys_slow_query_log_use_global_control(
1083 +       "slow_query_log_use_global_control",
1084 +       "Choose flags, wich always use the global variables. Multiple flags allowed in a comma-separated string. [none, log_slow_filter, log_slow_rate_limit, log_slow_verbosity, long_query_time, min_examined_row_limit, all]",
1085 +       GLOBAL_VAR(opt_slow_query_log_use_global_control), CMD_LINE(REQUIRED_ARG),
1086 +       slow_query_log_use_global_control_name, DEFAULT(0),
1087 +        NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1088 +       ON_UPDATE(update_slow_query_log_use_global_control));
1089 +const char *slow_query_log_timestamp_precision_name[]= { "second", "microsecond", 0 };
1090 +static Sys_var_enum Sys_slow_query_log_timestamp_precision(
1091 +       "slow_query_log_timestamp_precision",
1092 +       "Log slow statements executed by stored procedure to the slow log if it is open. [second, microsecond]",
1093 +       GLOBAL_VAR(opt_slow_query_log_timestamp_precision), CMD_LINE(REQUIRED_ARG),
1094 +       slow_query_log_timestamp_precision_name, DEFAULT(SLOG_SECOND));
1095
1096  /* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
1097  static Sys_var_mybool Sys_log_slow(
1098         "log_slow_queries",
1099 --- a/sql/sql_profile.cc
1100 +++ b/sql/sql_profile.cc
1101 @@ -243,7 +243,8 @@
1102  {
1103    time_usecs= (double) my_getsystime() / 10.0;  /* 1 sec was 1e7, now is 1e6 */
1104  #ifdef HAVE_GETRUSAGE
1105 -  getrusage(RUSAGE_SELF, &rusage);
1106 +  if ((profile->get_profiling())->enabled_getrusage())
1107 +    getrusage(RUSAGE_SELF, &rusage);
1108  #elif defined(_WIN32)
1109    FILETIME ftDummy;
1110    // NOTE: Get{Process|Thread}Times has a granularity of the clock interval,
1111 @@ -251,6 +252,19 @@
1112    // measurable by this function.
1113    GetProcessTimes(GetCurrentProcess(), &ftDummy, &ftDummy, &ftKernel, &ftUser);
1114  #endif
1115 +
1116 +#ifdef HAVE_CLOCK_GETTIME
1117 +  struct timespec tp;
1118 +
1119 +  if (!(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
1120 +  {
1121 +    cpu_time_usecs= tp.tv_sec*1000000000.0 + tp.tv_nsec;
1122 +  }
1123 +  else
1124 +#endif
1125 +  {
1126 +    cpu_time_usecs= 0;
1127 +  }
1128  }
1129  
1130  
1131 @@ -366,7 +380,8 @@
1132      finish_current_query();
1133    }
1134  
1135 -  enabled= ((thd->variables.option_bits & OPTION_PROFILING) != 0);
1136 +  enabled= ((thd->variables.option_bits & OPTION_PROFILING) != 0) ||
1137 +            ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING)) != 0);
1138  
1139    if (! enabled) DBUG_VOID_RETURN;
1140  
1141 @@ -404,7 +419,8 @@
1142      status_change("ending", NULL, NULL, 0);
1143  
1144      if ((enabled) &&                                    /* ON at start? */
1145 -        ((thd->variables.option_bits & OPTION_PROFILING) != 0) &&   /* and ON at end? */
1146 +        (((thd->variables.option_bits & OPTION_PROFILING) != 0) ||
1147 +          ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING)) != 0)) &&   /* and ON at end? */
1148          (current->query_source != NULL) &&
1149          (! current->entries.is_empty()))
1150      {
1151 @@ -505,6 +521,118 @@
1152    DBUG_VOID_RETURN;
1153  }
1154  
1155 +bool PROFILING::enabled_getrusage()
1156 +{
1157 +  return ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING_USE_GETRUSAGE)) != 0);
1158 +}
1159 +
1160 +/**
1161 +   For a given profile entry specified by a name and 2 time measurements,
1162 +   print its normalized name (i.e. with all spaces replaced with underscores)
1163 +   along with its wall clock and CPU time.
1164 +*/
1165 +
1166 +static void my_b_print_status(IO_CACHE *log_file, const char *status,
1167 +                              PROF_MEASUREMENT *start, PROF_MEASUREMENT *stop)
1168 +{
1169 +  DBUG_ENTER("my_b_print_status");
1170 +  DBUG_ASSERT(log_file != NULL && status != NULL);
1171 +  char query_time_buff[22+7];
1172 +  const char *tmp;
1173 +
1174 +  my_b_printf(log_file, "Profile_");
1175 +  for (tmp= status; *tmp; tmp++)
1176 +    my_b_write_byte(log_file, *tmp == ' ' ? '_' : *tmp);
1177 +
1178 +  snprintf(query_time_buff, sizeof(query_time_buff), "%.6f",
1179 +           (stop->time_usecs - start->time_usecs) / (1000.0 * 1000));
1180 +  my_b_printf(log_file, ": %s ", query_time_buff);
1181 +
1182 +  my_b_printf(log_file, "Profile_");
1183 +  for (tmp= status; *tmp; tmp++)
1184 +    my_b_write_byte(log_file, *tmp == ' ' ? '_' : *tmp);
1185 +  my_b_printf(log_file, "_cpu: ");
1186 +
1187 +  snprintf(query_time_buff, sizeof(query_time_buff), "%.6f",
1188 +           (stop->cpu_time_usecs - start->cpu_time_usecs) /
1189 +           (1000.0 * 1000 * 1000));
1190 +  my_b_printf(log_file, "%s ", query_time_buff);
1191 +
1192 +  DBUG_VOID_RETURN;
1193 +}
1194 +
1195 +/**
1196 +  Print output for current query to file 
1197 +*/
1198 +
1199 +int PROFILING::print_current(IO_CACHE *log_file)
1200 +{
1201 +  DBUG_ENTER("PROFILING::print_current");
1202 +  ulonglong row_number= 0;
1203 +
1204 +  QUERY_PROFILE *query;
1205 +  /* Get current query */
1206 +  if (current == NULL)
1207 +  {
1208 +    DBUG_RETURN(0);
1209 +  }
1210 +
1211 +  query= current;
1212 +
1213 +  my_b_printf(log_file, "# ");
1214 +
1215 +    void *entry_iterator;
1216 +    PROF_MEASUREMENT *entry= NULL, *previous= NULL, *first= NULL;
1217 +    /* ...and for each query, go through all its state-change steps. */
1218 +    for (entry_iterator= query->entries.new_iterator();
1219 +         entry_iterator != NULL;
1220 +         entry_iterator= query->entries.iterator_next(entry_iterator),
1221 +         previous=entry, row_number++)
1222 +    {
1223 +      entry= query->entries.iterator_value(entry_iterator);
1224 +
1225 +      /* Skip the first.  We count spans of fence, not fence-posts. */
1226 +      if (previous == NULL) {first= entry; continue;}
1227 +
1228 +      if (thd->lex->sql_command == SQLCOM_SHOW_PROFILE)
1229 +      {
1230 +        /*
1231 +          We got here via a SHOW command.  That means that we stored
1232 +          information about the query we wish to show and that isn't
1233 +          in a WHERE clause at a higher level to filter out rows we
1234 +          wish to exclude.
1235 +
1236 +          Because that functionality isn't available in the server yet,
1237 +          we must filter here, at the wrong level.  Once one can con-
1238 +          struct where and having conditions at the SQL layer, then this
1239 +          condition should be ripped out.
1240 +        */
1241 +        if (thd->lex->profile_query_id == 0) /* 0 == show final query */
1242 +        {
1243 +          if (query != last)
1244 +            continue;
1245 +        }
1246 +        else
1247 +        {
1248 +          if (thd->lex->profile_query_id != query->profiling_query_id)
1249 +            continue;
1250 +        }
1251 +      }
1252 +
1253 +      my_b_print_status(log_file, previous->status, previous, entry);
1254 +    }
1255 +
1256 +    my_b_write_byte(log_file, '\n');
1257 +    if ((entry != NULL) && (first != NULL))
1258 +    {
1259 +      my_b_printf(log_file, "# ");
1260 +      my_b_print_status(log_file, "total", first, entry);
1261 +      my_b_write_byte(log_file, '\n');
1262 +    }
1263 +
1264 +  DBUG_RETURN(0);
1265 +}
1266 +
1267  /**
1268    Fill the information schema table, "query_profile", as defined in show.cc .
1269    There are two ways to get to this function:  Selecting from the information
1270 @@ -600,6 +728,8 @@
1271  
1272  #ifdef HAVE_GETRUSAGE
1273  
1274 +      if (enabled_getrusage())
1275 +      {
1276        my_decimal cpu_utime_decimal, cpu_stime_decimal;
1277  
1278        double2my_decimal(E_DEC_FATAL_ERROR,
1279 @@ -687,6 +817,7 @@
1280        table->field[14]->store((uint32)(entry->rusage.ru_nswap -
1281                               previous->rusage.ru_nswap), true);
1282        table->field[14]->set_notnull();
1283 +      }
1284  #else
1285        /* TODO: Add swap info for non-BSD systems */
1286  #endif
1287 --- a/sql/sql_profile.h
1288 +++ b/sql/sql_profile.h
1289 @@ -164,11 +164,15 @@
1290  */
1291  class PROF_MEASUREMENT
1292  {
1293 -private:
1294 -  friend class QUERY_PROFILE;
1295 -  friend class PROFILING;
1296 -
1297    QUERY_PROFILE *profile;
1298 +
1299 +  char *allocated_status_memory;
1300 +
1301 +  void set_label(const char *status_arg, const char *function_arg, 
1302 +                  const char *file_arg, unsigned int line_arg);
1303 +  void clean_up();
1304 +
1305 +public:
1306    char *status;
1307  #ifdef HAVE_GETRUSAGE
1308    struct rusage rusage;
1309 @@ -181,12 +185,7 @@
1310    unsigned int line;
1311  
1312    double time_usecs;
1313 -  char *allocated_status_memory;
1314 -
1315 -  void set_label(const char *status_arg, const char *function_arg, 
1316 -                  const char *file_arg, unsigned int line_arg);
1317 -  void clean_up();
1318 -  
1319 +  double cpu_time_usecs;
1320    PROF_MEASUREMENT();
1321    PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char *status_arg);
1322    PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char *status_arg,
1323 @@ -231,6 +230,11 @@
1324  
1325    /* Show this profile.  This is called by PROFILING. */
1326    bool show(uint options);
1327 +
1328 +public:
1329 +
1330 +  inline PROFILING * get_profiling() { return profiling; };
1331 +
1332  };
1333  
1334  
1335 @@ -276,9 +280,11 @@
1336  
1337    /* SHOW PROFILES */
1338    bool show_profiles();
1339 +  bool enabled_getrusage();
1340  
1341    /* ... from INFORMATION_SCHEMA.PROFILING ... */
1342    int fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond);
1343 +  int print_current(IO_CACHE *log_file);
1344  };
1345  
1346  #  endif /* HAVE_PROFILING */
1347 --- /dev/null
1348 +++ b/mysql-test/include/log_grep.inc
1349 @@ -0,0 +1,17 @@
1350 +--disable_query_log
1351 +--echo [log_grep.inc] file: $log_file pattern: $grep_pattern
1352 +perl;
1353 +  $log_file=           $ENV{'log_file'};
1354 +  $log_file_full_path= $ENV{'log_file_full_path'};
1355 +  $grep_pattern=       $ENV{'grep_pattern'};
1356 +
1357 +  open(FILE, "$log_file_full_path") 
1358 +    or die("Cannot open file $log_file_full_path: $!\n");
1359 +
1360 +  $lines = 0;
1361 +  while(<FILE>) {
1362 +    $lines++ if (/$grep_pattern/);
1363 +  }
1364 +  close(FILE);
1365 +  print "[log_grep.inc] lines:   $lines\n";
1366 +EOF
1367 --- /dev/null
1368 +++ b/mysql-test/include/log_start.inc
1369 @@ -0,0 +1,16 @@
1370 +--disable_query_log
1371 +--let log_file_full_path = $MYSQLTEST_VARDIR/$log_file
1372 +SET @slow_query_log_old=@@slow_query_log;
1373 +SET @slow_query_log_file_old= @@slow_query_log_file;
1374 +SET GLOBAL slow_query_log=OFF;
1375 +perl;
1376 +  $log_file_full_path= $ENV{'log_file_full_path'};
1377 +  unlink $log_file_full_path;
1378 +  open(FILE, '>', $log_file_full_path)
1379 +    or die "Cannot create log file $log_file_full_path, reason: $!";
1380 +  close(FILE);
1381 +EOF
1382 +--echo [log_start.inc] $log_file
1383 +EVAL SET GLOBAL slow_query_log_file="$log_file_full_path";
1384 +SET GLOBAL slow_query_log=ON;
1385 +--enable_query_log
1386 \ No newline at end of file
1387 --- /dev/null
1388 +++ b/mysql-test/include/log_stop.inc
1389 @@ -0,0 +1,7 @@
1390 +--disable_query_log
1391 +FLUSH LOGS;
1392 +SET GLOBAL slow_query_log=OFF;
1393 +--echo [log_stop.inc] $log_file
1394 +SET GLOBAL slow_query_log_file= @slow_query_log_file_old;
1395 +SET GLOBAL slow_query_log=      @slow_query_log_old;
1396 +--enable_query_log
1397 --- /dev/null
1398 +++ b/mysql-test/r/percona_bug643149.result
1399 @@ -0,0 +1,21 @@
1400 +SET @old_slow_query_log_file=@@global.slow_query_log_file;
1401 +SET GLOBAL slow_query_log=on;
1402 +SET LOCAL log_slow_verbosity='profiling';
1403 +SET LOCAL long_query_time=0;
1404 +SET GLOBAL slow_query_log_file='MYSQLTEST_VARDIR/percona_bug643149_slow.log';;
1405 +SELECT 1;
1406 +1
1407 +1
1408 +# User@Host: root[root] @ localhost []
1409 +# Thread_id: X  Schema: test  Last_errno: X  Killed: X
1410 +# Query_time: X.X  Lock_time: X.X  Rows_sent: X  Rows_examined: X  Rows_affected: X  Rows_read: X
1411 +# Bytes_sent: X  Tmp_tables: X  Tmp_disk_tables: X  Tmp_table_sizes: X
1412 +# Profile_starting: X.X Profile_starting_cpu: X.X Profile_Opening_tables: X.X Profile_Opening_tables_cpu: X.X Profile_query_end: X.X Profile_query_end_cpu: X.X Profile_closing_tables: X.X Profile_closing_tables_cpu: X.X Profile_freeing_items: X.X Profile_freeing_items_cpu: X.X Profile_logging_slow_query: X.X Profile_logging_slow_query_cpu: X.X 
1413 +# Profile_total: X.X Profile_total_cpu: X.X 
1414 +# User@Host: root[root] @ localhost []
1415 +# Thread_id: X  Schema: test  Last_errno: X  Killed: X
1416 +# Query_time: X.X  Lock_time: X.X  Rows_sent: X  Rows_examined: X  Rows_affected: X  Rows_read: X
1417 +# Bytes_sent: X  Tmp_tables: X  Tmp_disk_tables: X  Tmp_table_sizes: X
1418 +# Profile_starting: X.X Profile_starting_cpu: X.X Profile_checking_permissions: X.X Profile_checking_permissions_cpu: X.X Profile_Opening_tables: X.X Profile_Opening_tables_cpu: X.X Profile_init: X.X Profile_init_cpu: X.X Profile_optimizing: X.X Profile_optimizing_cpu: X.X Profile_executing: X.X Profile_executing_cpu: X.X Profile_end: X.X Profile_end_cpu: X.X Profile_query_end: X.X Profile_query_end_cpu: X.X Profile_closing_tables: X.X Profile_closing_tables_cpu: X.X Profile_freeing_items: X.X Profile_freeing_items_cpu: X.X Profile_logging_slow_query: X.X Profile_logging_slow_query_cpu: X.X 
1419 +# Profile_total: X.X Profile_total_cpu: X.X 
1420 +SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
1421 --- /dev/null
1422 +++ b/mysql-test/r/percona_log_slow_filter-cl.result
1423 @@ -0,0 +1,6 @@
1424 +SHOW VARIABLES LIKE 'log_slow_filter';
1425 +Variable_name  Value
1426 +log_slow_filter        full_join
1427 +SHOW GLOBAL VARIABLES LIKE 'log_slow_filter';
1428 +Variable_name  Value
1429 +log_slow_filter        full_join
1430 --- /dev/null
1431 +++ b/mysql-test/r/percona_log_slow_filter.result
1432 @@ -0,0 +1,15 @@
1433 +CREATE TABLE t(id INT PRIMARY KEY);
1434 +INSERT INTO t VALUES(1);
1435 +INSERT INTO t VALUES(2);
1436 +INSERT INTO t VALUES(3);
1437 +SET long_query_time=1;
1438 +SET log_slow_filter=full_join;
1439 +[log_start.inc] percona.slow_extended.log_slow_filter
1440 +SET query_exec_time = 1.1;
1441 +SELECT * FROM t AS t1, t AS t2;
1442 +SET query_exec_time = default;
1443 +[log_stop.inc] percona.slow_extended.log_slow_filter
1444 +SET log_slow_filter=default;
1445 +SET long_query_time=default;
1446 +[log_grep.inc] file: percona.slow_extended.log_slow_filter pattern: Query_time
1447 +[log_grep.inc] lines:   1
1448 --- /dev/null
1449 +++ b/mysql-test/r/percona_log_slow_slave_statements-cl.result
1450 @@ -0,0 +1,6 @@
1451 +SHOW VARIABLES LIKE 'log_slow_slave_statements';
1452 +Variable_name  Value
1453 +log_slow_slave_statements      ON
1454 +SHOW GLOBAL VARIABLES LIKE 'log_slow_slave_statements';
1455 +Variable_name  Value
1456 +log_slow_slave_statements      ON
1457 --- /dev/null
1458 +++ b/mysql-test/r/percona_log_slow_slave_statements-innodb.result
1459 @@ -0,0 +1,18 @@
1460 +include/master-slave.inc
1461 +[connection master]
1462 +DROP TABLE IF EXISTS t;
1463 +CREATE TABLE t(id INT,data CHAR(30)) ENGINE=InnoDB;
1464 +INSERT INTO t VALUES
1465 +(1,"aaaaabbbbbcccccdddddeeeeefffff"),
1466 +(2,"aaaaabbbbbcccccdddddeeeeefffff"),
1467 +(3,"aaaaabbbbbcccccdddddeeeeefffff"),
1468 +(4,"aaaaabbbbbcccccdddddeeeeefffff"),
1469 +(5,"aaaaabbbbbcccccdddddeeeeefffff");
1470 +INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
1471 +INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
1472 +[log_start.inc] percona.slow_extended.log_slow_slave_statements-innodb
1473 +INSERT INTO t SELECT t.id,t.data from t;
1474 +[log_stop.inc] percona.slow_extended.log_slow_slave_statements-innodb
1475 +[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements-innodb pattern: InnoDB_IO_r_ops
1476 +[log_grep.inc] lines:   1
1477 +include/rpl_end.inc
1478 --- /dev/null
1479 +++ b/mysql-test/r/percona_log_slow_slave_statements.result
1480 @@ -0,0 +1,44 @@
1481 +include/master-slave.inc
1482 +[connection master]
1483 +DROP TABLE IF EXISTS t;
1484 +CREATE TABLE t(id INT);
1485 +[log_start.inc] percona.slow_extended.log_slow_slave_statements
1486 +LINE 1
1487 +LOG_SLOW_SLAVE_STATAMENTS is OFF
1488 +LOG_SLOW_SLAVE_STATEMENTS=ON
1489 +LOG_SLOW_SLAVE_STATAMENTS is ON
1490 +LINE 2
1491 +include/restart_slave.inc
1492 +LOG_SLOW_SLAVE_STATAMENTS is ON
1493 +LINE 3
1494 +LOG_SLOW_SLAVE_STATAMENTS is ON
1495 +LOG_SLOW_SLAVE_STATEMENTS=OFF
1496 +LOG_SLOW_SLAVE_STATAMENTS is OFF
1497 +LINE 4
1498 +include/restart_slave.inc
1499 +LOG_SLOW_SLAVE_STATAMENTS is OFF
1500 +LINE 5
1501 +LOG_SLOW_SLAVE_STATAMENTS is OFF
1502 +LOG_SLOW_SLAVE_STATEMENTS=ON
1503 +LOG_SLOW_SLAVE_STATAMENTS is ON
1504 +LINE 6
1505 +include/restart_slave.inc
1506 +LOG_SLOW_SLAVE_STATAMENTS is ON
1507 +LINE 7
1508 +[log_stop.inc] percona.slow_extended.log_slow_slave_statements
1509 +SET GLOBAL log_slow_slave_statements=default;
1510 +[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(1\)
1511 +[log_grep.inc] lines:   0
1512 +[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(2\)
1513 +[log_grep.inc] lines:   0
1514 +[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(3\)
1515 +[log_grep.inc] lines:   1
1516 +[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(4\)
1517 +[log_grep.inc] lines:   0
1518 +[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(5\)
1519 +[log_grep.inc] lines:   0
1520 +[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(6\)
1521 +[log_grep.inc] lines:   0
1522 +[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(7\)
1523 +[log_grep.inc] lines:   1
1524 +include/rpl_end.inc
1525 --- /dev/null
1526 +++ b/mysql-test/r/percona_log_slow_sp_statements-cl.result
1527 @@ -0,0 +1,6 @@
1528 +SHOW VARIABLES LIKE 'log_slow_sp_statements';
1529 +Variable_name  Value
1530 +log_slow_sp_statements ON
1531 +SHOW GLOBAL VARIABLES LIKE 'log_slow_sp_statements';
1532 +Variable_name  Value
1533 +log_slow_sp_statements ON
1534 --- /dev/null
1535 +++ b/mysql-test/r/percona_log_slow_sp_statements.result
1536 @@ -0,0 +1,24 @@
1537 +SET long_query_time=1;
1538 +SET GLOBAL log_slow_sp_statements=ON;
1539 +SET SESSION query_exec_time=0.1;
1540 +[log_start.inc] percona.slow_extended.log_slow_sp_statements
1541 +CREATE PROCEDURE test_f()
1542 +BEGIN
1543 +SET SESSION query_exec_time=1.1; SELECT 1;
1544 +SET SESSION query_exec_time=2.1; SELECT 1;
1545 +SET SESSION query_exec_time=3.1; SELECT 1;
1546 +SET SESSION query_exec_time=0.1;
1547 +END^
1548 +CALL test_f();
1549 +1
1550 +1
1551 +1
1552 +1
1553 +1
1554 +1
1555 +[log_stop.inc] percona.slow_extended.log_slow_sp_statements
1556 +SET SESSION query_exec_time=default;
1557 +SET GLOBAL log_slow_sp_statements=default;
1558 +SET long_query_time=default;
1559 +[log_grep.inc] file: percona.slow_extended.log_slow_sp_statements pattern: Query_time
1560 +[log_grep.inc] lines:   3
1561 --- /dev/null
1562 +++ b/mysql-test/r/percona_log_slow_verbosity-cl.result
1563 @@ -0,0 +1,6 @@
1564 +SHOW VARIABLES LIKE 'log_slow_verbosity';
1565 +Variable_name  Value
1566 +log_slow_verbosity     microtime,query_plan,innodb
1567 +SHOW GLOBAL VARIABLES LIKE 'log_slow_verbosity';
1568 +Variable_name  Value
1569 +log_slow_verbosity     microtime,query_plan,innodb
1570 --- /dev/null
1571 +++ b/mysql-test/r/percona_log_slow_verbosity.result
1572 @@ -0,0 +1,16 @@
1573 +SET SESSION long_query_time=1;
1574 +[log_start.inc] percona.slow_extended.log_slow_verbosity
1575 +SET SESSION query_exec_time=2.1;
1576 +SELECT 1;
1577 +1
1578 +1
1579 +SET SESSION log_slow_verbosity=innodb;
1580 +SELECT 1;
1581 +1
1582 +1
1583 +SET SESSION query_exec_time=default;
1584 +[log_stop.inc] percona.slow_extended.log_slow_verbosity
1585 +SET log_slow_verbosity=default;
1586 +SET long_query_time=default;
1587 +[log_grep.inc] file: percona.slow_extended.log_slow_verbosity pattern: No InnoDB statistics available for this query
1588 +[log_grep.inc] lines:   1
1589 --- /dev/null
1590 +++ b/mysql-test/r/percona_long_query_time.result
1591 @@ -0,0 +1,33 @@
1592 +SET long_query_time=2;
1593 +[log_start.inc] percona.slow_extended.long_query_time
1594 +SET SESSION query_exec_time=1.1;
1595 +SELECT 1;
1596 +1
1597 +1
1598 +SET SESSION query_exec_time=3.1;
1599 +SELECT 1;
1600 +1
1601 +1
1602 +SET SESSION query_exec_time=5.1;
1603 +SELECT 1;
1604 +1
1605 +1
1606 +SET long_query_time=4;
1607 +SET SESSION query_exec_time=1.1;
1608 +SELECT 1;
1609 +1
1610 +1
1611 +SET SESSION query_exec_time=3.1;
1612 +SELECT 1;
1613 +1
1614 +1
1615 +SET SESSION query_exec_time=5.1;
1616 +SELECT 1;
1617 +1
1618 +1
1619 +SET SESSION query_exec_time=default;
1620 +SET long_query_time=2;
1621 +[log_stop.inc] percona.slow_extended.long_query_time
1622 +SET long_query_time=default;
1623 +[log_grep.inc] file: percona.slow_extended.long_query_time pattern: Query_time
1624 +[log_grep.inc] lines:   3
1625 --- /dev/null
1626 +++ b/mysql-test/r/percona_slow_query_log_timestamp_always-cl.result
1627 @@ -0,0 +1,6 @@
1628 +SHOW VARIABLES LIKE 'slow_query_log_timestamp_always';
1629 +Variable_name  Value
1630 +slow_query_log_timestamp_always        ON
1631 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_always';
1632 +Variable_name  Value
1633 +slow_query_log_timestamp_always        ON
1634 --- /dev/null
1635 +++ b/mysql-test/r/percona_slow_query_log_timestamp_always.result
1636 @@ -0,0 +1,41 @@
1637 +SET long_query_time=2;
1638 +SET GLOBAL slow_query_log_timestamp_always=ON;
1639 +[log_start.inc] percona.slow_extended.slow_query_log_timestamp_always
1640 +SET SESSION query_exec_time=2.1;
1641 +SELECT 1;
1642 +1
1643 +1
1644 +SELECT 1;
1645 +1
1646 +1
1647 +SELECT 1;
1648 +1
1649 +1
1650 +SET GLOBAL slow_query_log_timestamp_always=OFF;
1651 +SET SESSION query_exec_time=2.1;
1652 +SELECT 1;
1653 +1
1654 +1
1655 +SELECT 1;
1656 +1
1657 +1
1658 +SELECT 1;
1659 +1
1660 +1
1661 +SET GLOBAL slow_query_log_timestamp_always=ON;
1662 +SET SESSION query_exec_time=2.1;
1663 +SELECT 1;
1664 +1
1665 +1
1666 +SELECT 1;
1667 +1
1668 +1
1669 +SELECT 1;
1670 +1
1671 +1
1672 +SET SESSION query_exec_time=default;
1673 +[log_stop.inc] percona.slow_extended.slow_query_log_timestamp_always
1674 +SET GLOBAL slow_query_log_timestamp_always=default;
1675 +SET long_query_time=default;
1676 +[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_always pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
1677 +[log_grep.inc] lines:   6
1678 --- /dev/null
1679 +++ b/mysql-test/r/percona_slow_query_log_timestamp_precision-cl.result
1680 @@ -0,0 +1,6 @@
1681 +SHOW VARIABLES LIKE 'slow_query_log_timestamp_precision';
1682 +Variable_name  Value
1683 +slow_query_log_timestamp_precision     microsecond
1684 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_precision';
1685 +Variable_name  Value
1686 +slow_query_log_timestamp_precision     microsecond
1687 --- /dev/null
1688 +++ b/mysql-test/r/percona_slow_query_log_timestamp_precision.result
1689 @@ -0,0 +1,18 @@
1690 +SET long_query_time=2;
1691 +[log_start.inc] percona.slow_extended.slow_query_log_timestamp_precision
1692 +SET SESSION query_exec_time=2.1;
1693 +SELECT 1;
1694 +1
1695 +1
1696 +SET GLOBAL slow_query_log_timestamp_precision='microsecond';
1697 +SELECT 1;
1698 +1
1699 +1
1700 +SET SESSION query_exec_time=default;
1701 +[log_stop.inc] percona.slow_extended.slow_query_log_timestamp_precision
1702 +SET GLOBAL slow_query_log_timestamp_precision=default;
1703 +SET long_query_time=default;
1704 +[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_precision pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+.[0-9]+
1705 +[log_grep.inc] lines:   1
1706 +[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_precision pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
1707 +[log_grep.inc] lines:   2
1708 --- /dev/null
1709 +++ b/mysql-test/r/percona_slow_query_log_use_global_control.result
1710 @@ -0,0 +1,18 @@
1711 +SET GLOBAL long_query_time=1;
1712 +[log_start.inc] percona.slow_extended.slow_query_log_use_global_control
1713 +SET SESSION query_exec_time=1.1;
1714 +SELECT 1;
1715 +1
1716 +1
1717 +SET GLOBAL log_slow_verbosity=innodb;
1718 +SET GLOBAL slow_query_log_use_global_control="log_slow_verbosity,long_query_time";
1719 +SELECT 1;
1720 +1
1721 +1
1722 +SET SESSION query_exec_time=default;
1723 +[log_stop.inc] percona.slow_extended.slow_query_log_use_global_control
1724 +SET GLOBAL slow_query_log_use_global_control=default;
1725 +SET GLOBAL log_slow_verbosity=default;
1726 +SET GLOBAL long_query_time=default;
1727 +[log_grep.inc] file: percona.slow_extended.slow_query_log_use_global_control pattern: No InnoDB statistics available for this query
1728 +[log_grep.inc] lines:   1
1729 --- /dev/null
1730 +++ b/mysql-test/t/percona_bug643149.test
1731 @@ -0,0 +1,49 @@
1732 +#
1733 +# This test suffers from server
1734 +# Bug#38124 "general_log_file" variable silently unset when using expression
1735 +# In short:
1736 +#    SET GLOBAL general_log_file = @<whatever>
1737 +#    SET GLOBAL slow_query_log = @<whatever>
1738 +# cause that the value of these server system variables is set to default
1739 +# instead of the assigned values. There comes no error message or warning.
1740 +# If this bug is fixed please
1741 +# 1. try this test with "let $fixed_bug38124 = 0;"
1742 +# 2. remove all workarounds if 1. was successful.
1743 +--source include/have_profiling.inc
1744 +let $fixed_bug38124 = 0;
1745 +
1746 +SET @old_slow_query_log_file=@@global.slow_query_log_file;
1747 +SET GLOBAL slow_query_log=on;
1748 +SET LOCAL log_slow_verbosity='profiling';
1749 +SET LOCAL long_query_time=0;
1750 +
1751 +let slogfile=$MYSQLTEST_VARDIR/percona_bug643149_slow.log;
1752 +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1753 +--eval SET GLOBAL slow_query_log_file='$slogfile';
1754 +
1755 +SELECT 1;
1756 +
1757 +perl;
1758 +  $slogfile= $ENV{'slogfile'};
1759 +
1760 +  open(FILE, "$slogfile") or
1761 +    die("Unable to read slow query log file $slogfile: $!\n");
1762 +  while(<FILE>) {
1763 +    next if (!/^#/);
1764 +    next if (/^# Time:/);
1765 +    s/[0-9]+/X/g;
1766 +    print;
1767 +  }
1768 +
1769 +  close(FILE);
1770 +EOF
1771 +
1772 +SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
1773 +
1774 +if(!$fixed_bug38124)
1775 +{
1776 +  --disable_query_log
1777 +  let $my_var = `SELECT @old_slow_query_log_file`;
1778 +  eval SET @@global.slow_query_log_file = '$my_var';
1779 +  --enable_query_log
1780 +}
1781 --- /dev/null
1782 +++ b/mysql-test/t/percona_log_slow_filter-cl-master.opt
1783 @@ -0,0 +1 @@
1784 +--log_slow_filter=full_join
1785 --- /dev/null
1786 +++ b/mysql-test/t/percona_log_slow_filter-cl.test
1787 @@ -0,0 +1,2 @@
1788 +SHOW VARIABLES LIKE 'log_slow_filter';
1789 +SHOW GLOBAL VARIABLES LIKE 'log_slow_filter';
1790 --- /dev/null
1791 +++ b/mysql-test/t/percona_log_slow_filter.test
1792 @@ -0,0 +1,26 @@
1793 +--source include/have_debug.inc
1794 +
1795 +CREATE TABLE t(id INT PRIMARY KEY);
1796 +INSERT INTO t VALUES(1);
1797 +INSERT INTO t VALUES(2);
1798 +INSERT INTO t VALUES(3);
1799 +
1800 +SET long_query_time=1;
1801 +SET log_slow_filter=full_join;
1802 +--let log_file=percona.slow_extended.log_slow_filter
1803 +--source include/log_start.inc
1804 +
1805 +SET query_exec_time = 1.1;
1806 +--disable_result_log
1807 +SELECT * FROM t AS t1, t AS t2;
1808 +--enable_result_log
1809 +SET query_exec_time = default;
1810 +
1811 +--source include/log_stop.inc
1812 +SET log_slow_filter=default;
1813 +SET long_query_time=default;
1814 +
1815 +--let grep_pattern = Query_time
1816 +--source include/log_grep.inc
1817 +
1818 +DROP TABLE t;
1819 --- /dev/null
1820 +++ b/mysql-test/t/percona_log_slow_slave_statements-cl-master.opt
1821 @@ -0,0 +1 @@
1822 +--log_slow_slave_statements
1823 \ No newline at end of file
1824 --- /dev/null
1825 +++ b/mysql-test/t/percona_log_slow_slave_statements-cl.test
1826 @@ -0,0 +1,3 @@
1827 +SHOW VARIABLES LIKE 'log_slow_slave_statements';
1828 +SHOW GLOBAL VARIABLES LIKE 'log_slow_slave_statements';
1829 +
1830 --- /dev/null
1831 +++ b/mysql-test/t/percona_log_slow_slave_statements-innodb-slave.opt
1832 @@ -0,0 +1 @@
1833 +--long_query_time=0 --log_slow_slave_statements --log_slow_verbosity=innodb
1834 \ No newline at end of file
1835 --- /dev/null
1836 +++ b/mysql-test/t/percona_log_slow_slave_statements-innodb.test
1837 @@ -0,0 +1,42 @@
1838 +--source include/have_binlog_format_statement.inc
1839 +--source include/master-slave.inc
1840 +--source include/have_innodb.inc
1841 +--let log_file=percona.slow_extended.log_slow_slave_statements-innodb
1842 +
1843 +connection master;
1844 +-- disable_warnings
1845 +DROP TABLE IF EXISTS t;
1846 +-- enable_warnings
1847 +
1848 +CREATE TABLE t(id INT,data CHAR(30)) ENGINE=InnoDB;
1849 +INSERT INTO t VALUES
1850 +(1,"aaaaabbbbbcccccdddddeeeeefffff"),
1851 +(2,"aaaaabbbbbcccccdddddeeeeefffff"),
1852 +(3,"aaaaabbbbbcccccdddddeeeeefffff"),
1853 +(4,"aaaaabbbbbcccccdddddeeeeefffff"),
1854 +(5,"aaaaabbbbbcccccdddddeeeeefffff");
1855 +INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
1856 +INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
1857 +sync_slave_with_master;
1858 +
1859 +connection slave;
1860 +--source include/log_start.inc
1861 +
1862 +connection master;
1863 +INSERT INTO t SELECT t.id,t.data from t;
1864 +sync_slave_with_master;
1865 +
1866 +connection slave;
1867 +--source include/log_stop.inc
1868 +
1869 +--enable_query_log
1870 +--enable_result_log
1871 +
1872 +--let grep_pattern =  InnoDB_IO_r_ops
1873 +--source include/log_grep.inc
1874 +
1875 +connection master;
1876 +DROP TABLE t;
1877 +sync_slave_with_master;
1878 +
1879 +--source include/rpl_end.inc
1880 --- /dev/null
1881 +++ b/mysql-test/t/percona_log_slow_slave_statements-slave.opt
1882 @@ -0,0 +1 @@
1883 +--long_query_time=0
1884 \ No newline at end of file
1885 --- /dev/null
1886 +++ b/mysql-test/t/percona_log_slow_slave_statements.test
1887 @@ -0,0 +1,117 @@
1888 +-- source include/have_binlog_format_statement.inc
1889 +-- source include/master-slave.inc
1890 +--let log_file=percona.slow_extended.log_slow_slave_statements
1891 +--let show=SELECT Variable_value FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE Variable_name LIKE 'log_slow_slave_statements';
1892 +
1893 +connection master;
1894 +-- disable_warnings
1895 +DROP TABLE IF EXISTS t;
1896 +-- enable_warnings
1897 +
1898 +CREATE TABLE t(id INT);
1899 +sync_slave_with_master;
1900 +
1901 +connection slave;
1902 +--source include/log_start.inc
1903 +
1904 +--disable_query_log
1905 +--disable_result_log
1906 +
1907 +--echo LINE 1
1908 +connection master;
1909 +INSERT INTO t VALUES (1);
1910 +sync_slave_with_master;
1911 +
1912 +connection slave;
1913 +--let value=`$show`
1914 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1915 +--echo LOG_SLOW_SLAVE_STATEMENTS=ON
1916 +SET GLOBAL log_slow_slave_statements=ON;
1917 +--let value=`$show`
1918 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1919 +
1920 +--echo LINE 2
1921 +connection master;
1922 +INSERT INTO t VALUES (2);
1923 +sync_slave_with_master;
1924 +
1925 +--source include/restart_slave_sql.inc
1926 +
1927 +connection slave;
1928 +--let value=`$show`
1929 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1930 +
1931 +--echo LINE 3
1932 +connection master;
1933 +INSERT INTO t VALUES (3);
1934 +sync_slave_with_master;
1935 +
1936 +connection slave;
1937 +--let value=`$show`
1938 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1939 +--echo LOG_SLOW_SLAVE_STATEMENTS=OFF
1940 +SET GLOBAL log_slow_slave_statements=OFF;
1941 +--let value=`$show`
1942 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1943 +
1944 +--echo LINE 4
1945 +connection master;
1946 +INSERT INTO t VALUES (4);
1947 +sync_slave_with_master;
1948 +
1949 +--source include/restart_slave_sql.inc
1950 +
1951 +connection slave;
1952 +--let value=`$show`
1953 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1954 +
1955 +--echo LINE 5
1956 +connection master;
1957 +INSERT INTO t VALUES (5);
1958 +sync_slave_with_master;
1959 +
1960 +connection slave;
1961 +--let value=`$show`
1962 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1963 +--echo LOG_SLOW_SLAVE_STATEMENTS=ON
1964 +SET GLOBAL log_slow_slave_statements=ON;
1965 +--let value=`$show`
1966 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1967 +
1968 +--echo LINE 6
1969 +connection master;
1970 +INSERT INTO t VALUES (6);
1971 +sync_slave_with_master;
1972 +
1973 +--source include/restart_slave_sql.inc
1974 +
1975 +connection slave;
1976 +--let value=`$show`
1977 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1978 +
1979 +--echo LINE 7
1980 +connection master;
1981 +INSERT INTO t VALUES (7);
1982 +sync_slave_with_master;
1983 +
1984 +--enable_query_log
1985 +--enable_result_log
1986 +
1987 +connection slave;
1988 +--source include/log_stop.inc
1989 +SET GLOBAL log_slow_slave_statements=default;
1990 +
1991 +connection slave;
1992 +--let i=1
1993 +while($i < 8)
1994 +{
1995 +--let grep_pattern= INSERT INTO t VALUES \($i\)
1996 +--source include/log_grep.inc
1997 +  inc $i;
1998 +}
1999 +
2000 +connection master;
2001 +DROP TABLE t;
2002 +sync_slave_with_master;
2003 +
2004 +--source include/rpl_end.inc
2005 --- /dev/null
2006 +++ b/mysql-test/t/percona_log_slow_sp_statements-cl-master.opt
2007 @@ -0,0 +1 @@
2008 +--log_slow_sp_statements
2009 --- /dev/null
2010 +++ b/mysql-test/t/percona_log_slow_sp_statements-cl.test
2011 @@ -0,0 +1,2 @@
2012 +SHOW VARIABLES LIKE 'log_slow_sp_statements';
2013 +SHOW GLOBAL VARIABLES LIKE 'log_slow_sp_statements';
2014 --- /dev/null
2015 +++ b/mysql-test/t/percona_log_slow_sp_statements.test
2016 @@ -0,0 +1,29 @@
2017 +--source include/have_debug.inc
2018 +
2019 +SET long_query_time=1;
2020 +SET GLOBAL log_slow_sp_statements=ON;
2021 +SET SESSION query_exec_time=0.1;
2022 +--let log_file=percona.slow_extended.log_slow_sp_statements
2023 +--source include/log_start.inc
2024 +
2025 +delimiter ^;
2026 +CREATE PROCEDURE test_f()
2027 +BEGIN
2028 +  SET SESSION query_exec_time=1.1; SELECT 1;
2029 +  SET SESSION query_exec_time=2.1; SELECT 1;
2030 +  SET SESSION query_exec_time=3.1; SELECT 1;
2031 +  SET SESSION query_exec_time=0.1;
2032 +END^
2033 +delimiter ;^   
2034 +
2035 +CALL test_f();
2036 +
2037 +--source include/log_stop.inc
2038 +SET SESSION query_exec_time=default;
2039 +SET GLOBAL log_slow_sp_statements=default;
2040 +SET long_query_time=default;
2041 +
2042 +--let grep_pattern = Query_time
2043 +--source include/log_grep.inc
2044 +
2045 +DROP PROCEDURE test_f;
2046 --- /dev/null
2047 +++ b/mysql-test/t/percona_log_slow_verbosity-cl-master.opt
2048 @@ -0,0 +1 @@
2049 +--log_slow_verbosity="full"
2050 --- /dev/null
2051 +++ b/mysql-test/t/percona_log_slow_verbosity-cl.test
2052 @@ -0,0 +1,2 @@
2053 +SHOW VARIABLES LIKE 'log_slow_verbosity';
2054 +SHOW GLOBAL VARIABLES LIKE 'log_slow_verbosity';
2055 --- /dev/null
2056 +++ b/mysql-test/t/percona_log_slow_verbosity.test
2057 @@ -0,0 +1,19 @@
2058 +--source include/have_innodb.inc
2059 +--source include/have_debug.inc
2060 +
2061 +SET SESSION long_query_time=1;
2062 +--let log_file=percona.slow_extended.log_slow_verbosity
2063 +--source include/log_start.inc
2064 +
2065 +SET SESSION query_exec_time=2.1;
2066 +SELECT 1;
2067 +SET SESSION log_slow_verbosity=innodb;
2068 +SELECT 1;
2069 +SET SESSION query_exec_time=default;
2070 +
2071 +--source include/log_stop.inc
2072 +SET log_slow_verbosity=default;
2073 +SET long_query_time=default;
2074 +
2075 +--let grep_pattern = No InnoDB statistics available for this query
2076 +--source include/log_grep.inc
2077 --- /dev/null
2078 +++ b/mysql-test/t/percona_long_query_time.test
2079 @@ -0,0 +1,25 @@
2080 +--source include/have_debug.inc
2081 +
2082 +SET long_query_time=2;
2083 +--let log_file=percona.slow_extended.long_query_time
2084 +--source include/log_start.inc
2085 +
2086 +SET SESSION query_exec_time=1.1; SELECT 1;
2087 +SET SESSION query_exec_time=3.1; SELECT 1;
2088 +SET SESSION query_exec_time=5.1; SELECT 1;
2089 +
2090 +SET long_query_time=4;
2091 +
2092 +SET SESSION query_exec_time=1.1; SELECT 1;
2093 +SET SESSION query_exec_time=3.1; SELECT 1;
2094 +SET SESSION query_exec_time=5.1; SELECT 1;
2095 +
2096 +SET SESSION query_exec_time=default;
2097 +
2098 +SET long_query_time=2;
2099 +
2100 +--source include/log_stop.inc
2101 +SET long_query_time=default;
2102 +
2103 +--let grep_pattern = Query_time
2104 +--source include/log_grep.inc
2105 --- /dev/null
2106 +++ b/mysql-test/t/percona_slow_query_log_timestamp_always-cl-master.opt
2107 @@ -0,0 +1 @@
2108 +--slow_query_log_timestamp_always
2109 \ No newline at end of file
2110 --- /dev/null
2111 +++ b/mysql-test/t/percona_slow_query_log_timestamp_always-cl.test
2112 @@ -0,0 +1,2 @@
2113 +SHOW VARIABLES LIKE 'slow_query_log_timestamp_always';
2114 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_always';
2115 --- /dev/null
2116 +++ b/mysql-test/t/percona_slow_query_log_timestamp_always.test
2117 @@ -0,0 +1,34 @@
2118 +--source include/have_debug.inc
2119 +
2120 +SET long_query_time=2;
2121 +SET GLOBAL slow_query_log_timestamp_always=ON;
2122 +--let log_file=percona.slow_extended.slow_query_log_timestamp_always
2123 +--source include/log_start.inc
2124 +
2125 +SET SESSION query_exec_time=2.1;
2126 +SELECT 1;
2127 +SELECT 1;
2128 +SELECT 1;
2129 +
2130 +SET GLOBAL slow_query_log_timestamp_always=OFF;
2131 +
2132 +SET SESSION query_exec_time=2.1;
2133 +SELECT 1;
2134 +SELECT 1;
2135 +SELECT 1;
2136 +
2137 +SET GLOBAL slow_query_log_timestamp_always=ON;
2138 +
2139 +SET SESSION query_exec_time=2.1;
2140 +SELECT 1;
2141 +SELECT 1;
2142 +SELECT 1;
2143 +
2144 +SET SESSION query_exec_time=default;
2145 +
2146 +--source include/log_stop.inc
2147 +SET GLOBAL slow_query_log_timestamp_always=default;
2148 +SET long_query_time=default;
2149 +
2150 +--let grep_pattern =  # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
2151 +--source include/log_grep.inc
2152 --- /dev/null
2153 +++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-cl-master.opt
2154 @@ -0,0 +1 @@
2155 +--slow_query_log_timestamp_precision='microsecond'
2156 \ No newline at end of file
2157 --- /dev/null
2158 +++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-cl.test
2159 @@ -0,0 +1,2 @@
2160 +SHOW VARIABLES LIKE 'slow_query_log_timestamp_precision';
2161 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_precision';
2162 --- /dev/null
2163 +++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-master.opt
2164 @@ -0,0 +1 @@
2165 +--slow_query_log_timestamp_always
2166 \ No newline at end of file
2167 --- /dev/null
2168 +++ b/mysql-test/t/percona_slow_query_log_timestamp_precision.test
2169 @@ -0,0 +1,25 @@
2170 +--source include/have_debug.inc
2171 +
2172 +SET long_query_time=2;
2173 +--let log_file=percona.slow_extended.slow_query_log_timestamp_precision
2174 +--source include/log_start.inc
2175 +
2176 +SET SESSION query_exec_time=2.1;
2177 +
2178 +SELECT 1;
2179 +
2180 +SET GLOBAL slow_query_log_timestamp_precision='microsecond';
2181 +
2182 +SELECT 1;
2183 +
2184 +SET SESSION query_exec_time=default;
2185 +
2186 +--source include/log_stop.inc
2187 +SET GLOBAL slow_query_log_timestamp_precision=default;
2188 +SET long_query_time=default;
2189 +
2190 +--let grep_pattern = # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+.[0-9]+
2191 +--source include/log_grep.inc
2192 +
2193 +--let grep_pattern =  # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
2194 +--source include/log_grep.inc
2195 --- /dev/null
2196 +++ b/mysql-test/t/percona_slow_query_log_use_global_control.test
2197 @@ -0,0 +1,28 @@
2198 +--source include/have_debug.inc
2199 +--source include/have_innodb.inc
2200 +
2201 +SET GLOBAL long_query_time=1;
2202 +
2203 +--let log_file=percona.slow_extended.slow_query_log_use_global_control
2204 +--source include/log_start.inc
2205 +
2206 +SET SESSION query_exec_time=1.1;
2207 +SELECT 1;
2208 +
2209 +SET GLOBAL log_slow_verbosity=innodb;
2210 +SET GLOBAL slow_query_log_use_global_control="log_slow_verbosity,long_query_time";
2211 +
2212 +SELECT 1;
2213 +
2214 +SET SESSION query_exec_time=default;
2215 +
2216 +--source include/log_stop.inc
2217 +
2218 +
2219 +SET GLOBAL slow_query_log_use_global_control=default;
2220 +SET GLOBAL log_slow_verbosity=default;
2221 +SET GLOBAL long_query_time=default;
2222 +
2223 +--let grep_pattern = No InnoDB statistics available for this query
2224 +--source include/log_grep.inc
2225 +
2226 --- /dev/null
2227 +++ b/mysql-test/r/percona_slow_query_log_use_global_control-cl.result
2228 @@ -0,0 +1,6 @@
2229 +SHOW VARIABLES LIKE 'slow_query_log_use_global_control';
2230 +Variable_name  Value
2231 +slow_query_log_use_global_control      log_slow_verbosity,long_query_time
2232 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_use_global_control';
2233 +Variable_name  Value
2234 +slow_query_log_use_global_control      log_slow_verbosity,long_query_time
2235 --- /dev/null
2236 +++ b/mysql-test/t/percona_slow_query_log_use_global_control-cl-master.opt
2237 @@ -0,0 +1 @@
2238 +--slow_query_log_use_global_control="log_slow_verbosity,long_query_time"
2239 --- /dev/null
2240 +++ b/mysql-test/t/percona_slow_query_log_use_global_control-cl.test
2241 @@ -0,0 +1,2 @@
2242 +SHOW VARIABLES LIKE 'slow_query_log_use_global_control';
2243 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_use_global_control';
2244 --- /dev/null
2245 +++ b/mysql-test/r/percona_min_examined_row_limit.result
2246 @@ -0,0 +1,34 @@
2247 +drop table if exists t;
2248 +create table t(id INT PRIMARY KEY);
2249 +insert into t values(1);
2250 +insert into t values(2);
2251 +insert into t values(3);
2252 +SET GLOBAL long_query_time=2;
2253 +SET GLOBAL slow_query_log_use_global_control='long_query_time,min_examined_row_limit';
2254 +[log_start.inc] percona.slow_extended.min_examined_row_limit
2255 +SET SESSION query_exec_time=2.1;
2256 +SELECT 1;
2257 +1
2258 +1
2259 +SET GLOBAL min_examined_row_limit=5;
2260 +select * from t as t1, t as t2;
2261 +id     id
2262 +1      1
2263 +2      1
2264 +3      1
2265 +1      2
2266 +2      2
2267 +3      2
2268 +1      3
2269 +2      3
2270 +3      3
2271 +SELECT 1;
2272 +1
2273 +1
2274 +SET SESSION query_exec_time=default;
2275 +[log_stop.inc] percona.slow_extended.min_examined_row_limit
2276 +SET GLOBAL min_examined_row_limit=default;
2277 +SET GLOBAL slow_query_log_use_global_control=default;
2278 +SET GLOBAL long_query_time=default;
2279 +[log_grep.inc] file: percona.slow_extended.min_examined_row_limit pattern: Query_time
2280 +[log_grep.inc] lines:   1
2281 --- /dev/null
2282 +++ b/mysql-test/t/percona_min_examined_row_limit.test
2283 @@ -0,0 +1,35 @@
2284 +--source include/have_debug.inc
2285 +
2286 +--disable_warnings
2287 +drop table if exists t;
2288 +--enable_warnings
2289 +
2290 +create table t(id INT PRIMARY KEY);
2291 +insert into t values(1);
2292 +insert into t values(2);
2293 +insert into t values(3);
2294 +
2295 +SET GLOBAL long_query_time=2;
2296 +SET GLOBAL slow_query_log_use_global_control='long_query_time,min_examined_row_limit';
2297 +--let log_file=percona.slow_extended.min_examined_row_limit
2298 +--source include/log_start.inc
2299 +
2300 +SET SESSION query_exec_time=2.1;
2301 +SELECT 1;
2302 +
2303 +SET GLOBAL min_examined_row_limit=5;
2304 +
2305 +select * from t as t1, t as t2;
2306 +SELECT 1;
2307 +
2308 +SET SESSION query_exec_time=default;
2309 +
2310 +--source include/log_stop.inc
2311 +SET GLOBAL min_examined_row_limit=default;
2312 +SET GLOBAL slow_query_log_use_global_control=default;
2313 +SET GLOBAL long_query_time=default;
2314 +
2315 +--let grep_pattern = Query_time
2316 +--source include/log_grep.inc
2317 +
2318 +DROP TABLE t;
2319 --- a/sql/log_event.cc
2320 +++ b/sql/log_event.cc
2321 @@ -2380,6 +2380,14 @@
2322        start+= host.length;
2323      }
2324    }
2325 +#ifndef DBUG_OFF
2326 +  if (thd && thd->variables.query_exec_time > 0)
2327 +  {
2328 +    *start++= Q_QUERY_EXEC_TIME;
2329 +    int8store(start, thd->variables.query_exec_time);
2330 +    start+= 8;
2331 +  }
2332 +#endif
2333    /*
2334      NOTE: When adding new status vars, please don't forget to update
2335      the MAX_SIZE_LOG_EVENT_STATUS in log_event.h and update the function
2336 @@ -2866,6 +2874,17 @@
2337        data_written= master_data_written= uint4korr(pos);
2338        pos+= 4;
2339        break;
2340 +#if !defined(DBUG_OFF) && !defined(MYSQL_CLIENT)
2341 +    case Q_QUERY_EXEC_TIME:
2342 +    {
2343 +      THD *thd= current_thd;
2344 +      CHECK_SPACE(pos, end, 8);
2345 +      if (thd)
2346 +        thd->variables.query_exec_time= uint8korr(pos);
2347 +      pos+= 8;
2348 +      break;
2349 +    }
2350 +#endif
2351      case Q_INVOKER:
2352      {
2353        CHECK_SPACE(pos, end, 1);
2354 --- a/sql/log_event.h
2355 +++ b/sql/log_event.h
2356 @@ -342,6 +342,10 @@
2357  
2358  #define Q_INVOKER 11
2359  
2360 +#ifndef DBUG_OFF
2361 +#define Q_QUERY_EXEC_TIME 250
2362 +#endif
2363 +
2364  /* Intvar event post-header */
2365  
2366  /* Intvar event data */
2367 --- /dev/null
2368 +++ b/mysql-test/suite/sys_vars/r/query_exec_time_basic.result
2369 @@ -0,0 +1,2 @@
2370 +SET GLOBAL query_exec_time=default;
2371 +SET SESSION query_exec_time=default;
2372 --- /dev/null
2373 +++ b/mysql-test/suite/sys_vars/t/query_exec_time_basic.test
2374 @@ -0,0 +1,4 @@
2375 +--source include/have_debug.inc
2376 +
2377 +SET GLOBAL query_exec_time=default;
2378 +SET SESSION query_exec_time=default;
This page took 0.26342 seconds and 3 git commands to generate.