1 # name : slow_extended.patch
2 # introduced : 11 or before
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
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,
18 + long io_reads_wait_timer,
19 + long lock_que_wait_timer,
20 + long que_wait_timer,
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
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,
37 + long io_reads_wait_timer,
38 + long lock_que_wait_timer,
39 + long que_wait_timer,
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
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,
56 + long io_reads_wait_timer,
57 + long lock_que_wait_timer,
58 + long que_wait_timer,
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
68 /* Increments the row counter, see THD::row_count */
69 void thd_inc_row_count(MYSQL_THD thd);
71 +void increment_thd_innodb_stats(MYSQL_THD thd,
72 + unsigned long long trx_id,
75 + long io_reads_wait_timer,
76 + long lock_que_wait_timer,
77 + long que_wait_timer,
79 +unsigned long thd_log_slow_verbosity(const MYSQL_THD thd);
80 +int thd_opt_slow_log();
81 +#define EXTENDED_SLOWLOG
83 Create a temporary file.
86 +++ b/patch_info/slow_extended.info
88 +File=slow_extended.patch
89 +Name=Extended statistics in slow.log (not InnoDB part)
91 +Author=Percona <info@percona.com>
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).
99 +VT: Moved log_slow_rate_limit in SHOW VARIABLE into right place
102 +Arjen Lentz: Fixups (backward compatibility) by Arjen Lentz <arjen@openquery.com.au>
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)
112 +Patch profiling_slow.patch was merged
113 --- a/scripts/mysqldumpslow.sh
114 +++ b/scripts/mysqldumpslow.sh
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) : ('','');
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};
125 # remove fluff that mysqld writes to log when it (re)starts:
126 --- a/sql/event_scheduler.cc
127 +++ b/sql/event_scheduler.cc
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);
136 --- a/sql/filesort.cc
137 +++ b/sql/filesort.cc
140 status_var_increment(thd->status_var.filesort_scan_count);
142 + thd->query_plan_flags|= QPLAN_FILESORT;
143 #ifdef CAN_TRUST_RANGE
144 if (select && select->quick && select->quick->records > 0L)
150 + thd->query_plan_flags|= QPLAN_FILESORT_DISK;
151 if (table_sort.buffpek && table_sort.buffpek_len < maxbuffer)
153 my_free(table_sort.buffpek);
154 @@ -1219,6 +1221,7 @@
155 DBUG_ENTER("merge_buffers");
157 status_var_increment(current_thd->status_var.filesort_merge_passes);
158 + current_thd->query_plan_fsort_passes++;
159 if (param->not_killable)
161 killed= ¬_killable;
164 @@ -715,11 +715,13 @@
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)
174 + time_t current_time= my_time_possible_from_micro(current_utime);
176 TABLE_LIST table_list;
179 @@ -935,14 +937,14 @@
180 /** Wrapper around MYSQL_LOG::write() for slow log. */
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)
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) -
205 @@ -1224,8 +1226,22 @@
206 current_time= my_time_possible_from_micro(current_utime);
207 if (thd->start_utime)
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)
217 + query_utime= (current_utime - thd->start_utime);
219 + if(thd->utime_after_lock < thd->start_utime)
225 + lock_utime= (thd->utime_after_lock - thd->start_utime);
230 @@ -1239,8 +1255,20 @@
231 query_length= command_name[thd->command].length;
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;
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 @@
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)
263 + time_t current_time= my_time_possible_from_micro(current_utime);
265 DBUG_ENTER("MYSQL_QUERY_LOG::write");
267 @@ -2683,17 +2712,28 @@
269 if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
271 - if (current_time != last_time)
272 + if (opt_slow_query_log_timestamp_always || current_time != last_time)
274 last_time= current_time;
276 localtime_r(¤t_time, &start);
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)
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);
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);
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)
326 +#if defined(ENABLED_PROFILING)
327 + thd->profiling.print_current(&log_file);
329 + if (thd->innodb_was_used)
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)
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)
350 + if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_INNODB)) && thd->innodb_was_used)
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)
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)
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)
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);
388 virtual bool init()= 0;
389 virtual void cleanup()= 0;
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,
398 virtual void cleanup();
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,
407 virtual void cleanup();
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,
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 @@
444 +/* defined in sys_vars.cc */
445 +extern void init_log_slow_verbosity();
446 +extern void init_slow_query_log_use_global_control();
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);
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;
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;
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);
485 @@ -2152,7 +2152,7 @@
486 DBUG_PRINT("info",(" %.*s: eval args done", (int) m_name.length,
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)
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.
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();
504 @@ -1766,6 +1767,7 @@
508 + thd->query_plan_flags|= QPLAN_QC_NO;
509 MYSQL_QUERY_CACHE_MISS(thd->query());
510 DBUG_RETURN(0); // Query was not cached
512 --- a/sql/sql_class.cc
513 +++ b/sql/sql_class.cc
515 thd->warning_info->inc_current_row_for_warning();
519 +void increment_thd_innodb_stats(THD* thd,
520 + unsigned long long trx_id,
523 + long io_reads_wait_timer,
524 + long lock_que_wait_timer,
525 + long que_wait_timer,
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;
539 +unsigned long thd_log_slow_verbosity(const THD *thd)
541 + return (unsigned long) thd->variables.log_slow_verbosity;
545 +int thd_opt_slow_log()
547 + return (int) opt_slow_log;
551 Dumps a text description of a thread, its security context
556 + last_errno= sql_errno;
558 for (Internal_error_handler *error_handler= m_internal_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;
571 if ((!lex->requires_prelocking() || is_update_query(lex->sql_command)) &&
572 !is_current_stmt_binlog_format_row())
573 @@ -3676,6 +3714,14 @@
575 transaction.savepoints= 0;
576 first_successful_insert_id_in_cur_stmt= 0;
579 + innodb_io_reads= 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;
588 @@ -3738,6 +3784,12 @@
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;
601 --- a/sql/sql_class.h
602 +++ b/sql/sql_class.h
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
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
617 +enum enum_slow_query_log_timestamp_precision {
618 + SLOG_SECOND, SLOG_MICROSECOND
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
634 enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT,
635 SLAVE_EXEC_MODE_IDEMPOTENT,
636 SLAVE_EXEC_MODE_LAST_BIT};
639 my_bool sysdate_is_now;
642 + ulonglong query_exec_time;
643 + double query_exec_time_double;
645 + ulong log_slow_rate_limit;
646 + ulonglong log_slow_filter;
647 + ulonglong log_slow_verbosity;
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;
656 double long_query_time_double;
659 @@ -1140,6 +1182,14 @@
661 bool enable_slow_log;
662 bool last_insert_id_used;
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;
671 SAVEPOINT *savepoints;
672 enum enum_check_fields count_cuted_fields;
674 @@ -1588,6 +1638,26 @@
675 thr_lock_type update_lock_default;
678 + bool write_to_slow_log;
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;
693 + ulong query_plan_flags;
694 + ulong query_plan_fsort_passes;
698 /* <> 0 if we are inside of trigger or stored function. */
701 --- a/sql/sql_connect.cc
702 +++ b/sql/sql_connect.cc
704 MYSQL_CONNECTION_START(thd->thread_id, &thd->security_ctx->priv_user[0],
705 (char *) thd->security_ctx->host_or_ip);
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. :)
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;
716 prepare_new_connection_state(thd);
719 --- a/sql/sql_parse.cc
720 +++ b/sql/sql_parse.cc
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);
727 const char *any_db="*any*"; // Special symbol for check_access
729 @@ -1430,6 +1431,60 @@
734 + Calculate execution time for the current query.
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.
739 + SET queries are ignored so that statements changing query_exec_time are not
740 + affected by themselves.
742 + @param thd thread handle
743 + @param lex current relative time in microseconds
745 + @return time in microseconds from utime_after_lock
748 +static inline ulonglong get_query_exec_time(THD *thd, ulonglong cur_utime)
752 + if (thd->variables.query_exec_time != 0)
753 + res= thd->lex->sql_command != SQLCOM_SET_OPTION ?
754 + thd->variables.query_exec_time : 0;
758 + res= cur_utime - thd->utime_after_lock;
760 + if (res > thd->variables.long_query_time)
761 + thd->server_status|= SERVER_QUERY_WAS_SLOW;
763 + thd->server_status&= ~SERVER_QUERY_WAS_SLOW;
769 +static inline void copy_global_to_session(THD *thd, ulong flag,
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;
778 +static inline void copy_global_to_session(THD *thd, ulong flag,
779 + const ulonglong *val)
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;
788 void log_slow_statement(THD *thd)
790 @@ -1443,13 +1498,48 @@
791 if (unlikely(thd->in_sub_stmt))
792 DBUG_VOID_RETURN; // Don't set time for sub stmt
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))))
801 + ulonglong end_utime_of_query= thd->current_utime();
802 + ulonglong query_exec_time= get_query_exec_time(thd, end_utime_of_query);
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.
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);
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))
831 Do not log administrative statements unless the appropriate option is
834 if (thd->enable_slow_log)
836 - ulonglong end_utime_of_query= thd->current_utime();
837 thd_proc_info(thd, "logging slow query");
839 if (((thd->server_status & SERVER_QUERY_WAS_SLOW) ||
840 @@ -1879,6 +1969,9 @@
841 context.resolve_in_table_list_only(select_lex->
844 + /* Reset the counter at all cases for the extended slow query log */
845 + thd->sent_row_count= 0;
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 @@
852 thd->sent_row_count= thd->examined_row_count= 0;
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;
869 thd->reset_current_stmt_binlog_format_row();
870 thd->binlog_unsafe_warning_flags= 0;
872 --- a/sql/sql_select.cc
873 +++ b/sql/sql_select.cc
874 @@ -6902,7 +6902,10 @@
876 join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
879 status_var_increment(join->thd->status_var.select_scan_count);
880 + join->thd->query_plan_flags|= QPLAN_FULL_SCAN;
885 @@ -6916,7 +6919,10 @@
887 join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
890 status_var_increment(join->thd->status_var.select_full_join_count);
891 + join->thd->query_plan_flags|= QPLAN_FULL_JOIN;
895 if (!table->no_keyread)
896 @@ -10264,6 +10270,7 @@
897 (ulong) rows_limit,test(group)));
899 status_var_increment(thd->status_var.created_tmp_tables);
900 + thd->query_plan_flags|= QPLAN_TMP_TABLE;
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 @@
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;
912 @@ -11180,6 +11188,14 @@
913 save_proc_info=thd->proc_info;
914 thd_proc_info(thd, "removing tmp table");
916 + thd->tmp_tables_used++;
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++;
924 // Release latches since this can take a long time
925 ha_release_temporary_latches(thd);
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);
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)
938 + value_in_time_column = (now - tmp->start_time);
939 + if(value_in_time_column > now)
941 + value_in_time_column= 0;
944 + table->field[5]->store(value_in_time_column, FALSE);
947 if ((val= thread_state_info(tmp)))
949 --- a/sql/sys_vars.cc
950 +++ b/sql/sys_vars.cc
952 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
953 ON_UPDATE(update_cached_long_query_time));
956 +static bool update_cached_query_exec_time(sys_var *self, THD *thd,
957 + enum_var_type type)
959 + if (type == OPT_SESSION)
960 + thd->variables.query_exec_time=
961 + double2ulonglong(thd->variables.query_exec_time_double * 1e6);
963 + global_system_variables.query_exec_time=
964 + double2ulonglong(global_system_variables.query_exec_time_double * 1e6);
968 +static Sys_var_double Sys_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));
978 static bool fix_low_prio_updates(sys_var *self, THD *thd, enum_var_type type)
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));
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(
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
1004 +static ulonglong update_log_slow_verbosity_replace(ulonglong value, ulonglong what, ulonglong by)
1006 + if((value & what) == what)
1008 + value = value & (~what);
1009 + value = value | by;
1013 +void update_log_slow_verbosity(ulonglong* value_ptr)
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);
1026 +static bool update_log_slow_verbosity_helper(sys_var */*self*/, THD *thd,
1027 + enum_var_type type)
1029 + if(type == OPT_SESSION)
1031 + update_log_slow_verbosity(&(thd->variables.log_slow_verbosity));
1035 + update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
1039 +void init_slow_query_log_use_global_control()
1041 + update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
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),
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),
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),
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*/)
1070 + if(opt_slow_query_log_use_global_control & (ULL(1) << SLOG_UG_ALL))
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;
1078 +void init_log_slow_verbosity()
1080 + update_slow_query_log_use_global_control(0,0,OPT_GLOBAL);
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));
1096 /* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
1097 static Sys_var_mybool Sys_log_slow(
1099 --- a/sql/sql_profile.cc
1100 +++ b/sql/sql_profile.cc
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)
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);
1116 +#ifdef HAVE_CLOCK_GETTIME
1117 + struct timespec tp;
1119 + if (!(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
1121 + cpu_time_usecs= tp.tv_sec*1000000000.0 + tp.tv_nsec;
1126 + cpu_time_usecs= 0;
1132 finish_current_query();
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);
1139 if (! enabled) DBUG_VOID_RETURN;
1142 status_change("ending", NULL, NULL, 0);
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()))
1151 @@ -505,6 +521,118 @@
1155 +bool PROFILING::enabled_getrusage()
1157 + return ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING_USE_GETRUSAGE)) != 0);
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.
1166 +static void my_b_print_status(IO_CACHE *log_file, const char *status,
1167 + PROF_MEASUREMENT *start, PROF_MEASUREMENT *stop)
1169 + DBUG_ENTER("my_b_print_status");
1170 + DBUG_ASSERT(log_file != NULL && status != NULL);
1171 + char query_time_buff[22+7];
1174 + my_b_printf(log_file, "Profile_");
1175 + for (tmp= status; *tmp; tmp++)
1176 + my_b_write_byte(log_file, *tmp == ' ' ? '_' : *tmp);
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);
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: ");
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);
1196 + Print output for current query to file
1199 +int PROFILING::print_current(IO_CACHE *log_file)
1201 + DBUG_ENTER("PROFILING::print_current");
1202 + ulonglong row_number= 0;
1204 + QUERY_PROFILE *query;
1205 + /* Get current query */
1206 + if (current == NULL)
1213 + my_b_printf(log_file, "# ");
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++)
1223 + entry= query->entries.iterator_value(entry_iterator);
1225 + /* Skip the first. We count spans of fence, not fence-posts. */
1226 + if (previous == NULL) {first= entry; continue;}
1228 + if (thd->lex->sql_command == SQLCOM_SHOW_PROFILE)
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
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.
1241 + if (thd->lex->profile_query_id == 0) /* 0 == show final query */
1243 + if (query != last)
1248 + if (thd->lex->profile_query_id != query->profiling_query_id)
1253 + my_b_print_status(log_file, previous->status, previous, entry);
1256 + my_b_write_byte(log_file, '\n');
1257 + if ((entry != NULL) && (first != NULL))
1259 + my_b_printf(log_file, "# ");
1260 + my_b_print_status(log_file, "total", first, entry);
1261 + my_b_write_byte(log_file, '\n');
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
1272 #ifdef HAVE_GETRUSAGE
1274 + if (enabled_getrusage())
1276 my_decimal cpu_utime_decimal, cpu_stime_decimal;
1278 double2my_decimal(E_DEC_FATAL_ERROR,
1280 table->field[14]->store((uint32)(entry->rusage.ru_nswap -
1281 previous->rusage.ru_nswap), true);
1282 table->field[14]->set_notnull();
1285 /* TODO: Add swap info for non-BSD systems */
1287 --- a/sql/sql_profile.h
1288 +++ b/sql/sql_profile.h
1289 @@ -164,11 +164,15 @@
1291 class PROF_MEASUREMENT
1294 - friend class QUERY_PROFILE;
1295 - friend class PROFILING;
1297 QUERY_PROFILE *profile;
1299 + char *allocated_status_memory;
1301 + void set_label(const char *status_arg, const char *function_arg,
1302 + const char *file_arg, unsigned int line_arg);
1307 #ifdef HAVE_GETRUSAGE
1308 struct rusage rusage;
1309 @@ -181,12 +185,7 @@
1313 - char *allocated_status_memory;
1315 - void set_label(const char *status_arg, const char *function_arg,
1316 - const char *file_arg, unsigned int line_arg);
1319 + double cpu_time_usecs;
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 @@
1325 /* Show this profile. This is called by PROFILING. */
1326 bool show(uint options);
1330 + inline PROFILING * get_profiling() { return profiling; };
1335 @@ -276,9 +280,11 @@
1338 bool show_profiles();
1339 + bool enabled_getrusage();
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);
1346 # endif /* HAVE_PROFILING */
1348 +++ b/mysql-test/include/log_grep.inc
1350 +--disable_query_log
1351 +--echo [log_grep.inc] file: $log_file pattern: $grep_pattern
1353 + $log_file= $ENV{'log_file'};
1354 + $log_file_full_path= $ENV{'log_file_full_path'};
1355 + $grep_pattern= $ENV{'grep_pattern'};
1357 + open(FILE, "$log_file_full_path")
1358 + or die("Cannot open file $log_file_full_path: $!\n");
1362 + $lines++ if (/$grep_pattern/);
1365 + print "[log_grep.inc] lines: $lines\n";
1368 +++ b/mysql-test/include/log_start.inc
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;
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: $!";
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;
1386 \ No newline at end of file
1388 +++ b/mysql-test/include/log_stop.inc
1390 +--disable_query_log
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;
1398 +++ b/mysql-test/r/percona_bug643149.result
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';;
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;
1422 +++ b/mysql-test/r/percona_log_slow_filter-cl.result
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
1431 +++ b/mysql-test/r/percona_log_slow_filter.result
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
1449 +++ b/mysql-test/r/percona_log_slow_slave_statements-cl.result
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
1458 +++ b/mysql-test/r/percona_log_slow_slave_statements-innodb.result
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
1479 +++ b/mysql-test/r/percona_log_slow_slave_statements.result
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
1487 +LOG_SLOW_SLAVE_STATAMENTS is OFF
1488 +LOG_SLOW_SLAVE_STATEMENTS=ON
1489 +LOG_SLOW_SLAVE_STATAMENTS is ON
1491 +include/restart_slave.inc
1492 +LOG_SLOW_SLAVE_STATAMENTS is ON
1494 +LOG_SLOW_SLAVE_STATAMENTS is ON
1495 +LOG_SLOW_SLAVE_STATEMENTS=OFF
1496 +LOG_SLOW_SLAVE_STATAMENTS is OFF
1498 +include/restart_slave.inc
1499 +LOG_SLOW_SLAVE_STATAMENTS is OFF
1501 +LOG_SLOW_SLAVE_STATAMENTS is OFF
1502 +LOG_SLOW_SLAVE_STATEMENTS=ON
1503 +LOG_SLOW_SLAVE_STATAMENTS is ON
1505 +include/restart_slave.inc
1506 +LOG_SLOW_SLAVE_STATAMENTS is ON
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
1526 +++ b/mysql-test/r/percona_log_slow_sp_statements-cl.result
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
1535 +++ b/mysql-test/r/percona_log_slow_sp_statements.result
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()
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;
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
1562 +++ b/mysql-test/r/percona_log_slow_verbosity-cl.result
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
1571 +++ b/mysql-test/r/percona_log_slow_verbosity.result
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;
1579 +SET SESSION log_slow_verbosity=innodb;
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
1590 +++ b/mysql-test/r/percona_long_query_time.result
1592 +SET long_query_time=2;
1593 +[log_start.inc] percona.slow_extended.long_query_time
1594 +SET SESSION query_exec_time=1.1;
1598 +SET SESSION query_exec_time=3.1;
1602 +SET SESSION query_exec_time=5.1;
1606 +SET long_query_time=4;
1607 +SET SESSION query_exec_time=1.1;
1611 +SET SESSION query_exec_time=3.1;
1615 +SET SESSION query_exec_time=5.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
1626 +++ b/mysql-test/r/percona_slow_query_log_timestamp_always-cl.result
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
1635 +++ b/mysql-test/r/percona_slow_query_log_timestamp_always.result
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;
1650 +SET GLOBAL slow_query_log_timestamp_always=OFF;
1651 +SET SESSION query_exec_time=2.1;
1661 +SET GLOBAL slow_query_log_timestamp_always=ON;
1662 +SET SESSION query_exec_time=2.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
1679 +++ b/mysql-test/r/percona_slow_query_log_timestamp_precision-cl.result
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
1688 +++ b/mysql-test/r/percona_slow_query_log_timestamp_precision.result
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;
1696 +SET GLOBAL slow_query_log_timestamp_precision='microsecond';
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
1709 +++ b/mysql-test/r/percona_slow_query_log_use_global_control.result
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;
1717 +SET GLOBAL log_slow_verbosity=innodb;
1718 +SET GLOBAL slow_query_log_use_global_control="log_slow_verbosity,long_query_time";
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
1730 +++ b/mysql-test/t/percona_bug643149.test
1733 +# This test suffers from server
1734 +# Bug#38124 "general_log_file" variable silently unset when using expression
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;
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;
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';
1758 + $slogfile= $ENV{'slogfile'};
1760 + open(FILE, "$slogfile") or
1761 + die("Unable to read slow query log file $slogfile: $!\n");
1764 + next if (/^# Time:/);
1772 +SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
1774 +if(!$fixed_bug38124)
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
1782 +++ b/mysql-test/t/percona_log_slow_filter-cl-master.opt
1784 +--log_slow_filter=full_join
1786 +++ b/mysql-test/t/percona_log_slow_filter-cl.test
1788 +SHOW VARIABLES LIKE 'log_slow_filter';
1789 +SHOW GLOBAL VARIABLES LIKE 'log_slow_filter';
1791 +++ b/mysql-test/t/percona_log_slow_filter.test
1793 +--source include/have_debug.inc
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);
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
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;
1811 +--source include/log_stop.inc
1812 +SET log_slow_filter=default;
1813 +SET long_query_time=default;
1815 +--let grep_pattern = Query_time
1816 +--source include/log_grep.inc
1820 +++ b/mysql-test/t/percona_log_slow_slave_statements-cl-master.opt
1822 +--log_slow_slave_statements
1823 \ No newline at end of file
1825 +++ b/mysql-test/t/percona_log_slow_slave_statements-cl.test
1827 +SHOW VARIABLES LIKE 'log_slow_slave_statements';
1828 +SHOW GLOBAL VARIABLES LIKE 'log_slow_slave_statements';
1831 +++ b/mysql-test/t/percona_log_slow_slave_statements-innodb-slave.opt
1833 +--long_query_time=0 --log_slow_slave_statements --log_slow_verbosity=innodb
1834 \ No newline at end of file
1836 +++ b/mysql-test/t/percona_log_slow_slave_statements-innodb.test
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
1844 +-- disable_warnings
1845 +DROP TABLE IF EXISTS t;
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;
1860 +--source include/log_start.inc
1863 +INSERT INTO t SELECT t.id,t.data from t;
1864 +sync_slave_with_master;
1867 +--source include/log_stop.inc
1870 +--enable_result_log
1872 +--let grep_pattern = InnoDB_IO_r_ops
1873 +--source include/log_grep.inc
1877 +sync_slave_with_master;
1879 +--source include/rpl_end.inc
1881 +++ b/mysql-test/t/percona_log_slow_slave_statements-slave.opt
1883 +--long_query_time=0
1884 \ No newline at end of file
1886 +++ b/mysql-test/t/percona_log_slow_slave_statements.test
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';
1894 +-- disable_warnings
1895 +DROP TABLE IF EXISTS t;
1898 +CREATE TABLE t(id INT);
1899 +sync_slave_with_master;
1902 +--source include/log_start.inc
1904 +--disable_query_log
1905 +--disable_result_log
1909 +INSERT INTO t VALUES (1);
1910 +sync_slave_with_master;
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
1922 +INSERT INTO t VALUES (2);
1923 +sync_slave_with_master;
1925 +--source include/restart_slave_sql.inc
1928 +--let value=`$show`
1929 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1933 +INSERT INTO t VALUES (3);
1934 +sync_slave_with_master;
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
1946 +INSERT INTO t VALUES (4);
1947 +sync_slave_with_master;
1949 +--source include/restart_slave_sql.inc
1952 +--let value=`$show`
1953 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1957 +INSERT INTO t VALUES (5);
1958 +sync_slave_with_master;
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
1970 +INSERT INTO t VALUES (6);
1971 +sync_slave_with_master;
1973 +--source include/restart_slave_sql.inc
1976 +--let value=`$show`
1977 +--echo LOG_SLOW_SLAVE_STATAMENTS is $value
1981 +INSERT INTO t VALUES (7);
1982 +sync_slave_with_master;
1985 +--enable_result_log
1988 +--source include/log_stop.inc
1989 +SET GLOBAL log_slow_slave_statements=default;
1995 +--let grep_pattern= INSERT INTO t VALUES \($i\)
1996 +--source include/log_grep.inc
2002 +sync_slave_with_master;
2004 +--source include/rpl_end.inc
2006 +++ b/mysql-test/t/percona_log_slow_sp_statements-cl-master.opt
2008 +--log_slow_sp_statements
2010 +++ b/mysql-test/t/percona_log_slow_sp_statements-cl.test
2012 +SHOW VARIABLES LIKE 'log_slow_sp_statements';
2013 +SHOW GLOBAL VARIABLES LIKE 'log_slow_sp_statements';
2015 +++ b/mysql-test/t/percona_log_slow_sp_statements.test
2017 +--source include/have_debug.inc
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
2026 +CREATE PROCEDURE test_f()
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;
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;
2042 +--let grep_pattern = Query_time
2043 +--source include/log_grep.inc
2045 +DROP PROCEDURE test_f;
2047 +++ b/mysql-test/t/percona_log_slow_verbosity-cl-master.opt
2049 +--log_slow_verbosity="full"
2051 +++ b/mysql-test/t/percona_log_slow_verbosity-cl.test
2053 +SHOW VARIABLES LIKE 'log_slow_verbosity';
2054 +SHOW GLOBAL VARIABLES LIKE 'log_slow_verbosity';
2056 +++ b/mysql-test/t/percona_log_slow_verbosity.test
2058 +--source include/have_innodb.inc
2059 +--source include/have_debug.inc
2061 +SET SESSION long_query_time=1;
2062 +--let log_file=percona.slow_extended.log_slow_verbosity
2063 +--source include/log_start.inc
2065 +SET SESSION query_exec_time=2.1;
2067 +SET SESSION log_slow_verbosity=innodb;
2069 +SET SESSION query_exec_time=default;
2071 +--source include/log_stop.inc
2072 +SET log_slow_verbosity=default;
2073 +SET long_query_time=default;
2075 +--let grep_pattern = No InnoDB statistics available for this query
2076 +--source include/log_grep.inc
2078 +++ b/mysql-test/t/percona_long_query_time.test
2080 +--source include/have_debug.inc
2082 +SET long_query_time=2;
2083 +--let log_file=percona.slow_extended.long_query_time
2084 +--source include/log_start.inc
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;
2090 +SET long_query_time=4;
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;
2096 +SET SESSION query_exec_time=default;
2098 +SET long_query_time=2;
2100 +--source include/log_stop.inc
2101 +SET long_query_time=default;
2103 +--let grep_pattern = Query_time
2104 +--source include/log_grep.inc
2106 +++ b/mysql-test/t/percona_slow_query_log_timestamp_always-cl-master.opt
2108 +--slow_query_log_timestamp_always
2109 \ No newline at end of file
2111 +++ b/mysql-test/t/percona_slow_query_log_timestamp_always-cl.test
2113 +SHOW VARIABLES LIKE 'slow_query_log_timestamp_always';
2114 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_always';
2116 +++ b/mysql-test/t/percona_slow_query_log_timestamp_always.test
2118 +--source include/have_debug.inc
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
2125 +SET SESSION query_exec_time=2.1;
2130 +SET GLOBAL slow_query_log_timestamp_always=OFF;
2132 +SET SESSION query_exec_time=2.1;
2137 +SET GLOBAL slow_query_log_timestamp_always=ON;
2139 +SET SESSION query_exec_time=2.1;
2144 +SET SESSION query_exec_time=default;
2146 +--source include/log_stop.inc
2147 +SET GLOBAL slow_query_log_timestamp_always=default;
2148 +SET long_query_time=default;
2150 +--let grep_pattern = # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
2151 +--source include/log_grep.inc
2153 +++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-cl-master.opt
2155 +--slow_query_log_timestamp_precision='microsecond'
2156 \ No newline at end of file
2158 +++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-cl.test
2160 +SHOW VARIABLES LIKE 'slow_query_log_timestamp_precision';
2161 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_precision';
2163 +++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-master.opt
2165 +--slow_query_log_timestamp_always
2166 \ No newline at end of file
2168 +++ b/mysql-test/t/percona_slow_query_log_timestamp_precision.test
2170 +--source include/have_debug.inc
2172 +SET long_query_time=2;
2173 +--let log_file=percona.slow_extended.slow_query_log_timestamp_precision
2174 +--source include/log_start.inc
2176 +SET SESSION query_exec_time=2.1;
2180 +SET GLOBAL slow_query_log_timestamp_precision='microsecond';
2184 +SET SESSION query_exec_time=default;
2186 +--source include/log_stop.inc
2187 +SET GLOBAL slow_query_log_timestamp_precision=default;
2188 +SET long_query_time=default;
2190 +--let grep_pattern = # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+.[0-9]+
2191 +--source include/log_grep.inc
2193 +--let grep_pattern = # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
2194 +--source include/log_grep.inc
2196 +++ b/mysql-test/t/percona_slow_query_log_use_global_control.test
2198 +--source include/have_debug.inc
2199 +--source include/have_innodb.inc
2201 +SET GLOBAL long_query_time=1;
2203 +--let log_file=percona.slow_extended.slow_query_log_use_global_control
2204 +--source include/log_start.inc
2206 +SET SESSION query_exec_time=1.1;
2209 +SET GLOBAL log_slow_verbosity=innodb;
2210 +SET GLOBAL slow_query_log_use_global_control="log_slow_verbosity,long_query_time";
2214 +SET SESSION query_exec_time=default;
2216 +--source include/log_stop.inc
2219 +SET GLOBAL slow_query_log_use_global_control=default;
2220 +SET GLOBAL log_slow_verbosity=default;
2221 +SET GLOBAL long_query_time=default;
2223 +--let grep_pattern = No InnoDB statistics available for this query
2224 +--source include/log_grep.inc
2227 +++ b/mysql-test/r/percona_slow_query_log_use_global_control-cl.result
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
2236 +++ b/mysql-test/t/percona_slow_query_log_use_global_control-cl-master.opt
2238 +--slow_query_log_use_global_control="log_slow_verbosity,long_query_time"
2240 +++ b/mysql-test/t/percona_slow_query_log_use_global_control-cl.test
2242 +SHOW VARIABLES LIKE 'slow_query_log_use_global_control';
2243 +SHOW GLOBAL VARIABLES LIKE 'slow_query_log_use_global_control';
2245 +++ b/mysql-test/r/percona_min_examined_row_limit.result
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;
2259 +SET GLOBAL min_examined_row_limit=5;
2260 +select * from t as t1, t as t2;
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
2282 +++ b/mysql-test/t/percona_min_examined_row_limit.test
2284 +--source include/have_debug.inc
2287 +drop table if exists t;
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);
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
2300 +SET SESSION query_exec_time=2.1;
2303 +SET GLOBAL min_examined_row_limit=5;
2305 +select * from t as t1, t as t2;
2308 +SET SESSION query_exec_time=default;
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;
2315 +--let grep_pattern = Query_time
2316 +--source include/log_grep.inc
2319 --- a/sql/log_event.cc
2320 +++ b/sql/log_event.cc
2321 @@ -2380,6 +2380,14 @@
2322 start+= host.length;
2326 + if (thd && thd->variables.query_exec_time > 0)
2328 + *start++= Q_QUERY_EXEC_TIME;
2329 + int8store(start, thd->variables.query_exec_time);
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);
2340 +#if !defined(DBUG_OFF) && !defined(MYSQL_CLIENT)
2341 + case Q_QUERY_EXEC_TIME:
2343 + THD *thd= current_thd;
2344 + CHECK_SPACE(pos, end, 8);
2346 + thd->variables.query_exec_time= uint8korr(pos);
2353 CHECK_SPACE(pos, end, 1);
2354 --- a/sql/log_event.h
2355 +++ b/sql/log_event.h
2356 @@ -342,6 +342,10 @@
2358 #define Q_INVOKER 11
2361 +#define Q_QUERY_EXEC_TIME 250
2364 /* Intvar event post-header */
2366 /* Intvar event data */
2368 +++ b/mysql-test/suite/sys_vars/r/query_exec_time_basic.result
2370 +SET GLOBAL query_exec_time=default;
2371 +SET SESSION query_exec_time=default;
2373 +++ b/mysql-test/suite/sys_vars/t/query_exec_time_basic.test
2375 +--source include/have_debug.inc
2377 +SET GLOBAL query_exec_time=default;
2378 +SET SESSION query_exec_time=default;