Merge lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory into lp:percona-server/5.5

Proposed by 林晓斌
Status: Superseded
Proposed branch: lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory
Merge into: lp:percona-server/5.5
Diff against target: 6450 lines (+879/-2772)
4 files modified
doc/source/diagnostics/slow_log_in_memory.rst (+74/-0)
patches/series (+1/-0)
patches/slow_extended.patch (+0/-2772)
patches/slowlog_in_memory.patch (+804/-0)
To merge this branch: bzr merge lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory
Reviewer Review Type Date Requested Status
Oleg Tsarev Pending
Review via email: mp+86783@code.launchpad.net

This proposal supersedes a proposal from 2011-12-21.

This proposal has been superseded by a proposal from 2011-12-29.

Description of the change

patch for https://blueprints.launchpad.net/percona-server/+spec/log-queries-in-memory.

add a variable 'slowlog_in_memory_audit_max_memory' and global status 'slow_log_current_memory'

If the current_memory grows larger than max_memory, the eldest ones will be wash out.
Same action happens when max_mamory are set to a new value that is less than current_memory.

To post a comment you must log in.
Revision history for this message
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal

1. Please add patch name to the "patches/series" file
2. About innodb_trx_id. Please look to two following cases:
 * log_slow_verbosity doesn't set "innodb"
 * query doesn't use the InnoDB
In first case slow query log will has no information about InnoDB
In second case slow query will have line "# No InnoDB statistics available for this query\n"
In this two cases innodb_trx_id will be incorrect, and you can't use and setup it.

Please handle variable innodb_was_used correctly (at least for innodb_trx_id)

3. Following is very, very bad:
+ if (general_query)
+ {
....
+ }
+ else
+ {
+ this->general_query= "NULL";
+ this->general_query_len= 5;
+ }
You are break SQL semantic. For example query:
SELECT * FROM INSFORMATION_SCHEMA.I_S_SLOW_LOG WHERE QUERY IS NULL
or any join will not work correctly.
You are break SQL language semantic by string "NULL" instead of NULL

Same for Schema.

4. I_S_SLOW_LOG not very good name. Why SLOW_LOG bad?

5. Please add documentation to the doc/

6. Sleep in the test file - bad idea. Please replace this by debug variable query_exec_time.

7. Please add tests to sys_vars suite for the all added variables.

Please fix this, and I will review again.

review: Needs Fixing
Revision history for this message
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal

8.
+ ulonglong utime_of_query= thd->current_utime() - thd->utime_after_lock;
+ if (utime_of_query <= thd->variables.long_query_time)
+ return;

Please look into the slow_extended.patch:

static inline ulonglong get_query_exec_time(THD *thd, ulonglong cur_utime)
...
thd->server_status|= SERVER_QUERY_WAS_SLOW;

Please better use this status variable, instead of calculate query execution time directly.

Revision history for this message
林晓斌 (dingqi-lxb) wrote : Posted in a previous version of this proposal

Thank you. Oleg, I have some items to discuss.

2. About innodb_trx_id. Please look to two following cases
   In these two cases, the variable thd->innodb_trx_id is set to 0. It seems that I have to show it in the result table as 0, is there other result even use innodb_was_used ?

8.About calculating query execution time directly, it is because that I have to get the query_time, the status is not enough.

* Why plugin doesn't uninstall in test?
  You mean that it shows " Plugin is busy and will be uninstalled on shutdown" in result-file? It is the same with the demo for audit plugin "null_audit", the strategy decided by mysqld

Revision history for this message
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal

On Mon, Dec 12, 2011 at 12:05 PM, 林晓斌 <email address hidden> wrote:
> Thank you. Oleg, I have some items to discuss.
>
> 2. About innodb_trx_id. Please look to two following cases
>   In these two cases, the variable thd->innodb_trx_id is set to 0.  It seems that I have to show it in the result table as 0, is there other result even use innodb_was_used ?

I think right decision is "NULL" value instead of 0.
>
> 8.About calculating query execution time directly, it is because that I have to get the query_time, the status is not enough.
>
> * Why plugin doesn't uninstall in test?
>  You mean that it shows " Plugin is busy and will be uninstalled on shutdown" in result-file? It is the same with the demo for audit plugin "null_audit", the strategy decided by mysqld

Ok

> --
> https://code.launchpad.net/~dingqi-lxb/percona-server/5.5_log_queries_in_memory/+merge/85251
> You are reviewing the proposed merge of lp:~dingqi-lxb/percona-server/5.5_log_queries_in_memory into lp:percona-server.

--
Oleg Tsarev, Software Engineer, Percona Inc.

Revision history for this message
林晓斌 (dingqi-lxb) wrote : Posted in a previous version of this proposal

2. About innodb_trx_id. Generally, when the thd->innodb_trx_id is 0, the value of "INNODB_TRX_ID" should show NULL, so the thd->innodb_was_used will not be imported here.

7. Please add tests to sys_vars suite for the all added variables.
   The variable add in this plugin will not be seen in other test-case, it can only be seen the plugin is installed. So, is test-case in sys_vars suits necessary?

Revision history for this message
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal

On Wed, 21 Dec 2011 02:50:35 -0000, 林晓斌 <email address hidden> wrote:
> +There are two plugins in the feature. They can be installed by
> command ``"install plugin SLOWLOG_IN_MEMORY_AUDIT soname
> 'slowlog_in_memory.so'"`` and ``"install plugin SLOW_LOG soname
> 'slowlog_in_memory.so'"``, they work by keeping one list in memory.

I think we should be consistent in naming. SLOW_LOG instead of SLOWLOG
and slow_log instead of slowlog.
--
Stewart Smith

Revision history for this message
Baron Schwartz (baron-xaprb) wrote : Posted in a previous version of this proposal

I'm sorry that I haven't noticed this discussion before, but I believe that it would be best to avoid a query time in milliseconds:

1. It should have microsecond resolution. Milliseconds is not enough.
2. It should be named EXEC_TIME and should be a floating-point value in seconds so the user does not have to convert the value to seconds.

199. By 林晓斌

merge from trunk

200. By 林晓斌

add slowlog_in_memory.patch

Unmerged revisions

200. By 林晓斌

add slowlog_in_memory.patch

199. By 林晓斌

merge from trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'doc/source/diagnostics/slow_log_in_memory.rst'
2--- doc/source/diagnostics/slow_log_in_memory.rst 1970-01-01 00:00:00 +0000
3+++ doc/source/diagnostics/slow_log_in_memory.rst 2011-12-29 03:46:24 +0000
4@@ -0,0 +1,74 @@
5+.. _slow_log_in_memory:
6+
7+=================
8+ Slow Log In Memory
9+=================
10+
11+The feature is used to save slow queries in memory. This feature adds an ``INFORMATION_SCHEMA.SLOW_LOG`` table to show the latest queries, a variable to limit the max memory used, and status to show the status of memory used.
12+
13+There are two plugins in the feature. They can be installed by command ``"install plugin SLOWLOG_IN_MEMORY_AUDIT soname 'slowlog_in_memory.so'"`` and ``"install plugin SLOW_LOG soname 'slowlog_in_memory.so'"``, they work by keeping one list in memory.
14+
15+
16+Other Information
17+=================
18+
19+ * Author/Origin:
20+ *Percona*; *Percona* added an ``INFORMATION_SCHEMA`` table and the :variable:`slowlog_in_memory_audit_max_memory` and the :status:`slow_log_current_memory`.
21+
22+System Variables
23+================
24+
25+.. variable:: slowlog_in_memory_audit_max_memory
26+
27+ :cli: Yes
28+ :conf: Yes
29+ :scope: Global
30+ :dyn: Yes
31+ :vartype: ULONG
32+ :default: 1M
33+ :range: 0 - 1G
34+
35+The variable is used to limit the max-memory used for slow log. If a new slow query will make the `current_memory` bigger than this value, the most eldest items will be discarded, until there is enough memory for new item. When the value is decrease dynamically, it behaves the same.
36+
37+Status Variables
38+================
39+
40+One new status variable was introduced by this feature.
41+
42+.. variable:: slow_log_current_memory
43+
44+ :vartype: ULONG
45+ :scope: Global
46+
47+The variable showes the current memory used for the slow queries. It can never be bigger than the `slowlog_in_memory_audit_max_memory` variable.
48+
49+
50+INFORMATION_SCHEMA Tables
51+=========================
52+
53+.. table:: INFORMATION_SCHEMA.SLOW_LOG
54+
55+ :column EVENT_ID: A global increment id for every record in the table, can be used to identify every one.
56+ :column TIMESTAMP: The timestamp when the query stop.
57+ :column THREAD_ID: The thread_id of the query.
58+ :column DB: The current database() of the query, may be NULL.
59+ :column INNODB_TRX_ID: The Innodb_trx_id if InnoDB is used, may be NULL.
60+ :column ERROR: The errno of the query, 0 means no error.
61+ :column MS_QUERY_TIME: The query_exec_time of the query, in second.
62+ :column QUERY: The query statement.
63+
64+This table holds the lastest slow queries.
65+
66+Example: ::
67+
68+ mysql> select * from information_schema.slow_log \G
69+ *************************** 1. row ***************************
70+ EVENT_ID: 1
71+ TIMESTAMP: 1323753896
72+ THREAD_ID: 2
73+ DB: test
74+ INNODB_TRX_ID: NULL
75+ ERRNO: 0
76+ MS_QUERY_TIME: 3001
77+ QUERY: select sleep(3)
78+
79
80=== modified file 'patches/series'
81--- patches/series 2011-12-16 09:37:26 +0000
82+++ patches/series 2011-12-29 03:46:24 +0000
83@@ -62,3 +62,4 @@
84 bug45702.patch
85 group_commit.patch
86 warning_fixes.patch
87+slowlog_in_memory.patch
88
89=== added file 'patches/slow_extended.patch'
90--- patches/slow_extended.patch 1970-01-01 00:00:00 +0000
91+++ patches/slow_extended.patch 2011-12-29 03:46:24 +0000
92@@ -0,0 +1,2772 @@
93+# name : slow_extended.patch
94+# introduced : 11 or before
95+# maintainer : Oleg
96+#
97+#!!! notice !!!
98+# Any small change to this file in the main branch
99+# should be done or reviewed by the maintainer!
100+--- a/include/mysql/plugin_audit.h.pp
101++++ b/include/mysql/plugin_audit.h.pp
102+@@ -186,6 +186,16 @@
103+ char *thd_security_context(void* thd, char *buffer, unsigned int length,
104+ unsigned int max_query_len);
105+ void thd_inc_row_count(void* thd);
106++void increment_thd_innodb_stats(void* thd,
107++ unsigned long long trx_id,
108++ long io_reads,
109++ long long io_read,
110++ long io_reads_wait_timer,
111++ long lock_que_wait_timer,
112++ long que_wait_timer,
113++ long page_access);
114++unsigned long thd_log_slow_verbosity(const void* thd);
115++int thd_opt_slow_log();
116+ int mysql_tmpfile(const char *prefix);
117+ int thd_killed(const void* thd);
118+ unsigned long thd_get_thread_id(const void* thd);
119+--- a/include/mysql/plugin_auth.h.pp
120++++ b/include/mysql/plugin_auth.h.pp
121+@@ -186,6 +186,16 @@
122+ char *thd_security_context(void* thd, char *buffer, unsigned int length,
123+ unsigned int max_query_len);
124+ void thd_inc_row_count(void* thd);
125++void increment_thd_innodb_stats(void* thd,
126++ unsigned long long trx_id,
127++ long io_reads,
128++ long long io_read,
129++ long io_reads_wait_timer,
130++ long lock_que_wait_timer,
131++ long que_wait_timer,
132++ long page_access);
133++unsigned long thd_log_slow_verbosity(const void* thd);
134++int thd_opt_slow_log();
135+ int mysql_tmpfile(const char *prefix);
136+ int thd_killed(const void* thd);
137+ unsigned long thd_get_thread_id(const void* thd);
138+--- a/include/mysql/plugin_ftparser.h.pp
139++++ b/include/mysql/plugin_ftparser.h.pp
140+@@ -139,6 +139,16 @@
141+ char *thd_security_context(void* thd, char *buffer, unsigned int length,
142+ unsigned int max_query_len);
143+ void thd_inc_row_count(void* thd);
144++void increment_thd_innodb_stats(void* thd,
145++ unsigned long long trx_id,
146++ long io_reads,
147++ long long io_read,
148++ long io_reads_wait_timer,
149++ long lock_que_wait_timer,
150++ long que_wait_timer,
151++ long page_access);
152++unsigned long thd_log_slow_verbosity(const void* thd);
153++int thd_opt_slow_log();
154+ int mysql_tmpfile(const char *prefix);
155+ int thd_killed(const void* thd);
156+ unsigned long thd_get_thread_id(const void* thd);
157+--- a/include/mysql/plugin.h
158++++ b/include/mysql/plugin.h
159+@@ -545,6 +545,17 @@
160+ /* Increments the row counter, see THD::row_count */
161+ void thd_inc_row_count(MYSQL_THD thd);
162+
163++void increment_thd_innodb_stats(MYSQL_THD thd,
164++ unsigned long long trx_id,
165++ long io_reads,
166++ long long io_read,
167++ long io_reads_wait_timer,
168++ long lock_que_wait_timer,
169++ long que_wait_timer,
170++ long page_access);
171++unsigned long thd_log_slow_verbosity(const MYSQL_THD thd);
172++int thd_opt_slow_log();
173++#define EXTENDED_SLOWLOG
174+ /**
175+ Create a temporary file.
176+
177+--- /dev/null
178++++ b/patch_info/slow_extended.info
179+@@ -0,0 +1,25 @@
180++File=slow_extended.patch
181++Name=Extended statistics in slow.log (not InnoDB part)
182++Version=1.3
183++Author=Percona <info@percona.com>
184++License=GPL
185++Comment=
186++Changelog
187++2008-11-26
188++YK: Fix inefficient determination of trx, Make not to call useless gettimeofday when don't use slow log. Make log_slow_queries dynamic (bool).
189++
190++2008-11-07
191++VT: Moved log_slow_rate_limit in SHOW VARIABLE into right place
192++
193++2008-11
194++Arjen Lentz: Fixups (backward compatibility) by Arjen Lentz <arjen@openquery.com.au>
195++
196++2010-07
197++1) Fix overflow of query time and lock time (Bug 600360) (slow_extended_fix_overflow.patch merged)
198++2) Control global slow feature merged (control_global_slow.patch merged)
199++3) Microseconds in slow query log merged (microseconds_in_slow_query_log.patch merged)
200++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)
201++5) Fix innodb_stats on replication (Bug 600684)
202++6) Change variable types (system/command-line)
203++2011-01
204++Patch profiling_slow.patch was merged
205+--- a/scripts/mysqldumpslow.sh
206++++ b/scripts/mysqldumpslow.sh
207+@@ -102,8 +102,8 @@
208+ s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//;
209+ my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('','');
210+
211+- s/^# Query_time: ([0-9.]+)\s+Lock_time: ([0-9.]+)\s+Rows_sent: ([0-9.]+).*\n//;
212+- my ($t, $l, $r) = ($1, $2, $3);
213++ s/^# Query_time: (\d+(\.\d+)?) Lock_time: (\d+(\.\d+)?) Rows_sent: (\d+(\.\d+)?).*\n//;
214++ my ($t, $l, $r) = ($1, $3, $5);
215+ $t -= $l unless $opt{l};
216+
217+ # remove fluff that mysqld writes to log when it (re)starts:
218+--- a/sql/event_scheduler.cc
219++++ b/sql/event_scheduler.cc
220+@@ -195,6 +195,7 @@
221+ thd->client_capabilities|= CLIENT_MULTI_RESULTS;
222+ mysql_mutex_lock(&LOCK_thread_count);
223+ thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
224++ thd->write_to_slow_log = TRUE;
225+ mysql_mutex_unlock(&LOCK_thread_count);
226+
227+ /*
228+--- a/sql/filesort.cc
229++++ b/sql/filesort.cc
230+@@ -193,6 +193,7 @@
231+ {
232+ status_var_increment(thd->status_var.filesort_scan_count);
233+ }
234++ thd->query_plan_flags|= QPLAN_FILESORT;
235+ #ifdef CAN_TRUST_RANGE
236+ if (select && select->quick && select->quick->records > 0L)
237+ {
238+@@ -261,6 +262,7 @@
239+ /* filesort cannot handle zero-length records during merge. */
240+ DBUG_ASSERT(param.sort_length != 0);
241+
242++ thd->query_plan_flags|= QPLAN_FILESORT_DISK;
243+ if (table_sort.buffpek && table_sort.buffpek_len < maxbuffer)
244+ {
245+ my_free(table_sort.buffpek);
246+@@ -1209,6 +1211,7 @@
247+ DBUG_ENTER("merge_buffers");
248+
249+ status_var_increment(current_thd->status_var.filesort_merge_passes);
250++ current_thd->query_plan_fsort_passes++;
251+ if (param->not_killable)
252+ {
253+ killed= &not_killable;
254+--- a/sql/log.cc
255++++ b/sql/log.cc
256+@@ -715,11 +715,13 @@
257+ */
258+
259+ bool Log_to_csv_event_handler::
260+- log_slow(THD *thd, time_t current_time, time_t query_start_arg,
261++ log_slow(THD *thd, ulonglong current_utime, time_t query_start_arg,
262+ const char *user_host, uint user_host_len,
263+ ulonglong query_utime, ulonglong lock_utime, bool is_command,
264+ const char *sql_text, uint sql_text_len)
265+ {
266++ time_t current_time= my_time_possible_from_micro(current_utime);
267++
268+ TABLE_LIST table_list;
269+ TABLE *table;
270+ bool result= TRUE;
271+@@ -935,14 +937,14 @@
272+ /** Wrapper around MYSQL_LOG::write() for slow log. */
273+
274+ bool Log_to_file_event_handler::
275+- log_slow(THD *thd, time_t current_time, time_t query_start_arg,
276++ log_slow(THD *thd, ulonglong current_utime, time_t query_start_arg,
277+ const char *user_host, uint user_host_len,
278+ ulonglong query_utime, ulonglong lock_utime, bool is_command,
279+ const char *sql_text, uint sql_text_len)
280+ {
281+ Silence_log_table_errors error_handler;
282+ thd->push_internal_handler(&error_handler);
283+- bool retval= mysql_slow_log.write(thd, current_time, query_start_arg,
284++ bool retval= mysql_slow_log.write(thd, current_utime, query_start_arg,
285+ user_host, user_host_len,
286+ query_utime, lock_utime, is_command,
287+ sql_text, sql_text_len);
288+@@ -1200,8 +1202,6 @@
289+
290+ if (*slow_log_handler_list)
291+ {
292+- time_t current_time;
293+-
294+ /* do not log slow queries from replication threads */
295+ if (thd->slave_thread && !opt_log_slow_slave_statements)
296+ return 0;
297+@@ -1216,16 +1216,29 @@
298+ /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
299+ user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
300+ sctx->priv_user ? sctx->priv_user : "", "[",
301+- sctx->user ? sctx->user : "", "] @ ",
302++ sctx->user ? sctx->user : (thd->slave_thread ? "SQL_SLAVE" : ""), "] @ ",
303+ sctx->host ? sctx->host : "", " [",
304+ sctx->ip ? sctx->ip : "", "]", NullS) -
305+ user_host_buff);
306+
307+- current_time= my_time_possible_from_micro(current_utime);
308+ if (thd->start_utime)
309+ {
310+- query_utime= (current_utime - thd->start_utime);
311+- lock_utime= (thd->utime_after_lock - thd->start_utime);
312++ if(current_utime < thd->start_utime)
313++ {
314++ query_utime= 0;
315++ }
316++ else
317++ {
318++ query_utime= (current_utime - thd->start_utime);
319++ }
320++ if(thd->utime_after_lock < thd->start_utime)
321++ {
322++ lock_utime= 0;
323++ }
324++ else
325++ {
326++ lock_utime= (thd->utime_after_lock - thd->start_utime);
327++ }
328+ }
329+ else
330+ {
331+@@ -1240,7 +1253,7 @@
332+ }
333+
334+ for (current_handler= slow_log_handler_list; *current_handler ;)
335+- error= (*current_handler++)->log_slow(thd, current_time, thd->start_time,
336++ error= (*current_handler++)->log_slow(thd, current_utime, thd->start_time,
337+ user_host_buff, user_host_len,
338+ query_utime, lock_utime, is_command,
339+ query, query_length) || error;
340+@@ -2656,12 +2669,13 @@
341+ TRUE - error occured
342+ */
343+
344+-bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
345++bool MYSQL_QUERY_LOG::write(THD *thd, ulonglong current_utime,
346+ time_t query_start_arg, const char *user_host,
347+ uint user_host_len, ulonglong query_utime,
348+ ulonglong lock_utime, bool is_command,
349+ const char *sql_text, uint sql_text_len)
350+ {
351++ time_t current_time= my_time_possible_from_micro(current_utime);
352+ bool error= 0;
353+ DBUG_ENTER("MYSQL_QUERY_LOG::write");
354+
355+@@ -2683,17 +2697,28 @@
356+
357+ if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
358+ {
359+- if (current_time != last_time)
360++ if (opt_slow_query_log_timestamp_always || current_time != last_time)
361+ {
362+ last_time= current_time;
363+ struct tm start;
364+ localtime_r(&current_time, &start);
365+-
366+- buff_len= my_snprintf(buff, sizeof buff,
367+- "# Time: %02d%02d%02d %2d:%02d:%02d\n",
368+- start.tm_year % 100, start.tm_mon + 1,
369+- start.tm_mday, start.tm_hour,
370+- start.tm_min, start.tm_sec);
371++ if(opt_slow_query_log_timestamp_precision & SLOG_MICROSECOND)
372++ {
373++ ulonglong microsecond = current_utime % (1000 * 1000);
374++ buff_len= snprintf(buff, sizeof buff,
375++ "# Time: %02d%02d%02d %2d:%02d:%02d.%010lld\n",
376++ start.tm_year % 100, start.tm_mon + 1,
377++ start.tm_mday, start.tm_hour,
378++ start.tm_min, start.tm_sec,microsecond);
379++ }
380++ else
381++ {
382++ buff_len= my_snprintf(buff, sizeof buff,
383++ "# Time: %02d%02d%02d %2d:%02d:%02d\n",
384++ start.tm_year % 100, start.tm_mon + 1,
385++ start.tm_mday, start.tm_hour,
386++ start.tm_min, start.tm_sec);
387++ }
388+
389+ /* Note that my_b_write() assumes it knows the length for this */
390+ if (my_b_write(&log_file, (uchar*) buff, buff_len))
391+@@ -2710,13 +2735,71 @@
392+ /* For slow query log */
393+ sprintf(query_time_buff, "%.6f", ulonglong2double(query_utime)/1000000.0);
394+ sprintf(lock_time_buff, "%.6f", ulonglong2double(lock_utime)/1000000.0);
395++ DBUG_PRINT("info", ("Last_errno: %u", thd->last_errno));
396+ if (my_b_printf(&log_file,
397+- "# Query_time: %s Lock_time: %s"
398+- " Rows_sent: %lu Rows_examined: %lu\n",
399++ "# Thread_id: %lu Schema: %s Last_errno: %u Killed: %u\n" \
400++ "# Query_time: %s Lock_time: %s Rows_sent: %lu Rows_examined: %lu Rows_affected: %lu Rows_read: %lu\n"
401++ "# Bytes_sent: %lu Tmp_tables: %lu Tmp_disk_tables: %lu Tmp_table_sizes: %lu\n",
402++ (ulong) thd->thread_id, (thd->db ? thd->db : ""),
403++ thd->last_errno, (uint) thd->killed,
404+ query_time_buff, lock_time_buff,
405+ (ulong) thd->sent_row_count,
406+- (ulong) thd->examined_row_count) == (uint) -1)
407++ (ulong) thd->examined_row_count,
408++ ((long) thd->get_row_count_func() > 0 ) ? (ulong) thd->get_row_count_func() : 0,
409++ (ulong) thd->sent_row_count,
410++ (ulong) (thd->status_var.bytes_sent - thd->bytes_sent_old),
411++ (ulong) thd->tmp_tables_used,
412++ (ulong) thd->tmp_tables_disk_used,
413++ (ulong) thd->tmp_tables_size) == (uint) -1)
414+ tmp_errno= errno;
415++
416++#if defined(ENABLED_PROFILING)
417++ thd->profiling.print_current(&log_file);
418++#endif
419++ if (thd->innodb_was_used)
420++ {
421++ char buf[20];
422++ snprintf(buf, 20, "%llX", thd->innodb_trx_id);
423++ if (my_b_printf(&log_file,
424++ "# InnoDB_trx_id: %s\n", buf) == (uint) -1)
425++ tmp_errno=errno;
426++ }
427++ if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_QUERY_PLAN)) &&
428++ my_b_printf(&log_file,
429++ "# QC_Hit: %s Full_scan: %s Full_join: %s Tmp_table: %s Tmp_table_on_disk: %s\n" \
430++ "# Filesort: %s Filesort_on_disk: %s Merge_passes: %lu\n",
431++ ((thd->query_plan_flags & QPLAN_QC) ? "Yes" : "No"),
432++ ((thd->query_plan_flags & QPLAN_FULL_SCAN) ? "Yes" : "No"),
433++ ((thd->query_plan_flags & QPLAN_FULL_JOIN) ? "Yes" : "No"),
434++ ((thd->query_plan_flags & QPLAN_TMP_TABLE) ? "Yes" : "No"),
435++ ((thd->query_plan_flags & QPLAN_TMP_DISK) ? "Yes" : "No"),
436++ ((thd->query_plan_flags & QPLAN_FILESORT) ? "Yes" : "No"),
437++ ((thd->query_plan_flags & QPLAN_FILESORT_DISK) ? "Yes" : "No"),
438++ thd->query_plan_fsort_passes) == (uint) -1)
439++ tmp_errno=errno;
440++ if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_INNODB)) && thd->innodb_was_used)
441++ {
442++ char buf[3][20];
443++ snprintf(buf[0], 20, "%.6f", thd->innodb_io_reads_wait_timer / 1000000.0);
444++ snprintf(buf[1], 20, "%.6f", thd->innodb_lock_que_wait_timer / 1000000.0);
445++ snprintf(buf[2], 20, "%.6f", thd->innodb_innodb_que_wait_timer / 1000000.0);
446++ if (my_b_printf(&log_file,
447++ "# InnoDB_IO_r_ops: %lu InnoDB_IO_r_bytes: %lu InnoDB_IO_r_wait: %s\n" \
448++ "# InnoDB_rec_lock_wait: %s InnoDB_queue_wait: %s\n" \
449++ "# InnoDB_pages_distinct: %lu\n",
450++ (ulong) thd->innodb_io_reads,
451++ (ulong) thd->innodb_io_read,
452++ buf[0], buf[1], buf[2],
453++ (ulong) thd->innodb_page_access) == (uint) -1)
454++ tmp_errno=errno;
455++ }
456++ else
457++ {
458++ if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_INNODB)) &&
459++ my_b_printf(&log_file,"# No InnoDB statistics available for this query\n") == (uint) -1)
460++ tmp_errno=errno;
461++ }
462++
463+ if (thd->db && strcmp(thd->db, db))
464+ { // Database changed
465+ if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1)
466+--- a/sql/log.h
467++++ b/sql/log.h
468+@@ -242,7 +242,7 @@
469+ uint user_host_len, int thread_id,
470+ const char *command_type, uint command_type_len,
471+ const char *sql_text, uint sql_text_len);
472+- bool write(THD *thd, time_t current_time, time_t query_start_arg,
473++ bool write(THD *thd, ulonglong current_time, time_t query_start_arg,
474+ const char *user_host, uint user_host_len,
475+ ulonglong query_utime, ulonglong lock_utime, bool is_command,
476+ const char *sql_text, uint sql_text_len);
477+@@ -515,7 +515,7 @@
478+ virtual bool init()= 0;
479+ virtual void cleanup()= 0;
480+
481+- virtual bool log_slow(THD *thd, time_t current_time,
482++ virtual bool log_slow(THD *thd, ulonglong current_time,
483+ time_t query_start_arg, const char *user_host,
484+ uint user_host_len, ulonglong query_utime,
485+ ulonglong lock_utime, bool is_command,
486+@@ -544,7 +544,7 @@
487+ virtual bool init();
488+ virtual void cleanup();
489+
490+- virtual bool log_slow(THD *thd, time_t current_time,
491++ virtual bool log_slow(THD *thd, ulonglong current_utime,
492+ time_t query_start_arg, const char *user_host,
493+ uint user_host_len, ulonglong query_utime,
494+ ulonglong lock_utime, bool is_command,
495+@@ -576,7 +576,7 @@
496+ virtual bool init();
497+ virtual void cleanup();
498+
499+- virtual bool log_slow(THD *thd, time_t current_time,
500++ virtual bool log_slow(THD *thd, ulonglong current_utime,
501+ time_t query_start_arg, const char *user_host,
502+ uint user_host_len, ulonglong query_utime,
503+ ulonglong lock_utime, bool is_command,
504+--- a/sql/mysqld.cc
505++++ b/sql/mysqld.cc
506+@@ -421,6 +421,10 @@
507+ char* opt_secure_file_priv;
508+ my_bool opt_log_slow_admin_statements= 0;
509+ my_bool opt_log_slow_slave_statements= 0;
510++my_bool opt_log_slow_sp_statements= 0;
511++my_bool opt_slow_query_log_timestamp_always= 0;
512++ulonglong opt_slow_query_log_use_global_control= 0;
513++ulong opt_slow_query_log_timestamp_precision= 0;
514+ my_bool lower_case_file_system= 0;
515+ my_bool opt_large_pages= 0;
516+ my_bool opt_super_large_pages= 0;
517+@@ -5892,14 +5896,10 @@
518+ "Don't log extra information to update and slow-query logs.",
519+ &opt_short_log_format, &opt_short_log_format,
520+ 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
521+- {"log-slow-admin-statements", 0,
522+- "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to "
523+- "the slow log if it is open.", &opt_log_slow_admin_statements,
524+- &opt_log_slow_admin_statements, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
525+- {"log-slow-slave-statements", 0,
526++ /*{"log-slow-slave-statements", 0,
527+ "Log slow statements executed by slave thread to the slow log if it is open.",
528+ &opt_log_slow_slave_statements, &opt_log_slow_slave_statements,
529+- 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
530++ 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},*/
531+ {"log-slow-queries", OPT_SLOW_QUERY_LOG,
532+ "Log slow queries to a table or log file. Defaults logging to table "
533+ "mysql.slow_log or hostname-slow.log if --log-output=file is used. "
534+@@ -7288,6 +7288,10 @@
535+
536+ C_MODE_END
537+
538++/* defined in sys_vars.cc */
539++extern void init_log_slow_verbosity();
540++extern void init_slow_query_log_use_global_control();
541++
542+ /**
543+ Get server options from the command line,
544+ and perform related server initializations.
545+@@ -7437,6 +7441,8 @@
546+ global_system_variables.long_query_time= (ulonglong)
547+ (global_system_variables.long_query_time_double * 1e6);
548+
549++ init_log_slow_verbosity();
550++ init_slow_query_log_use_global_control();
551+ if (opt_short_log_format)
552+ opt_specialflag|= SPECIAL_SHORT_LOG_FORMAT;
553+
554+--- a/sql/mysqld.h
555++++ b/sql/mysqld.h
556+@@ -116,6 +116,10 @@
557+ extern char* opt_secure_backup_file_priv;
558+ extern size_t opt_secure_backup_file_priv_len;
559+ extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements;
560++extern my_bool opt_log_slow_sp_statements;
561++extern my_bool opt_slow_query_log_timestamp_always;
562++extern ulonglong opt_slow_query_log_use_global_control;
563++extern ulong opt_slow_query_log_timestamp_precision;
564+ extern my_bool sp_automatic_privileges, opt_noacl;
565+ extern my_bool opt_old_style_user_limits, trust_function_creators;
566+ extern uint opt_crash_binlog_innodb;
567+--- a/sql/slave.cc
568++++ b/sql/slave.cc
569+@@ -2038,6 +2038,7 @@
570+ + MAX_LOG_EVENT_HEADER; /* note, incr over the global not session var */
571+ thd->slave_thread = 1;
572+ thd->enable_slow_log= opt_log_slow_slave_statements;
573++ thd->write_to_slow_log= opt_log_slow_slave_statements;
574+ set_slave_thread_options(thd);
575+ thd->client_capabilities = CLIENT_LOCAL_FILES;
576+ mysql_mutex_lock(&LOCK_thread_count);
577+--- a/sql/sp_head.cc
578++++ b/sql/sp_head.cc
579+@@ -2152,7 +2152,7 @@
580+ DBUG_PRINT("info",(" %.*s: eval args done", (int) m_name.length,
581+ m_name.str));
582+ }
583+- if (!(m_flags & LOG_SLOW_STATEMENTS) && thd->enable_slow_log)
584++ if (!(m_flags & LOG_SLOW_STATEMENTS || opt_log_slow_sp_statements) && thd->enable_slow_log)
585+ {
586+ DBUG_PRINT("info", ("Disabling slow log for the execution"));
587+ save_enable_slow_log= true;
588+--- a/sql/sql_cache.cc
589++++ b/sql/sql_cache.cc
590+@@ -1756,6 +1756,7 @@
591+ response, we can't handle it anyway.
592+ */
593+ (void) trans_commit_stmt(thd);
594++ thd->query_plan_flags|= QPLAN_QC;
595+ if (!thd->stmt_da->is_set())
596+ thd->stmt_da->disable_status();
597+
598+@@ -1766,6 +1767,7 @@
599+ err_unlock:
600+ unlock();
601+ err:
602++ thd->query_plan_flags|= QPLAN_QC_NO;
603+ MYSQL_QUERY_CACHE_MISS(thd->query());
604+ DBUG_RETURN(0); // Query was not cached
605+ }
606+--- a/sql/sql_class.cc
607++++ b/sql/sql_class.cc
608+@@ -616,6 +616,37 @@
609+ thd->warning_info->inc_current_row_for_warning();
610+ }
611+
612++extern "C"
613++void increment_thd_innodb_stats(THD* thd,
614++ unsigned long long trx_id,
615++ long io_reads,
616++ long long io_read,
617++ long io_reads_wait_timer,
618++ long lock_que_wait_timer,
619++ long que_wait_timer,
620++ long page_access)
621++{
622++ thd->innodb_was_used= TRUE;
623++ thd->innodb_trx_id= trx_id;
624++ thd->innodb_io_reads+= io_reads;
625++ thd->innodb_io_read+= io_read;
626++ thd->innodb_io_reads_wait_timer+= io_reads_wait_timer;
627++ thd->innodb_lock_que_wait_timer+= lock_que_wait_timer;
628++ thd->innodb_innodb_que_wait_timer+= que_wait_timer;
629++ thd->innodb_page_access+= page_access;
630++}
631++
632++extern "C"
633++unsigned long thd_log_slow_verbosity(const THD *thd)
634++{
635++ return (unsigned long) thd->variables.log_slow_verbosity;
636++}
637++
638++extern "C"
639++int thd_opt_slow_log()
640++{
641++ return (int) opt_slow_log;
642++}
643+
644+ /**
645+ Dumps a text description of a thread, its security context
646+@@ -942,6 +973,8 @@
647+ const char* msg,
648+ MYSQL_ERROR ** cond_hdl)
649+ {
650++ last_errno= sql_errno;
651++
652+ if (!m_internal_handler)
653+ {
654+ *cond_hdl= NULL;
655+@@ -1236,6 +1269,8 @@
656+ /* Initialize the Debug Sync Facility. See debug_sync.cc. */
657+ debug_sync_init_thread(this);
658+ #endif /* defined(ENABLED_DEBUG_SYNC) */
659++
660++ clear_slow_extended();
661+ }
662+
663+
664+@@ -3682,8 +3717,6 @@
665+ backup->in_sub_stmt= in_sub_stmt;
666+ backup->enable_slow_log= enable_slow_log;
667+ backup->limit_found_rows= limit_found_rows;
668+- backup->examined_row_count= examined_row_count;
669+- backup->sent_row_count= sent_row_count;
670+ backup->cuted_fields= cuted_fields;
671+ backup->client_capabilities= client_capabilities;
672+ backup->savepoints= transaction.savepoints;
673+@@ -3691,6 +3724,7 @@
674+ first_successful_insert_id_in_prev_stmt;
675+ backup->first_successful_insert_id_in_cur_stmt=
676+ first_successful_insert_id_in_cur_stmt;
677++ reset_sub_statement_state_slow_extended(backup);
678+
679+ if ((!lex->requires_prelocking() || is_update_query(lex->sql_command)) &&
680+ !is_current_stmt_binlog_format_row())
681+@@ -3706,13 +3740,74 @@
682+ /* Disable result sets */
683+ client_capabilities &= ~CLIENT_MULTI_RESULTS;
684+ in_sub_stmt|= new_state;
685+- examined_row_count= 0;
686+- sent_row_count= 0;
687+ cuted_fields= 0;
688+ transaction.savepoints= 0;
689+ first_successful_insert_id_in_cur_stmt= 0;
690+ }
691+
692++void THD::clear_slow_extended()
693++{
694++ DBUG_ENTER("THD::clear_slow_extended");
695++ sent_row_count= 0;
696++ examined_row_count= 0;
697++ bytes_sent_old= status_var.bytes_sent;
698++ tmp_tables_used= 0;
699++ tmp_tables_disk_used= 0;
700++ tmp_tables_size= 0;
701++ innodb_was_used= FALSE;
702++ innodb_trx_id= 0;
703++ innodb_io_reads= 0;
704++ innodb_io_read= 0;
705++ innodb_io_reads_wait_timer= 0;
706++ innodb_lock_que_wait_timer= 0;
707++ innodb_innodb_que_wait_timer= 0;
708++ innodb_page_access= 0;
709++ query_plan_flags= QPLAN_NONE;
710++ query_plan_fsort_passes= 0;
711++ last_errno= 0;
712++ DBUG_VOID_RETURN;
713++}
714++
715++void THD::reset_sub_statement_state_slow_extended(Sub_statement_state *backup)
716++{
717++ DBUG_ENTER("THD::reset_sub_statement_state_slow_extended");
718++ backup->sent_row_count= sent_row_count;
719++ backup->examined_row_count= examined_row_count;
720++ backup->tmp_tables_used= tmp_tables_used;
721++ backup->tmp_tables_disk_used= tmp_tables_disk_used;
722++ backup->tmp_tables_size= tmp_tables_size;
723++ backup->innodb_was_used= innodb_was_used;
724++ backup->innodb_io_reads= innodb_io_reads;
725++ backup->innodb_io_read= innodb_io_read;
726++ backup->innodb_io_reads_wait_timer= innodb_io_reads_wait_timer;
727++ backup->innodb_lock_que_wait_timer= innodb_lock_que_wait_timer;
728++ backup->innodb_innodb_que_wait_timer= innodb_innodb_que_wait_timer;
729++ backup->innodb_page_access= innodb_page_access;
730++ backup->query_plan_flags= query_plan_flags;
731++ backup->query_plan_fsort_passes= query_plan_fsort_passes;
732++ clear_slow_extended();
733++ DBUG_VOID_RETURN;
734++}
735++
736++void THD::restore_sub_statement_state_slow_extended(const Sub_statement_state *backup)
737++{
738++ DBUG_ENTER("THD::restore_sub_statement_state_slow_extended");
739++ sent_row_count= backup->sent_row_count;
740++ examined_row_count+= backup->examined_row_count;
741++ tmp_tables_used+= backup->tmp_tables_used;
742++ tmp_tables_disk_used+= backup->tmp_tables_disk_used;
743++ tmp_tables_size+= backup->tmp_tables_size;
744++ innodb_was_used= (innodb_was_used || backup->innodb_was_used);
745++ innodb_io_reads+= backup->innodb_io_reads;
746++ innodb_io_read+= backup->innodb_io_read;
747++ innodb_io_reads_wait_timer+= backup->innodb_io_reads_wait_timer;
748++ innodb_lock_que_wait_timer+= backup->innodb_lock_que_wait_timer;
749++ innodb_innodb_que_wait_timer+= backup->innodb_innodb_que_wait_timer;
750++ innodb_page_access+= backup->innodb_page_access;
751++ query_plan_flags|= backup->query_plan_flags;
752++ query_plan_fsort_passes+= backup->query_plan_fsort_passes;
753++ DBUG_VOID_RETURN;
754++}
755+
756+ void THD::restore_sub_statement_state(Sub_statement_state *backup)
757+ {
758+@@ -3753,7 +3848,6 @@
759+ first_successful_insert_id_in_cur_stmt=
760+ backup->first_successful_insert_id_in_cur_stmt;
761+ limit_found_rows= backup->limit_found_rows;
762+- sent_row_count= backup->sent_row_count;
763+ client_capabilities= backup->client_capabilities;
764+ /*
765+ If we've left sub-statement mode, reset the fatal error flag.
766+@@ -3771,8 +3865,8 @@
767+ The following is added to the old values as we are interested in the
768+ total complexity of the query
769+ */
770+- examined_row_count+= backup->examined_row_count;
771+ cuted_fields+= backup->cuted_fields;
772++ restore_sub_statement_state_slow_extended(backup);
773+ DBUG_VOID_RETURN;
774+ }
775+
776+--- a/sql/sql_class.h
777++++ b/sql/sql_class.h
778+@@ -60,6 +60,33 @@
779+ enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
780+ enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON,
781+ DELAY_KEY_WRITE_ALL };
782++enum enum_slow_query_log_use_global_control {
783++ SLOG_UG_LOG_SLOW_FILTER, SLOG_UG_LOG_SLOW_RATE_LIMIT
784++ , SLOG_UG_LOG_SLOW_VERBOSITY, SLOG_UG_LONG_QUERY_TIME
785++ , SLOG_UG_MIN_EXAMINED_ROW_LIMIT, SLOG_UG_ALL
786++};
787++enum enum_log_slow_verbosity {
788++ SLOG_V_MICROTIME, SLOG_V_QUERY_PLAN, SLOG_V_INNODB,
789++ SLOG_V_PROFILING, SLOG_V_PROFILING_USE_GETRUSAGE,
790++ SLOG_V_MINIMAL, SLOG_V_STANDARD, SLOG_V_FULL
791++};
792++enum enum_slow_query_log_timestamp_precision {
793++ SLOG_SECOND, SLOG_MICROSECOND
794++};
795++#define QPLAN_NONE 0
796++#define QPLAN_QC 1 << 0
797++#define QPLAN_QC_NO 1 << 1
798++#define QPLAN_FULL_SCAN 1 << 2
799++#define QPLAN_FULL_JOIN 1 << 3
800++#define QPLAN_TMP_TABLE 1 << 4
801++#define QPLAN_TMP_DISK 1 << 5
802++#define QPLAN_FILESORT 1 << 6
803++#define QPLAN_FILESORT_DISK 1 << 7
804++enum enum_log_slow_filter {
805++ SLOG_F_QC_NO, SLOG_F_FULL_SCAN, SLOG_F_FULL_JOIN,
806++ SLOG_F_TMP_TABLE, SLOG_F_TMP_DISK, SLOG_F_FILESORT,
807++ SLOG_F_FILESORT_DISK
808++};
809+ enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT,
810+ SLAVE_EXEC_MODE_IDEMPOTENT,
811+ SLAVE_EXEC_MODE_LAST_BIT};
812+@@ -508,6 +535,21 @@
813+
814+ my_bool sysdate_is_now;
815+
816++#ifndef DBUG_OFF
817++ ulonglong query_exec_time;
818++ double query_exec_time_double;
819++#endif
820++ ulong log_slow_rate_limit;
821++ ulonglong log_slow_filter;
822++ ulonglong log_slow_verbosity;
823++
824++ ulong innodb_io_reads;
825++ ulonglong innodb_io_read;
826++ ulong innodb_io_reads_wait_timer;
827++ ulong innodb_lock_que_wait_timer;
828++ ulong innodb_innodb_que_wait_timer;
829++ ulong innodb_page_access;
830++
831+ double long_query_time_double;
832+
833+ } SV;
834+@@ -1140,6 +1182,24 @@
835+ uint in_sub_stmt;
836+ bool enable_slow_log;
837+ bool last_insert_id_used;
838++
839++ /*** Following variables used in slow_extended.patch ***/
840++ ulong tmp_tables_used;
841++ ulong tmp_tables_disk_used;
842++ ulonglong tmp_tables_size;
843++
844++ bool innodb_was_used;
845++ ulong innodb_io_reads;
846++ ulonglong innodb_io_read;
847++ ulong innodb_io_reads_wait_timer;
848++ ulong innodb_lock_que_wait_timer;
849++ ulong innodb_innodb_que_wait_timer;
850++ ulong innodb_page_access;
851++
852++ ulong query_plan_flags;
853++ ulong query_plan_fsort_passes;
854++ /*** The variables above used in slow_extended.patch ***/
855++
856+ SAVEPOINT *savepoints;
857+ enum enum_check_fields count_cuted_fields;
858+ };
859+@@ -1588,6 +1648,71 @@
860+ thr_lock_type update_lock_default;
861+ Delayed_insert *di;
862+
863++ /*** Following variables used in slow_extended.patch ***/
864++ /*
865++ Variable write_to_slow_log:
866++ 1) initialized in
867++ * sql_connect.cc (log_slow_rate_limit support)
868++ * slave.cc (log_slow_slave_statements support)
869++ 2) The variable is initialized on the thread startup and remains
870++ constant afterwards. This will change when
871++ LP #712396 ("log_slow_slave_statements not work on replication
872++ threads without RESTART") is implemented.
873++ 3) An implementation of LP #688646 ("Make query sampling possible by query") should use it.
874++ */
875++ bool write_to_slow_log;
876++ /*
877++ Variable bytes_send_old saves value of thd->status_var.bytes_sent
878++ before query execution.
879++ */
880++ ulonglong bytes_sent_old;
881++ /*
882++ Variables tmp_tables_*** collect statistics about usage of temporary tables
883++ */
884++ ulong tmp_tables_used;
885++ ulong tmp_tables_disk_used;
886++ ulonglong tmp_tables_size;
887++ /*
888++ Variable innodb_was_used shows used or not InnoDB engine in current query.
889++ */
890++ bool innodb_was_used;
891++ /*
892++ Following Variables innodb_*** (is |should be) different from
893++ default values only if (innodb_was_used==TRUE)
894++ */
895++ ulonglong innodb_trx_id;
896++ ulong innodb_io_reads;
897++ ulonglong innodb_io_read;
898++ ulong innodb_io_reads_wait_timer;
899++ ulong innodb_lock_que_wait_timer;
900++ ulong innodb_innodb_que_wait_timer;
901++ ulong innodb_page_access;
902++
903++ /*
904++ Variable query_plan_flags collects information about query plan entites
905++ used on query execution.
906++ */
907++ ulong query_plan_flags;
908++ /*
909++ Variable query_plan_fsort_passes collects information about file sort passes
910++ acquired during query execution.
911++ */
912++ ulong query_plan_fsort_passes;
913++ /*
914++ Query can generate several errors/warnings during execution
915++ (see THD::handle_condition comment in sql_class.h)
916++ Variable last_errno contains the last error/warning acquired during
917++ query execution.
918++ */
919++ uint last_errno;
920++ /*** The variables above used in slow_extended.patch ***/
921++
922++ /*** Following methods used in slow_extended.patch ***/
923++ void clear_slow_extended();
924++ void reset_sub_statement_state_slow_extended(Sub_statement_state *backup);
925++ void restore_sub_statement_state_slow_extended(const Sub_statement_state *backup);
926++ /*** The methods above used in slow_extended.patch ***/
927++
928+ /* <> 0 if we are inside of trigger or stored function. */
929+ uint in_sub_stmt;
930+
931+--- a/sql/sql_connect.cc
932++++ b/sql/sql_connect.cc
933+@@ -721,6 +721,15 @@
934+ MYSQL_CONNECTION_START(thd->thread_id, &thd->security_ctx->priv_user[0],
935+ (char *) thd->security_ctx->host_or_ip);
936+
937++ /*
938++ If rate limiting of slow log writes is enabled, decide whether to log this
939++ new thread's queries or not. Uses extremely simple algorithm. :)
940++ */
941++ thd->write_to_slow_log= FALSE;
942++ if (thd->variables.log_slow_rate_limit <= 1 ||
943++ (thd->thread_id % thd->variables.log_slow_rate_limit) == 0)
944++ thd->write_to_slow_log= TRUE;
945++
946+ prepare_new_connection_state(thd);
947+ return FALSE;
948+ }
949+--- a/sql/sql_parse.cc
950++++ b/sql/sql_parse.cc
951+@@ -114,6 +114,7 @@
952+
953+ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
954+ static void sql_kill(THD *thd, ulong id, bool only_kill_query);
955++static inline ulonglong get_query_exec_time(THD *thd, ulonglong cur_utime);
956+
957+ const char *any_db="*any*"; // Special symbol for check_access
958+
959+@@ -888,6 +889,7 @@
960+ the slow log only if opt_log_slow_admin_statements is set.
961+ */
962+ thd->enable_slow_log= TRUE;
963++ thd->clear_slow_extended();
964+ thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
965+ thd->set_time();
966+ if (!thd->is_valid_time())
967+@@ -1430,6 +1432,60 @@
968+ DBUG_RETURN(error);
969+ }
970+
971++/**
972++ Calculate execution time for the current query.
973++
974++ For debug builds, check the session value of query_exec_time
975++ and if it is not zero, return it instead of the actual execution time.
976++
977++ SET queries are ignored so that statements changing query_exec_time are not
978++ affected by themselves.
979++
980++ @param thd thread handle
981++ @param lex current relative time in microseconds
982++
983++ @return time in microseconds from utime_after_lock
984++*/
985++
986++static inline ulonglong get_query_exec_time(THD *thd, ulonglong cur_utime)
987++{
988++ ulonglong res;
989++#ifndef DBUG_OFF
990++ if (thd->variables.query_exec_time != 0)
991++ res= thd->lex->sql_command != SQLCOM_SET_OPTION ?
992++ thd->variables.query_exec_time : 0;
993++ else
994++#endif
995++
996++ res= cur_utime - thd->utime_after_lock;
997++
998++ if (res > thd->variables.long_query_time)
999++ thd->server_status|= SERVER_QUERY_WAS_SLOW;
1000++ else
1001++ thd->server_status&= ~SERVER_QUERY_WAS_SLOW;
1002++
1003++ return res;
1004++}
1005++
1006++
1007++static inline void copy_global_to_session(THD *thd, ulong flag,
1008++ const ulong *val)
1009++{
1010++ my_ptrdiff_t offset = ((char *)val - (char *)&global_system_variables);
1011++ if (opt_slow_query_log_use_global_control & (1ULL << flag))
1012++ *(ulong *)((char *) &thd->variables + offset) = *val;
1013++}
1014++
1015++
1016++static inline void copy_global_to_session(THD *thd, ulong flag,
1017++ const ulonglong *val)
1018++{
1019++ my_ptrdiff_t offset = ((char *)val - (char *)&global_system_variables);
1020++ if (opt_slow_query_log_use_global_control & (1ULL << flag))
1021++ *(ulonglong *)((char *) &thd->variables + offset) = *val;
1022++}
1023++
1024++
1025+
1026+ void log_slow_statement(THD *thd)
1027+ {
1028+@@ -1443,13 +1499,48 @@
1029+ if (unlikely(thd->in_sub_stmt))
1030+ DBUG_VOID_RETURN; // Don't set time for sub stmt
1031+
1032++ /* Follow the slow log filter configuration. */
1033++ if (thd->variables.log_slow_filter != 0 &&
1034++ (!(thd->variables.log_slow_filter & thd->query_plan_flags) ||
1035++ ((thd->variables.log_slow_filter & SLOG_F_QC_NO) &&
1036++ (thd->query_plan_flags & QPLAN_QC))))
1037++ DBUG_VOID_RETURN;
1038++
1039++ ulonglong end_utime_of_query= thd->current_utime();
1040++ ulonglong query_exec_time= get_query_exec_time(thd, end_utime_of_query);
1041++
1042++ /*
1043++ Low long_query_time value most likely means user is debugging stuff and even
1044++ though some thread's queries are not supposed to be logged b/c of the rate
1045++ limit, if one of them takes long enough (>= 1 second) it will be sensible
1046++ to make an exception and write to slow log anyway.
1047++ */
1048++
1049++ system_variables const &g= global_system_variables;
1050++ copy_global_to_session(thd, SLOG_UG_LOG_SLOW_FILTER,
1051++ &g.log_slow_filter);
1052++ copy_global_to_session(thd, SLOG_UG_LOG_SLOW_RATE_LIMIT,
1053++ &g.log_slow_rate_limit);
1054++ copy_global_to_session(thd, SLOG_UG_LOG_SLOW_VERBOSITY,
1055++ &g.log_slow_verbosity);
1056++ copy_global_to_session(thd, SLOG_UG_LONG_QUERY_TIME,
1057++ &g.long_query_time);
1058++ copy_global_to_session(thd, SLOG_UG_MIN_EXAMINED_ROW_LIMIT,
1059++ &g.min_examined_row_limit);
1060++
1061++ /* Do not log this thread's queries due to rate limiting. */
1062++ if (thd->write_to_slow_log != TRUE
1063++ && (thd->variables.long_query_time >= 1000000
1064++ || (ulong) query_exec_time < 1000000))
1065++ DBUG_VOID_RETURN;
1066++
1067++
1068+ /*
1069+ Do not log administrative statements unless the appropriate option is
1070+ set.
1071+ */
1072+ if (thd->enable_slow_log)
1073+ {
1074+- ulonglong end_utime_of_query= thd->current_utime();
1075+ thd_proc_info(thd, "logging slow query");
1076+
1077+ if (((thd->server_status & SERVER_QUERY_WAS_SLOW) ||
1078+@@ -5301,7 +5392,8 @@
1079+ thd->stmt_da->reset_diagnostics_area();
1080+ thd->warning_info->reset_for_next_command();
1081+ thd->rand_used= 0;
1082+- thd->sent_row_count= thd->examined_row_count= 0;
1083++
1084++ thd->clear_slow_extended();
1085+
1086+ thd->reset_current_stmt_binlog_format_row();
1087+ thd->binlog_unsafe_warning_flags= 0;
1088+--- a/sql/sql_select.cc
1089++++ b/sql/sql_select.cc
1090+@@ -6902,7 +6902,10 @@
1091+ {
1092+ join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
1093+ if (statistics)
1094++ {
1095+ status_var_increment(join->thd->status_var.select_scan_count);
1096++ join->thd->query_plan_flags|= QPLAN_FULL_SCAN;
1097++ }
1098+ }
1099+ }
1100+ else
1101+@@ -6916,7 +6919,10 @@
1102+ {
1103+ join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
1104+ if (statistics)
1105++ {
1106+ status_var_increment(join->thd->status_var.select_full_join_count);
1107++ join->thd->query_plan_flags|= QPLAN_FULL_JOIN;
1108++ }
1109+ }
1110+ }
1111+ if (!table->no_keyread)
1112+@@ -10264,6 +10270,7 @@
1113+ (ulong) rows_limit,test(group)));
1114+
1115+ status_var_increment(thd->status_var.created_tmp_tables);
1116++ thd->query_plan_flags|= QPLAN_TMP_TABLE;
1117+
1118+ if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
1119+ temp_pool_slot = bitmap_lock_set_next(&temp_pool);
1120+@@ -11162,6 +11169,7 @@
1121+ goto err;
1122+ }
1123+ status_var_increment(table->in_use->status_var.created_tmp_disk_tables);
1124++ table->in_use->query_plan_flags|= QPLAN_TMP_DISK;
1125+ share->db_record_offset= 1;
1126+ DBUG_RETURN(0);
1127+ err:
1128+@@ -11180,6 +11188,14 @@
1129+ save_proc_info=thd->proc_info;
1130+ thd_proc_info(thd, "removing tmp table");
1131+
1132++ thd->tmp_tables_used++;
1133++ if (entry->file)
1134++ {
1135++ thd->tmp_tables_size += entry->file->stats.data_file_length;
1136++ if (entry->file->ht->db_type != DB_TYPE_HEAP)
1137++ thd->tmp_tables_disk_used++;
1138++ }
1139++
1140+ // Release latches since this can take a long time
1141+ ha_release_temporary_latches(thd);
1142+
1143+--- a/sql/sql_show.cc
1144++++ b/sql/sql_show.cc
1145+@@ -1950,8 +1950,17 @@
1146+ table->field[4]->store(command_name[tmp->command].str,
1147+ command_name[tmp->command].length, cs);
1148+ /* MYSQL_TIME */
1149+- table->field[5]->store((longlong)(tmp->start_time ?
1150+- now - tmp->start_time : 0), FALSE);
1151++ longlong value_in_time_column= 0;
1152++ if(tmp->start_time)
1153++ {
1154++ value_in_time_column = (now - tmp->start_time);
1155++ if(value_in_time_column > now)
1156++ {
1157++ value_in_time_column= 0;
1158++ }
1159++ }
1160++ table->field[5]->store(value_in_time_column, FALSE);
1161++
1162+ /* STATE */
1163+ if ((val= thread_state_info(tmp)))
1164+ {
1165+--- a/sql/sys_vars.cc
1166++++ b/sql/sys_vars.cc
1167+@@ -972,6 +972,29 @@
1168+ NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1169+ ON_UPDATE(update_cached_long_query_time));
1170+
1171++#ifndef DBUG_OFF
1172++static bool update_cached_query_exec_time(sys_var *self, THD *thd,
1173++ enum_var_type type)
1174++{
1175++ if (type == OPT_SESSION)
1176++ thd->variables.query_exec_time=
1177++ double2ulonglong(thd->variables.query_exec_time_double * 1e6);
1178++ else
1179++ global_system_variables.query_exec_time=
1180++ double2ulonglong(global_system_variables.query_exec_time_double * 1e6);
1181++ return false;
1182++}
1183++
1184++static Sys_var_double Sys_query_exec_time(
1185++ "query_exec_time",
1186++ "Pretend queries take this many seconds. When 0 (the default) use the "
1187++ "actual execution time. Used only for debugging.",
1188++ SESSION_VAR(query_exec_time_double),
1189++ NO_CMD_LINE, VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(0),
1190++ NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
1191++ ON_UPDATE(update_cached_query_exec_time));
1192++#endif
1193++
1194+ static bool fix_low_prio_updates(sys_var *self, THD *thd, enum_var_type type)
1195+ {
1196+ if (type == OPT_SESSION)
1197+@@ -2898,6 +2921,123 @@
1198+ DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1199+ ON_UPDATE(fix_log_state));
1200+
1201++const char *log_slow_filter_name[]= { "qc_miss", "full_scan", "full_join",
1202++ "tmp_table", "tmp_table_on_disk", "filesort", "filesort_on_disk", 0};
1203++static Sys_var_set Sys_log_slow_filter(
1204++ "log_slow_filter",
1205++ "Log only the queries that followed certain execution plan. "
1206++ "Multiple flags allowed in a comma-separated string. "
1207++ "[qc_miss, full_scan, full_join, tmp_table, tmp_table_on_disk, "
1208++ "filesort, filesort_on_disk]",
1209++ SESSION_VAR(log_slow_filter), CMD_LINE(REQUIRED_ARG),
1210++ log_slow_filter_name, DEFAULT(0));
1211++static Sys_var_ulong sys_log_slow_rate_limit(
1212++ "log_slow_rate_limit","Rate limit statement writes to slow log to only those from every (1/log_slow_rate_limit) session.",
1213++ SESSION_VAR(log_slow_rate_limit), CMD_LINE(REQUIRED_ARG),
1214++ VALID_RANGE(1, ULONG_MAX), DEFAULT(1), BLOCK_SIZE(1));
1215++const char* log_slow_verbosity_name[] = {
1216++ "microtime", "query_plan", "innodb",
1217++ "profiling", "profling_use_getrusage",
1218++ "minimal", "standard", "full", 0
1219++};
1220++static ulonglong update_log_slow_verbosity_replace(ulonglong value, ulonglong what, ulonglong by)
1221++{
1222++ if((value & what) == what)
1223++ {
1224++ value = value & (~what);
1225++ value = value | by;
1226++ }
1227++ return value;
1228++}
1229++void update_log_slow_verbosity(ulonglong* value_ptr)
1230++{
1231++ ulonglong &value = *value_ptr;
1232++ ulonglong microtime= ULL(1) << SLOG_V_MICROTIME;
1233++ ulonglong query_plan= ULL(1) << SLOG_V_QUERY_PLAN;
1234++ ulonglong innodb= ULL(1) << SLOG_V_INNODB;
1235++ ulonglong minimal= ULL(1) << SLOG_V_MINIMAL;
1236++ ulonglong standard= ULL(1) << SLOG_V_STANDARD;
1237++ ulonglong full= ULL(1) << SLOG_V_FULL;
1238++ value= update_log_slow_verbosity_replace(value,minimal,microtime);
1239++ value= update_log_slow_verbosity_replace(value,standard,microtime | query_plan);
1240++ value= update_log_slow_verbosity_replace(value,full,microtime | query_plan | innodb);
1241++}
1242++static bool update_log_slow_verbosity_helper(sys_var */*self*/, THD *thd,
1243++ enum_var_type type)
1244++{
1245++ if(type == OPT_SESSION)
1246++ {
1247++ update_log_slow_verbosity(&(thd->variables.log_slow_verbosity));
1248++ }
1249++ else
1250++ {
1251++ update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
1252++ }
1253++ return false;
1254++}
1255++void init_slow_query_log_use_global_control()
1256++{
1257++ update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
1258++}
1259++static Sys_var_set Sys_log_slow_verbosity(
1260++ "log_slow_verbosity",
1261++ "Choose how verbose the messages to your slow log will be. "
1262++ "Multiple flags allowed in a comma-separated string. [microtime, query_plan, innodb, profiling, profiling_use_getrusage]",
1263++ SESSION_VAR(log_slow_verbosity), CMD_LINE(REQUIRED_ARG),
1264++ log_slow_verbosity_name, DEFAULT(SLOG_V_MICROTIME),
1265++ NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1266++ ON_UPDATE(update_log_slow_verbosity_helper));
1267++static Sys_var_mybool Sys_log_slow_slave_statements(
1268++ "log_slow_slave_statements",
1269++ "Log queries replayed be the slave SQL thread",
1270++ GLOBAL_VAR(opt_log_slow_slave_statements), CMD_LINE(OPT_ARG),
1271++ DEFAULT(FALSE));
1272++static Sys_var_mybool Sys_log_slow_admin_statements(
1273++ "log_slow_admin_statements",
1274++ "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements"
1275++ " to the slow log if it is open.",
1276++ GLOBAL_VAR(opt_log_slow_admin_statements), CMD_LINE(OPT_ARG),
1277++ DEFAULT(FALSE));
1278++static Sys_var_mybool Sys_log_slow_sp_statements(
1279++ "log_slow_sp_statements",
1280++ "Log slow statements executed by stored procedure to the slow log if it is open.",
1281++ GLOBAL_VAR(opt_log_slow_sp_statements), CMD_LINE(OPT_ARG),
1282++ DEFAULT(TRUE));
1283++static Sys_var_mybool Sys_slow_query_log_timestamp_always(
1284++ "slow_query_log_timestamp_always",
1285++ "Timestamp is printed for all records of the slow log even if they are same time.",
1286++ GLOBAL_VAR(opt_slow_query_log_timestamp_always), CMD_LINE(OPT_ARG),
1287++ DEFAULT(FALSE));
1288++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};
1289++static bool update_slow_query_log_use_global_control(sys_var */*self*/, THD */*thd*/,
1290++ enum_var_type /*type*/)
1291++{
1292++ if(opt_slow_query_log_use_global_control & (ULL(1) << SLOG_UG_ALL))
1293++ {
1294++ opt_slow_query_log_use_global_control=
1295++ SLOG_UG_LOG_SLOW_FILTER | SLOG_UG_LOG_SLOW_RATE_LIMIT | SLOG_UG_LOG_SLOW_VERBOSITY |
1296++ SLOG_UG_LONG_QUERY_TIME | SLOG_UG_MIN_EXAMINED_ROW_LIMIT;
1297++ }
1298++ return false;
1299++}
1300++void init_log_slow_verbosity()
1301++{
1302++ update_slow_query_log_use_global_control(0,0,OPT_GLOBAL);
1303++}
1304++static Sys_var_set Sys_slow_query_log_use_global_control(
1305++ "slow_query_log_use_global_control",
1306++ "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]",
1307++ GLOBAL_VAR(opt_slow_query_log_use_global_control), CMD_LINE(REQUIRED_ARG),
1308++ slow_query_log_use_global_control_name, DEFAULT(0),
1309++ NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1310++ ON_UPDATE(update_slow_query_log_use_global_control));
1311++const char *slow_query_log_timestamp_precision_name[]= { "second", "microsecond", 0 };
1312++static Sys_var_enum Sys_slow_query_log_timestamp_precision(
1313++ "slow_query_log_timestamp_precision",
1314++ "Log slow statements executed by stored procedure to the slow log if it is open. [second, microsecond]",
1315++ GLOBAL_VAR(opt_slow_query_log_timestamp_precision), CMD_LINE(REQUIRED_ARG),
1316++ slow_query_log_timestamp_precision_name, DEFAULT(SLOG_SECOND));
1317++
1318+ /* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
1319+ static Sys_var_mybool Sys_log_slow(
1320+ "log_slow_queries",
1321+--- a/sql/sql_profile.cc
1322++++ b/sql/sql_profile.cc
1323+@@ -243,7 +243,8 @@
1324+ {
1325+ time_usecs= (double) my_getsystime() / 10.0; /* 1 sec was 1e7, now is 1e6 */
1326+ #ifdef HAVE_GETRUSAGE
1327+- getrusage(RUSAGE_SELF, &rusage);
1328++ if ((profile->get_profiling())->enabled_getrusage())
1329++ getrusage(RUSAGE_SELF, &rusage);
1330+ #elif defined(_WIN32)
1331+ FILETIME ftDummy;
1332+ // NOTE: Get{Process|Thread}Times has a granularity of the clock interval,
1333+@@ -251,6 +252,19 @@
1334+ // measurable by this function.
1335+ GetProcessTimes(GetCurrentProcess(), &ftDummy, &ftDummy, &ftKernel, &ftUser);
1336+ #endif
1337++
1338++#ifdef HAVE_CLOCK_GETTIME
1339++ struct timespec tp;
1340++
1341++ if (!(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
1342++ {
1343++ cpu_time_usecs= tp.tv_sec*1000000000.0 + tp.tv_nsec;
1344++ }
1345++ else
1346++#endif
1347++ {
1348++ cpu_time_usecs= 0;
1349++ }
1350+ }
1351+
1352+
1353+@@ -366,7 +380,8 @@
1354+ finish_current_query();
1355+ }
1356+
1357+- enabled= ((thd->variables.option_bits & OPTION_PROFILING) != 0);
1358++ enabled= ((thd->variables.option_bits & OPTION_PROFILING) != 0) ||
1359++ ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING)) != 0);
1360+
1361+ if (! enabled) DBUG_VOID_RETURN;
1362+
1363+@@ -404,7 +419,8 @@
1364+ status_change("ending", NULL, NULL, 0);
1365+
1366+ if ((enabled) && /* ON at start? */
1367+- ((thd->variables.option_bits & OPTION_PROFILING) != 0) && /* and ON at end? */
1368++ (((thd->variables.option_bits & OPTION_PROFILING) != 0) ||
1369++ ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING)) != 0)) && /* and ON at end? */
1370+ (current->query_source != NULL) &&
1371+ (! current->entries.is_empty()))
1372+ {
1373+@@ -505,6 +521,118 @@
1374+ DBUG_VOID_RETURN;
1375+ }
1376+
1377++bool PROFILING::enabled_getrusage()
1378++{
1379++ return ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING_USE_GETRUSAGE)) != 0);
1380++}
1381++
1382++/**
1383++ For a given profile entry specified by a name and 2 time measurements,
1384++ print its normalized name (i.e. with all spaces replaced with underscores)
1385++ along with its wall clock and CPU time.
1386++*/
1387++
1388++static void my_b_print_status(IO_CACHE *log_file, const char *status,
1389++ PROF_MEASUREMENT *start, PROF_MEASUREMENT *stop)
1390++{
1391++ DBUG_ENTER("my_b_print_status");
1392++ DBUG_ASSERT(log_file != NULL && status != NULL);
1393++ char query_time_buff[22+7];
1394++ const char *tmp;
1395++
1396++ my_b_printf(log_file, "Profile_");
1397++ for (tmp= status; *tmp; tmp++)
1398++ my_b_write_byte(log_file, *tmp == ' ' ? '_' : *tmp);
1399++
1400++ snprintf(query_time_buff, sizeof(query_time_buff), "%.6f",
1401++ (stop->time_usecs - start->time_usecs) / (1000.0 * 1000));
1402++ my_b_printf(log_file, ": %s ", query_time_buff);
1403++
1404++ my_b_printf(log_file, "Profile_");
1405++ for (tmp= status; *tmp; tmp++)
1406++ my_b_write_byte(log_file, *tmp == ' ' ? '_' : *tmp);
1407++ my_b_printf(log_file, "_cpu: ");
1408++
1409++ snprintf(query_time_buff, sizeof(query_time_buff), "%.6f",
1410++ (stop->cpu_time_usecs - start->cpu_time_usecs) /
1411++ (1000.0 * 1000 * 1000));
1412++ my_b_printf(log_file, "%s ", query_time_buff);
1413++
1414++ DBUG_VOID_RETURN;
1415++}
1416++
1417++/**
1418++ Print output for current query to file
1419++*/
1420++
1421++int PROFILING::print_current(IO_CACHE *log_file)
1422++{
1423++ DBUG_ENTER("PROFILING::print_current");
1424++ ulonglong row_number= 0;
1425++
1426++ QUERY_PROFILE *query;
1427++ /* Get current query */
1428++ if (current == NULL)
1429++ {
1430++ DBUG_RETURN(0);
1431++ }
1432++
1433++ query= current;
1434++
1435++ my_b_printf(log_file, "# ");
1436++
1437++ void *entry_iterator;
1438++ PROF_MEASUREMENT *entry= NULL, *previous= NULL, *first= NULL;
1439++ /* ...and for each query, go through all its state-change steps. */
1440++ for (entry_iterator= query->entries.new_iterator();
1441++ entry_iterator != NULL;
1442++ entry_iterator= query->entries.iterator_next(entry_iterator),
1443++ previous=entry, row_number++)
1444++ {
1445++ entry= query->entries.iterator_value(entry_iterator);
1446++
1447++ /* Skip the first. We count spans of fence, not fence-posts. */
1448++ if (previous == NULL) {first= entry; continue;}
1449++
1450++ if (thd->lex->sql_command == SQLCOM_SHOW_PROFILE)
1451++ {
1452++ /*
1453++ We got here via a SHOW command. That means that we stored
1454++ information about the query we wish to show and that isn't
1455++ in a WHERE clause at a higher level to filter out rows we
1456++ wish to exclude.
1457++
1458++ Because that functionality isn't available in the server yet,
1459++ we must filter here, at the wrong level. Once one can con-
1460++ struct where and having conditions at the SQL layer, then this
1461++ condition should be ripped out.
1462++ */
1463++ if (thd->lex->profile_query_id == 0) /* 0 == show final query */
1464++ {
1465++ if (query != last)
1466++ continue;
1467++ }
1468++ else
1469++ {
1470++ if (thd->lex->profile_query_id != query->profiling_query_id)
1471++ continue;
1472++ }
1473++ }
1474++
1475++ my_b_print_status(log_file, previous->status, previous, entry);
1476++ }
1477++
1478++ my_b_write_byte(log_file, '\n');
1479++ if ((entry != NULL) && (first != NULL))
1480++ {
1481++ my_b_printf(log_file, "# ");
1482++ my_b_print_status(log_file, "total", first, entry);
1483++ my_b_write_byte(log_file, '\n');
1484++ }
1485++
1486++ DBUG_RETURN(0);
1487++}
1488++
1489+ /**
1490+ Fill the information schema table, "query_profile", as defined in show.cc .
1491+ There are two ways to get to this function: Selecting from the information
1492+@@ -600,6 +728,8 @@
1493+
1494+ #ifdef HAVE_GETRUSAGE
1495+
1496++ if (enabled_getrusage())
1497++ {
1498+ my_decimal cpu_utime_decimal, cpu_stime_decimal;
1499+
1500+ double2my_decimal(E_DEC_FATAL_ERROR,
1501+@@ -687,6 +817,7 @@
1502+ table->field[14]->store((uint32)(entry->rusage.ru_nswap -
1503+ previous->rusage.ru_nswap), true);
1504+ table->field[14]->set_notnull();
1505++ }
1506+ #else
1507+ /* TODO: Add swap info for non-BSD systems */
1508+ #endif
1509+--- a/sql/sql_profile.h
1510++++ b/sql/sql_profile.h
1511+@@ -164,11 +164,15 @@
1512+ */
1513+ class PROF_MEASUREMENT
1514+ {
1515+-private:
1516+- friend class QUERY_PROFILE;
1517+- friend class PROFILING;
1518+-
1519+ QUERY_PROFILE *profile;
1520++
1521++ char *allocated_status_memory;
1522++
1523++ void set_label(const char *status_arg, const char *function_arg,
1524++ const char *file_arg, unsigned int line_arg);
1525++ void clean_up();
1526++
1527++public:
1528+ char *status;
1529+ #ifdef HAVE_GETRUSAGE
1530+ struct rusage rusage;
1531+@@ -181,12 +185,7 @@
1532+ unsigned int line;
1533+
1534+ double time_usecs;
1535+- char *allocated_status_memory;
1536+-
1537+- void set_label(const char *status_arg, const char *function_arg,
1538+- const char *file_arg, unsigned int line_arg);
1539+- void clean_up();
1540+-
1541++ double cpu_time_usecs;
1542+ PROF_MEASUREMENT();
1543+ PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char *status_arg);
1544+ PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char *status_arg,
1545+@@ -231,6 +230,11 @@
1546+
1547+ /* Show this profile. This is called by PROFILING. */
1548+ bool show(uint options);
1549++
1550++public:
1551++
1552++ inline PROFILING * get_profiling() { return profiling; };
1553++
1554+ };
1555+
1556+
1557+@@ -276,9 +280,11 @@
1558+
1559+ /* SHOW PROFILES */
1560+ bool show_profiles();
1561++ bool enabled_getrusage();
1562+
1563+ /* ... from INFORMATION_SCHEMA.PROFILING ... */
1564+ int fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond);
1565++ int print_current(IO_CACHE *log_file);
1566+ };
1567+
1568+ # endif /* HAVE_PROFILING */
1569+--- /dev/null
1570++++ b/mysql-test/include/log_grep.inc
1571+@@ -0,0 +1,17 @@
1572++--disable_query_log
1573++--echo [log_grep.inc] file: $log_file pattern: $grep_pattern
1574++perl;
1575++ $log_file= $ENV{'log_file'};
1576++ $log_file_full_path= $ENV{'log_file_full_path'};
1577++ $grep_pattern= $ENV{'grep_pattern'};
1578++
1579++ open(FILE, "$log_file_full_path")
1580++ or die("Cannot open file $log_file_full_path: $!\n");
1581++
1582++ $lines = 0;
1583++ while(<FILE>) {
1584++ $lines++ if (/$grep_pattern/);
1585++ }
1586++ close(FILE);
1587++ print "[log_grep.inc] lines: $lines\n";
1588++EOF
1589+--- /dev/null
1590++++ b/mysql-test/include/log_start.inc
1591+@@ -0,0 +1,16 @@
1592++--disable_query_log
1593++--let log_file_full_path = $MYSQLTEST_VARDIR/$log_file
1594++SET @slow_query_log_old=@@slow_query_log;
1595++SET @slow_query_log_file_old= @@slow_query_log_file;
1596++SET GLOBAL slow_query_log=OFF;
1597++perl;
1598++ $log_file_full_path= $ENV{'log_file_full_path'};
1599++ unlink $log_file_full_path;
1600++ open(FILE, '>', $log_file_full_path)
1601++ or die "Cannot create log file $log_file_full_path, reason: $!";
1602++ close(FILE);
1603++EOF
1604++--echo [log_start.inc] $log_file
1605++EVAL SET GLOBAL slow_query_log_file="$log_file_full_path";
1606++SET GLOBAL slow_query_log=ON;
1607++--enable_query_log
1608+\ No newline at end of file
1609+--- /dev/null
1610++++ b/mysql-test/include/log_stop.inc
1611+@@ -0,0 +1,7 @@
1612++--disable_query_log
1613++FLUSH LOGS;
1614++SET GLOBAL slow_query_log=OFF;
1615++--echo [log_stop.inc] $log_file
1616++SET GLOBAL slow_query_log_file= @slow_query_log_file_old;
1617++SET GLOBAL slow_query_log= @slow_query_log_old;
1618++--enable_query_log
1619+--- /dev/null
1620++++ b/mysql-test/r/percona_bug643149.result
1621+@@ -0,0 +1,21 @@
1622++SET @old_slow_query_log_file=@@global.slow_query_log_file;
1623++SET GLOBAL slow_query_log=on;
1624++SET LOCAL log_slow_verbosity='profiling';
1625++SET LOCAL long_query_time=0;
1626++SET GLOBAL slow_query_log_file='MYSQLTEST_VARDIR/percona_bug643149_slow.log';;
1627++SELECT 1;
1628++1
1629++1
1630++# User@Host: root[root] @ localhost []
1631++# Thread_id: X Schema: test Last_errno: X Killed: X
1632++# Query_time: X.X Lock_time: X.X Rows_sent: X Rows_examined: X Rows_affected: X Rows_read: X
1633++# Bytes_sent: X Tmp_tables: X Tmp_disk_tables: X Tmp_table_sizes: X
1634++# 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
1635++# Profile_total: X.X Profile_total_cpu: X.X
1636++# User@Host: root[root] @ localhost []
1637++# Thread_id: X Schema: test Last_errno: X Killed: X
1638++# Query_time: X.X Lock_time: X.X Rows_sent: X Rows_examined: X Rows_affected: X Rows_read: X
1639++# Bytes_sent: X Tmp_tables: X Tmp_disk_tables: X Tmp_table_sizes: X
1640++# 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
1641++# Profile_total: X.X Profile_total_cpu: X.X
1642++SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
1643+--- /dev/null
1644++++ b/mysql-test/r/percona_log_slow_filter-cl.result
1645+@@ -0,0 +1,6 @@
1646++SHOW VARIABLES LIKE 'log_slow_filter';
1647++Variable_name Value
1648++log_slow_filter full_join
1649++SHOW GLOBAL VARIABLES LIKE 'log_slow_filter';
1650++Variable_name Value
1651++log_slow_filter full_join
1652+--- /dev/null
1653++++ b/mysql-test/r/percona_log_slow_filter.result
1654+@@ -0,0 +1,15 @@
1655++CREATE TABLE t(id INT PRIMARY KEY);
1656++INSERT INTO t VALUES(1);
1657++INSERT INTO t VALUES(2);
1658++INSERT INTO t VALUES(3);
1659++SET long_query_time=1;
1660++SET log_slow_filter=full_join;
1661++[log_start.inc] percona.slow_extended.log_slow_filter
1662++SET query_exec_time = 1.1;
1663++SELECT * FROM t AS t1, t AS t2;
1664++SET query_exec_time = default;
1665++[log_stop.inc] percona.slow_extended.log_slow_filter
1666++SET log_slow_filter=default;
1667++SET long_query_time=default;
1668++[log_grep.inc] file: percona.slow_extended.log_slow_filter pattern: Query_time
1669++[log_grep.inc] lines: 1
1670+--- /dev/null
1671++++ b/mysql-test/r/percona_log_slow_slave_statements-cl.result
1672+@@ -0,0 +1,6 @@
1673++SHOW VARIABLES LIKE 'log_slow_slave_statements';
1674++Variable_name Value
1675++log_slow_slave_statements ON
1676++SHOW GLOBAL VARIABLES LIKE 'log_slow_slave_statements';
1677++Variable_name Value
1678++log_slow_slave_statements ON
1679+--- /dev/null
1680++++ b/mysql-test/r/percona_log_slow_slave_statements-innodb.result
1681+@@ -0,0 +1,18 @@
1682++include/master-slave.inc
1683++[connection master]
1684++DROP TABLE IF EXISTS t;
1685++CREATE TABLE t(id INT,data CHAR(30)) ENGINE=InnoDB;
1686++INSERT INTO t VALUES
1687++(1,"aaaaabbbbbcccccdddddeeeeefffff"),
1688++(2,"aaaaabbbbbcccccdddddeeeeefffff"),
1689++(3,"aaaaabbbbbcccccdddddeeeeefffff"),
1690++(4,"aaaaabbbbbcccccdddddeeeeefffff"),
1691++(5,"aaaaabbbbbcccccdddddeeeeefffff");
1692++INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
1693++INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
1694++[log_start.inc] percona.slow_extended.log_slow_slave_statements-innodb
1695++INSERT INTO t SELECT t.id,t.data from t;
1696++[log_stop.inc] percona.slow_extended.log_slow_slave_statements-innodb
1697++[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements-innodb pattern: InnoDB_IO_r_ops
1698++[log_grep.inc] lines: 1
1699++include/rpl_end.inc
1700+--- /dev/null
1701++++ b/mysql-test/r/percona_log_slow_slave_statements.result
1702+@@ -0,0 +1,44 @@
1703++include/master-slave.inc
1704++[connection master]
1705++DROP TABLE IF EXISTS t;
1706++CREATE TABLE t(id INT);
1707++[log_start.inc] percona.slow_extended.log_slow_slave_statements
1708++LINE 1
1709++LOG_SLOW_SLAVE_STATAMENTS is OFF
1710++LOG_SLOW_SLAVE_STATEMENTS=ON
1711++LOG_SLOW_SLAVE_STATAMENTS is ON
1712++LINE 2
1713++include/restart_slave.inc
1714++LOG_SLOW_SLAVE_STATAMENTS is ON
1715++LINE 3
1716++LOG_SLOW_SLAVE_STATAMENTS is ON
1717++LOG_SLOW_SLAVE_STATEMENTS=OFF
1718++LOG_SLOW_SLAVE_STATAMENTS is OFF
1719++LINE 4
1720++include/restart_slave.inc
1721++LOG_SLOW_SLAVE_STATAMENTS is OFF
1722++LINE 5
1723++LOG_SLOW_SLAVE_STATAMENTS is OFF
1724++LOG_SLOW_SLAVE_STATEMENTS=ON
1725++LOG_SLOW_SLAVE_STATAMENTS is ON
1726++LINE 6
1727++include/restart_slave.inc
1728++LOG_SLOW_SLAVE_STATAMENTS is ON
1729++LINE 7
1730++[log_stop.inc] percona.slow_extended.log_slow_slave_statements
1731++SET GLOBAL log_slow_slave_statements=default;
1732++[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(1\)
1733++[log_grep.inc] lines: 0
1734++[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(2\)
1735++[log_grep.inc] lines: 0
1736++[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(3\)
1737++[log_grep.inc] lines: 1
1738++[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(4\)
1739++[log_grep.inc] lines: 0
1740++[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(5\)
1741++[log_grep.inc] lines: 0
1742++[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(6\)
1743++[log_grep.inc] lines: 0
1744++[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(7\)
1745++[log_grep.inc] lines: 1
1746++include/rpl_end.inc
1747+--- /dev/null
1748++++ b/mysql-test/r/percona_log_slow_sp_statements-cl.result
1749+@@ -0,0 +1,6 @@
1750++SHOW VARIABLES LIKE 'log_slow_sp_statements';
1751++Variable_name Value
1752++log_slow_sp_statements ON
1753++SHOW GLOBAL VARIABLES LIKE 'log_slow_sp_statements';
1754++Variable_name Value
1755++log_slow_sp_statements ON
1756+--- /dev/null
1757++++ b/mysql-test/r/percona_log_slow_sp_statements.result
1758+@@ -0,0 +1,24 @@
1759++SET long_query_time=1;
1760++SET GLOBAL log_slow_sp_statements=ON;
1761++SET SESSION query_exec_time=0.1;
1762++[log_start.inc] percona.slow_extended.log_slow_sp_statements
1763++CREATE PROCEDURE test_f()
1764++BEGIN
1765++SET SESSION query_exec_time=1.1; SELECT 1;
1766++SET SESSION query_exec_time=2.1; SELECT 1;
1767++SET SESSION query_exec_time=3.1; SELECT 1;
1768++SET SESSION query_exec_time=0.1;
1769++END^
1770++CALL test_f();
1771++1
1772++1
1773++1
1774++1
1775++1
1776++1
1777++[log_stop.inc] percona.slow_extended.log_slow_sp_statements
1778++SET SESSION query_exec_time=default;
1779++SET GLOBAL log_slow_sp_statements=default;
1780++SET long_query_time=default;
1781++[log_grep.inc] file: percona.slow_extended.log_slow_sp_statements pattern: Query_time
1782++[log_grep.inc] lines: 3
1783+--- /dev/null
1784++++ b/mysql-test/r/percona_log_slow_verbosity-cl.result
1785+@@ -0,0 +1,6 @@
1786++SHOW VARIABLES LIKE 'log_slow_verbosity';
1787++Variable_name Value
1788++log_slow_verbosity microtime,query_plan,innodb
1789++SHOW GLOBAL VARIABLES LIKE 'log_slow_verbosity';
1790++Variable_name Value
1791++log_slow_verbosity microtime,query_plan,innodb
1792+--- /dev/null
1793++++ b/mysql-test/r/percona_log_slow_verbosity.result
1794+@@ -0,0 +1,16 @@
1795++SET SESSION long_query_time=1;
1796++[log_start.inc] percona.slow_extended.log_slow_verbosity
1797++SET SESSION query_exec_time=2.1;
1798++SELECT 1;
1799++1
1800++1
1801++SET SESSION log_slow_verbosity=innodb;
1802++SELECT 1;
1803++1
1804++1
1805++SET SESSION query_exec_time=default;
1806++[log_stop.inc] percona.slow_extended.log_slow_verbosity
1807++SET log_slow_verbosity=default;
1808++SET long_query_time=default;
1809++[log_grep.inc] file: percona.slow_extended.log_slow_verbosity pattern: No InnoDB statistics available for this query
1810++[log_grep.inc] lines: 1
1811+--- /dev/null
1812++++ b/mysql-test/r/percona_long_query_time.result
1813+@@ -0,0 +1,33 @@
1814++SET long_query_time=2;
1815++[log_start.inc] percona.slow_extended.long_query_time
1816++SET SESSION query_exec_time=1.1;
1817++SELECT 1;
1818++1
1819++1
1820++SET SESSION query_exec_time=3.1;
1821++SELECT 1;
1822++1
1823++1
1824++SET SESSION query_exec_time=5.1;
1825++SELECT 1;
1826++1
1827++1
1828++SET long_query_time=4;
1829++SET SESSION query_exec_time=1.1;
1830++SELECT 1;
1831++1
1832++1
1833++SET SESSION query_exec_time=3.1;
1834++SELECT 1;
1835++1
1836++1
1837++SET SESSION query_exec_time=5.1;
1838++SELECT 1;
1839++1
1840++1
1841++SET SESSION query_exec_time=default;
1842++SET long_query_time=2;
1843++[log_stop.inc] percona.slow_extended.long_query_time
1844++SET long_query_time=default;
1845++[log_grep.inc] file: percona.slow_extended.long_query_time pattern: Query_time
1846++[log_grep.inc] lines: 3
1847+--- /dev/null
1848++++ b/mysql-test/r/percona_slow_query_log_timestamp_always-cl.result
1849+@@ -0,0 +1,6 @@
1850++SHOW VARIABLES LIKE 'slow_query_log_timestamp_always';
1851++Variable_name Value
1852++slow_query_log_timestamp_always ON
1853++SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_always';
1854++Variable_name Value
1855++slow_query_log_timestamp_always ON
1856+--- /dev/null
1857++++ b/mysql-test/r/percona_slow_query_log_timestamp_always.result
1858+@@ -0,0 +1,41 @@
1859++SET long_query_time=2;
1860++SET GLOBAL slow_query_log_timestamp_always=ON;
1861++[log_start.inc] percona.slow_extended.slow_query_log_timestamp_always
1862++SET SESSION query_exec_time=2.1;
1863++SELECT 1;
1864++1
1865++1
1866++SELECT 1;
1867++1
1868++1
1869++SELECT 1;
1870++1
1871++1
1872++SET GLOBAL slow_query_log_timestamp_always=OFF;
1873++SET SESSION query_exec_time=2.1;
1874++SELECT 1;
1875++1
1876++1
1877++SELECT 1;
1878++1
1879++1
1880++SELECT 1;
1881++1
1882++1
1883++SET GLOBAL slow_query_log_timestamp_always=ON;
1884++SET SESSION query_exec_time=2.1;
1885++SELECT 1;
1886++1
1887++1
1888++SELECT 1;
1889++1
1890++1
1891++SELECT 1;
1892++1
1893++1
1894++SET SESSION query_exec_time=default;
1895++[log_stop.inc] percona.slow_extended.slow_query_log_timestamp_always
1896++SET GLOBAL slow_query_log_timestamp_always=default;
1897++SET long_query_time=default;
1898++[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_always pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
1899++[log_grep.inc] lines: 6
1900+--- /dev/null
1901++++ b/mysql-test/r/percona_slow_query_log_timestamp_precision-cl.result
1902+@@ -0,0 +1,6 @@
1903++SHOW VARIABLES LIKE 'slow_query_log_timestamp_precision';
1904++Variable_name Value
1905++slow_query_log_timestamp_precision microsecond
1906++SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_precision';
1907++Variable_name Value
1908++slow_query_log_timestamp_precision microsecond
1909+--- /dev/null
1910++++ b/mysql-test/r/percona_slow_query_log_timestamp_precision.result
1911+@@ -0,0 +1,18 @@
1912++SET long_query_time=2;
1913++[log_start.inc] percona.slow_extended.slow_query_log_timestamp_precision
1914++SET SESSION query_exec_time=2.1;
1915++SELECT 1;
1916++1
1917++1
1918++SET GLOBAL slow_query_log_timestamp_precision='microsecond';
1919++SELECT 1;
1920++1
1921++1
1922++SET SESSION query_exec_time=default;
1923++[log_stop.inc] percona.slow_extended.slow_query_log_timestamp_precision
1924++SET GLOBAL slow_query_log_timestamp_precision=default;
1925++SET long_query_time=default;
1926++[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_precision pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+.[0-9]+
1927++[log_grep.inc] lines: 1
1928++[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_precision pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
1929++[log_grep.inc] lines: 2
1930+--- /dev/null
1931++++ b/mysql-test/r/percona_slow_query_log_use_global_control.result
1932+@@ -0,0 +1,18 @@
1933++SET GLOBAL long_query_time=1;
1934++[log_start.inc] percona.slow_extended.slow_query_log_use_global_control
1935++SET SESSION query_exec_time=1.1;
1936++SELECT 1;
1937++1
1938++1
1939++SET GLOBAL log_slow_verbosity=innodb;
1940++SET GLOBAL slow_query_log_use_global_control="log_slow_verbosity,long_query_time";
1941++SELECT 1;
1942++1
1943++1
1944++SET SESSION query_exec_time=default;
1945++[log_stop.inc] percona.slow_extended.slow_query_log_use_global_control
1946++SET GLOBAL slow_query_log_use_global_control=default;
1947++SET GLOBAL log_slow_verbosity=default;
1948++SET GLOBAL long_query_time=default;
1949++[log_grep.inc] file: percona.slow_extended.slow_query_log_use_global_control pattern: No InnoDB statistics available for this query
1950++[log_grep.inc] lines: 1
1951+--- /dev/null
1952++++ b/mysql-test/t/percona_bug643149.test
1953+@@ -0,0 +1,49 @@
1954++#
1955++# This test suffers from server
1956++# Bug#38124 "general_log_file" variable silently unset when using expression
1957++# In short:
1958++# SET GLOBAL general_log_file = @<whatever>
1959++# SET GLOBAL slow_query_log = @<whatever>
1960++# cause that the value of these server system variables is set to default
1961++# instead of the assigned values. There comes no error message or warning.
1962++# If this bug is fixed please
1963++# 1. try this test with "let $fixed_bug38124 = 0;"
1964++# 2. remove all workarounds if 1. was successful.
1965++--source include/have_profiling.inc
1966++let $fixed_bug38124 = 0;
1967++
1968++SET @old_slow_query_log_file=@@global.slow_query_log_file;
1969++SET GLOBAL slow_query_log=on;
1970++SET LOCAL log_slow_verbosity='profiling';
1971++SET LOCAL long_query_time=0;
1972++
1973++let slogfile=$MYSQLTEST_VARDIR/percona_bug643149_slow.log;
1974++--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1975++--eval SET GLOBAL slow_query_log_file='$slogfile';
1976++
1977++SELECT 1;
1978++
1979++perl;
1980++ $slogfile= $ENV{'slogfile'};
1981++
1982++ open(FILE, "$slogfile") or
1983++ die("Unable to read slow query log file $slogfile: $!\n");
1984++ while(<FILE>) {
1985++ next if (!/^#/);
1986++ next if (/^# Time:/);
1987++ s/[0-9]+/X/g;
1988++ print;
1989++ }
1990++
1991++ close(FILE);
1992++EOF
1993++
1994++SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
1995++
1996++if(!$fixed_bug38124)
1997++{
1998++ --disable_query_log
1999++ let $my_var = `SELECT @old_slow_query_log_file`;
2000++ eval SET @@global.slow_query_log_file = '$my_var';
2001++ --enable_query_log
2002++}
2003+--- /dev/null
2004++++ b/mysql-test/t/percona_log_slow_filter-cl-master.opt
2005+@@ -0,0 +1 @@
2006++--log_slow_filter=full_join
2007+--- /dev/null
2008++++ b/mysql-test/t/percona_log_slow_filter-cl.test
2009+@@ -0,0 +1,2 @@
2010++SHOW VARIABLES LIKE 'log_slow_filter';
2011++SHOW GLOBAL VARIABLES LIKE 'log_slow_filter';
2012+--- /dev/null
2013++++ b/mysql-test/t/percona_log_slow_filter.test
2014+@@ -0,0 +1,26 @@
2015++--source include/have_debug.inc
2016++
2017++CREATE TABLE t(id INT PRIMARY KEY);
2018++INSERT INTO t VALUES(1);
2019++INSERT INTO t VALUES(2);
2020++INSERT INTO t VALUES(3);
2021++
2022++SET long_query_time=1;
2023++SET log_slow_filter=full_join;
2024++--let log_file=percona.slow_extended.log_slow_filter
2025++--source include/log_start.inc
2026++
2027++SET query_exec_time = 1.1;
2028++--disable_result_log
2029++SELECT * FROM t AS t1, t AS t2;
2030++--enable_result_log
2031++SET query_exec_time = default;
2032++
2033++--source include/log_stop.inc
2034++SET log_slow_filter=default;
2035++SET long_query_time=default;
2036++
2037++--let grep_pattern = Query_time
2038++--source include/log_grep.inc
2039++
2040++DROP TABLE t;
2041+--- /dev/null
2042++++ b/mysql-test/t/percona_log_slow_slave_statements-cl-master.opt
2043+@@ -0,0 +1 @@
2044++--log_slow_slave_statements
2045+\ No newline at end of file
2046+--- /dev/null
2047++++ b/mysql-test/t/percona_log_slow_slave_statements-cl.test
2048+@@ -0,0 +1,3 @@
2049++SHOW VARIABLES LIKE 'log_slow_slave_statements';
2050++SHOW GLOBAL VARIABLES LIKE 'log_slow_slave_statements';
2051++
2052+--- /dev/null
2053++++ b/mysql-test/t/percona_log_slow_slave_statements-innodb-slave.opt
2054+@@ -0,0 +1 @@
2055++--long_query_time=0 --log_slow_slave_statements --log_slow_verbosity=innodb
2056+\ No newline at end of file
2057+--- /dev/null
2058++++ b/mysql-test/t/percona_log_slow_slave_statements-innodb.test
2059+@@ -0,0 +1,42 @@
2060++--source include/have_binlog_format_statement.inc
2061++--source include/master-slave.inc
2062++--source include/have_innodb.inc
2063++--let log_file=percona.slow_extended.log_slow_slave_statements-innodb
2064++
2065++connection master;
2066++-- disable_warnings
2067++DROP TABLE IF EXISTS t;
2068++-- enable_warnings
2069++
2070++CREATE TABLE t(id INT,data CHAR(30)) ENGINE=InnoDB;
2071++INSERT INTO t VALUES
2072++(1,"aaaaabbbbbcccccdddddeeeeefffff"),
2073++(2,"aaaaabbbbbcccccdddddeeeeefffff"),
2074++(3,"aaaaabbbbbcccccdddddeeeeefffff"),
2075++(4,"aaaaabbbbbcccccdddddeeeeefffff"),
2076++(5,"aaaaabbbbbcccccdddddeeeeefffff");
2077++INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
2078++INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
2079++sync_slave_with_master;
2080++
2081++connection slave;
2082++--source include/log_start.inc
2083++
2084++connection master;
2085++INSERT INTO t SELECT t.id,t.data from t;
2086++sync_slave_with_master;
2087++
2088++connection slave;
2089++--source include/log_stop.inc
2090++
2091++--enable_query_log
2092++--enable_result_log
2093++
2094++--let grep_pattern = InnoDB_IO_r_ops
2095++--source include/log_grep.inc
2096++
2097++connection master;
2098++DROP TABLE t;
2099++sync_slave_with_master;
2100++
2101++--source include/rpl_end.inc
2102+--- /dev/null
2103++++ b/mysql-test/t/percona_log_slow_slave_statements-slave.opt
2104+@@ -0,0 +1 @@
2105++--long_query_time=0
2106+\ No newline at end of file
2107+--- /dev/null
2108++++ b/mysql-test/t/percona_log_slow_slave_statements.test
2109+@@ -0,0 +1,117 @@
2110++-- source include/have_binlog_format_statement.inc
2111++-- source include/master-slave.inc
2112++--let log_file=percona.slow_extended.log_slow_slave_statements
2113++--let show=SELECT Variable_value FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE Variable_name LIKE 'log_slow_slave_statements';
2114++
2115++connection master;
2116++-- disable_warnings
2117++DROP TABLE IF EXISTS t;
2118++-- enable_warnings
2119++
2120++CREATE TABLE t(id INT);
2121++sync_slave_with_master;
2122++
2123++connection slave;
2124++--source include/log_start.inc
2125++
2126++--disable_query_log
2127++--disable_result_log
2128++
2129++--echo LINE 1
2130++connection master;
2131++INSERT INTO t VALUES (1);
2132++sync_slave_with_master;
2133++
2134++connection slave;
2135++--let value=`$show`
2136++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2137++--echo LOG_SLOW_SLAVE_STATEMENTS=ON
2138++SET GLOBAL log_slow_slave_statements=ON;
2139++--let value=`$show`
2140++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2141++
2142++--echo LINE 2
2143++connection master;
2144++INSERT INTO t VALUES (2);
2145++sync_slave_with_master;
2146++
2147++--source include/restart_slave_sql.inc
2148++
2149++connection slave;
2150++--let value=`$show`
2151++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2152++
2153++--echo LINE 3
2154++connection master;
2155++INSERT INTO t VALUES (3);
2156++sync_slave_with_master;
2157++
2158++connection slave;
2159++--let value=`$show`
2160++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2161++--echo LOG_SLOW_SLAVE_STATEMENTS=OFF
2162++SET GLOBAL log_slow_slave_statements=OFF;
2163++--let value=`$show`
2164++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2165++
2166++--echo LINE 4
2167++connection master;
2168++INSERT INTO t VALUES (4);
2169++sync_slave_with_master;
2170++
2171++--source include/restart_slave_sql.inc
2172++
2173++connection slave;
2174++--let value=`$show`
2175++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2176++
2177++--echo LINE 5
2178++connection master;
2179++INSERT INTO t VALUES (5);
2180++sync_slave_with_master;
2181++
2182++connection slave;
2183++--let value=`$show`
2184++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2185++--echo LOG_SLOW_SLAVE_STATEMENTS=ON
2186++SET GLOBAL log_slow_slave_statements=ON;
2187++--let value=`$show`
2188++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2189++
2190++--echo LINE 6
2191++connection master;
2192++INSERT INTO t VALUES (6);
2193++sync_slave_with_master;
2194++
2195++--source include/restart_slave_sql.inc
2196++
2197++connection slave;
2198++--let value=`$show`
2199++--echo LOG_SLOW_SLAVE_STATAMENTS is $value
2200++
2201++--echo LINE 7
2202++connection master;
2203++INSERT INTO t VALUES (7);
2204++sync_slave_with_master;
2205++
2206++--enable_query_log
2207++--enable_result_log
2208++
2209++connection slave;
2210++--source include/log_stop.inc
2211++SET GLOBAL log_slow_slave_statements=default;
2212++
2213++connection slave;
2214++--let i=1
2215++while($i < 8)
2216++{
2217++--let grep_pattern= INSERT INTO t VALUES \($i\)
2218++--source include/log_grep.inc
2219++ inc $i;
2220++}
2221++
2222++connection master;
2223++DROP TABLE t;
2224++sync_slave_with_master;
2225++
2226++--source include/rpl_end.inc
2227+--- /dev/null
2228++++ b/mysql-test/t/percona_log_slow_sp_statements-cl-master.opt
2229+@@ -0,0 +1 @@
2230++--log_slow_sp_statements
2231+--- /dev/null
2232++++ b/mysql-test/t/percona_log_slow_sp_statements-cl.test
2233+@@ -0,0 +1,2 @@
2234++SHOW VARIABLES LIKE 'log_slow_sp_statements';
2235++SHOW GLOBAL VARIABLES LIKE 'log_slow_sp_statements';
2236+--- /dev/null
2237++++ b/mysql-test/t/percona_log_slow_sp_statements.test
2238+@@ -0,0 +1,29 @@
2239++--source include/have_debug.inc
2240++
2241++SET long_query_time=1;
2242++SET GLOBAL log_slow_sp_statements=ON;
2243++SET SESSION query_exec_time=0.1;
2244++--let log_file=percona.slow_extended.log_slow_sp_statements
2245++--source include/log_start.inc
2246++
2247++delimiter ^;
2248++CREATE PROCEDURE test_f()
2249++BEGIN
2250++ SET SESSION query_exec_time=1.1; SELECT 1;
2251++ SET SESSION query_exec_time=2.1; SELECT 1;
2252++ SET SESSION query_exec_time=3.1; SELECT 1;
2253++ SET SESSION query_exec_time=0.1;
2254++END^
2255++delimiter ;^
2256++
2257++CALL test_f();
2258++
2259++--source include/log_stop.inc
2260++SET SESSION query_exec_time=default;
2261++SET GLOBAL log_slow_sp_statements=default;
2262++SET long_query_time=default;
2263++
2264++--let grep_pattern = Query_time
2265++--source include/log_grep.inc
2266++
2267++DROP PROCEDURE test_f;
2268+--- /dev/null
2269++++ b/mysql-test/t/percona_log_slow_verbosity-cl-master.opt
2270+@@ -0,0 +1 @@
2271++--log_slow_verbosity="full"
2272+--- /dev/null
2273++++ b/mysql-test/t/percona_log_slow_verbosity-cl.test
2274+@@ -0,0 +1,2 @@
2275++SHOW VARIABLES LIKE 'log_slow_verbosity';
2276++SHOW GLOBAL VARIABLES LIKE 'log_slow_verbosity';
2277+--- /dev/null
2278++++ b/mysql-test/t/percona_log_slow_verbosity.test
2279+@@ -0,0 +1,19 @@
2280++--source include/have_innodb.inc
2281++--source include/have_debug.inc
2282++
2283++SET SESSION long_query_time=1;
2284++--let log_file=percona.slow_extended.log_slow_verbosity
2285++--source include/log_start.inc
2286++
2287++SET SESSION query_exec_time=2.1;
2288++SELECT 1;
2289++SET SESSION log_slow_verbosity=innodb;
2290++SELECT 1;
2291++SET SESSION query_exec_time=default;
2292++
2293++--source include/log_stop.inc
2294++SET log_slow_verbosity=default;
2295++SET long_query_time=default;
2296++
2297++--let grep_pattern = No InnoDB statistics available for this query
2298++--source include/log_grep.inc
2299+--- /dev/null
2300++++ b/mysql-test/t/percona_long_query_time.test
2301+@@ -0,0 +1,25 @@
2302++--source include/have_debug.inc
2303++
2304++SET long_query_time=2;
2305++--let log_file=percona.slow_extended.long_query_time
2306++--source include/log_start.inc
2307++
2308++SET SESSION query_exec_time=1.1; SELECT 1;
2309++SET SESSION query_exec_time=3.1; SELECT 1;
2310++SET SESSION query_exec_time=5.1; SELECT 1;
2311++
2312++SET long_query_time=4;
2313++
2314++SET SESSION query_exec_time=1.1; SELECT 1;
2315++SET SESSION query_exec_time=3.1; SELECT 1;
2316++SET SESSION query_exec_time=5.1; SELECT 1;
2317++
2318++SET SESSION query_exec_time=default;
2319++
2320++SET long_query_time=2;
2321++
2322++--source include/log_stop.inc
2323++SET long_query_time=default;
2324++
2325++--let grep_pattern = Query_time
2326++--source include/log_grep.inc
2327+--- /dev/null
2328++++ b/mysql-test/t/percona_slow_query_log_timestamp_always-cl-master.opt
2329+@@ -0,0 +1 @@
2330++--slow_query_log_timestamp_always
2331+\ No newline at end of file
2332+--- /dev/null
2333++++ b/mysql-test/t/percona_slow_query_log_timestamp_always-cl.test
2334+@@ -0,0 +1,2 @@
2335++SHOW VARIABLES LIKE 'slow_query_log_timestamp_always';
2336++SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_always';
2337+--- /dev/null
2338++++ b/mysql-test/t/percona_slow_query_log_timestamp_always.test
2339+@@ -0,0 +1,34 @@
2340++--source include/have_debug.inc
2341++
2342++SET long_query_time=2;
2343++SET GLOBAL slow_query_log_timestamp_always=ON;
2344++--let log_file=percona.slow_extended.slow_query_log_timestamp_always
2345++--source include/log_start.inc
2346++
2347++SET SESSION query_exec_time=2.1;
2348++SELECT 1;
2349++SELECT 1;
2350++SELECT 1;
2351++
2352++SET GLOBAL slow_query_log_timestamp_always=OFF;
2353++
2354++SET SESSION query_exec_time=2.1;
2355++SELECT 1;
2356++SELECT 1;
2357++SELECT 1;
2358++
2359++SET GLOBAL slow_query_log_timestamp_always=ON;
2360++
2361++SET SESSION query_exec_time=2.1;
2362++SELECT 1;
2363++SELECT 1;
2364++SELECT 1;
2365++
2366++SET SESSION query_exec_time=default;
2367++
2368++--source include/log_stop.inc
2369++SET GLOBAL slow_query_log_timestamp_always=default;
2370++SET long_query_time=default;
2371++
2372++--let grep_pattern = # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
2373++--source include/log_grep.inc
2374+--- /dev/null
2375++++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-cl-master.opt
2376+@@ -0,0 +1 @@
2377++--slow_query_log_timestamp_precision='microsecond'
2378+\ No newline at end of file
2379+--- /dev/null
2380++++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-cl.test
2381+@@ -0,0 +1,2 @@
2382++SHOW VARIABLES LIKE 'slow_query_log_timestamp_precision';
2383++SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_precision';
2384+--- /dev/null
2385++++ b/mysql-test/t/percona_slow_query_log_timestamp_precision-master.opt
2386+@@ -0,0 +1 @@
2387++--slow_query_log_timestamp_always
2388+\ No newline at end of file
2389+--- /dev/null
2390++++ b/mysql-test/t/percona_slow_query_log_timestamp_precision.test
2391+@@ -0,0 +1,25 @@
2392++--source include/have_debug.inc
2393++
2394++SET long_query_time=2;
2395++--let log_file=percona.slow_extended.slow_query_log_timestamp_precision
2396++--source include/log_start.inc
2397++
2398++SET SESSION query_exec_time=2.1;
2399++
2400++SELECT 1;
2401++
2402++SET GLOBAL slow_query_log_timestamp_precision='microsecond';
2403++
2404++SELECT 1;
2405++
2406++SET SESSION query_exec_time=default;
2407++
2408++--source include/log_stop.inc
2409++SET GLOBAL slow_query_log_timestamp_precision=default;
2410++SET long_query_time=default;
2411++
2412++--let grep_pattern = # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+.[0-9]+
2413++--source include/log_grep.inc
2414++
2415++--let grep_pattern = # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
2416++--source include/log_grep.inc
2417+--- /dev/null
2418++++ b/mysql-test/t/percona_slow_query_log_use_global_control.test
2419+@@ -0,0 +1,28 @@
2420++--source include/have_debug.inc
2421++--source include/have_innodb.inc
2422++
2423++SET GLOBAL long_query_time=1;
2424++
2425++--let log_file=percona.slow_extended.slow_query_log_use_global_control
2426++--source include/log_start.inc
2427++
2428++SET SESSION query_exec_time=1.1;
2429++SELECT 1;
2430++
2431++SET GLOBAL log_slow_verbosity=innodb;
2432++SET GLOBAL slow_query_log_use_global_control="log_slow_verbosity,long_query_time";
2433++
2434++SELECT 1;
2435++
2436++SET SESSION query_exec_time=default;
2437++
2438++--source include/log_stop.inc
2439++
2440++
2441++SET GLOBAL slow_query_log_use_global_control=default;
2442++SET GLOBAL log_slow_verbosity=default;
2443++SET GLOBAL long_query_time=default;
2444++
2445++--let grep_pattern = No InnoDB statistics available for this query
2446++--source include/log_grep.inc
2447++
2448+--- /dev/null
2449++++ b/mysql-test/r/percona_slow_query_log_use_global_control-cl.result
2450+@@ -0,0 +1,6 @@
2451++SHOW VARIABLES LIKE 'slow_query_log_use_global_control';
2452++Variable_name Value
2453++slow_query_log_use_global_control log_slow_verbosity,long_query_time
2454++SHOW GLOBAL VARIABLES LIKE 'slow_query_log_use_global_control';
2455++Variable_name Value
2456++slow_query_log_use_global_control log_slow_verbosity,long_query_time
2457+--- /dev/null
2458++++ b/mysql-test/t/percona_slow_query_log_use_global_control-cl-master.opt
2459+@@ -0,0 +1 @@
2460++--slow_query_log_use_global_control="log_slow_verbosity,long_query_time"
2461+--- /dev/null
2462++++ b/mysql-test/t/percona_slow_query_log_use_global_control-cl.test
2463+@@ -0,0 +1,2 @@
2464++SHOW VARIABLES LIKE 'slow_query_log_use_global_control';
2465++SHOW GLOBAL VARIABLES LIKE 'slow_query_log_use_global_control';
2466+--- /dev/null
2467++++ b/mysql-test/r/percona_min_examined_row_limit.result
2468+@@ -0,0 +1,34 @@
2469++drop table if exists t;
2470++create table t(id INT PRIMARY KEY);
2471++insert into t values(1);
2472++insert into t values(2);
2473++insert into t values(3);
2474++SET GLOBAL long_query_time=2;
2475++SET GLOBAL slow_query_log_use_global_control='long_query_time,min_examined_row_limit';
2476++[log_start.inc] percona.slow_extended.min_examined_row_limit
2477++SET SESSION query_exec_time=2.1;
2478++SELECT 1;
2479++1
2480++1
2481++SET GLOBAL min_examined_row_limit=5;
2482++select * from t as t1, t as t2;
2483++id id
2484++1 1
2485++2 1
2486++3 1
2487++1 2
2488++2 2
2489++3 2
2490++1 3
2491++2 3
2492++3 3
2493++SELECT 1;
2494++1
2495++1
2496++SET SESSION query_exec_time=default;
2497++[log_stop.inc] percona.slow_extended.min_examined_row_limit
2498++SET GLOBAL min_examined_row_limit=default;
2499++SET GLOBAL slow_query_log_use_global_control=default;
2500++SET GLOBAL long_query_time=default;
2501++[log_grep.inc] file: percona.slow_extended.min_examined_row_limit pattern: Query_time
2502++[log_grep.inc] lines: 1
2503+--- /dev/null
2504++++ b/mysql-test/t/percona_min_examined_row_limit.test
2505+@@ -0,0 +1,35 @@
2506++--source include/have_debug.inc
2507++
2508++--disable_warnings
2509++drop table if exists t;
2510++--enable_warnings
2511++
2512++create table t(id INT PRIMARY KEY);
2513++insert into t values(1);
2514++insert into t values(2);
2515++insert into t values(3);
2516++
2517++SET GLOBAL long_query_time=2;
2518++SET GLOBAL slow_query_log_use_global_control='long_query_time,min_examined_row_limit';
2519++--let log_file=percona.slow_extended.min_examined_row_limit
2520++--source include/log_start.inc
2521++
2522++SET SESSION query_exec_time=2.1;
2523++SELECT 1;
2524++
2525++SET GLOBAL min_examined_row_limit=5;
2526++
2527++select * from t as t1, t as t2;
2528++SELECT 1;
2529++
2530++SET SESSION query_exec_time=default;
2531++
2532++--source include/log_stop.inc
2533++SET GLOBAL min_examined_row_limit=default;
2534++SET GLOBAL slow_query_log_use_global_control=default;
2535++SET GLOBAL long_query_time=default;
2536++
2537++--let grep_pattern = Query_time
2538++--source include/log_grep.inc
2539++
2540++DROP TABLE t;
2541+--- a/sql/log_event.cc
2542++++ b/sql/log_event.cc
2543+@@ -2385,6 +2385,14 @@
2544+ start+= host.length;
2545+ }
2546+ }
2547++#ifndef DBUG_OFF
2548++ if (thd && thd->variables.query_exec_time > 0)
2549++ {
2550++ *start++= Q_QUERY_EXEC_TIME;
2551++ int8store(start, thd->variables.query_exec_time);
2552++ start+= 8;
2553++ }
2554++#endif
2555+ /*
2556+ NOTE: When adding new status vars, please don't forget to update
2557+ the MAX_SIZE_LOG_EVENT_STATUS in log_event.h and update the function
2558+@@ -2871,6 +2879,17 @@
2559+ data_written= master_data_written= uint4korr(pos);
2560+ pos+= 4;
2561+ break;
2562++#if !defined(DBUG_OFF) && !defined(MYSQL_CLIENT)
2563++ case Q_QUERY_EXEC_TIME:
2564++ {
2565++ THD *thd= current_thd;
2566++ CHECK_SPACE(pos, end, 8);
2567++ if (thd)
2568++ thd->variables.query_exec_time= uint8korr(pos);
2569++ pos+= 8;
2570++ break;
2571++ }
2572++#endif
2573+ case Q_INVOKER:
2574+ {
2575+ CHECK_SPACE(pos, end, 1);
2576+--- a/sql/log_event.h
2577++++ b/sql/log_event.h
2578+@@ -342,6 +342,10 @@
2579+
2580+ #define Q_INVOKER 11
2581+
2582++#ifndef DBUG_OFF
2583++#define Q_QUERY_EXEC_TIME 250
2584++#endif
2585++
2586+ /* Intvar event post-header */
2587+
2588+ /* Intvar event data */
2589+--- /dev/null
2590++++ b/mysql-test/suite/sys_vars/r/query_exec_time_basic.result
2591+@@ -0,0 +1,2 @@
2592++SET GLOBAL query_exec_time=default;
2593++SET SESSION query_exec_time=default;
2594+--- /dev/null
2595++++ b/mysql-test/suite/sys_vars/t/query_exec_time_basic.test
2596+@@ -0,0 +1,4 @@
2597++--source include/have_debug.inc
2598++
2599++SET GLOBAL query_exec_time=default;
2600++SET SESSION query_exec_time=default;
2601+--- /dev/null
2602++++ b/mysql-test/r/percona_log_slow_global_control_default.result
2603+@@ -0,0 +1 @@
2604++SET GLOBAL slow_query_log_use_global_control=default;
2605+--- /dev/null
2606++++ b/mysql-test/t/percona_log_slow_global_control_default.test
2607+@@ -0,0 +1 @@
2608++SET GLOBAL slow_query_log_use_global_control=default;
2609+--- /dev/null
2610++++ b/mysql-test/r/percona_slow_extended_log_error.result
2611+@@ -0,0 +1,9 @@
2612++SET long_query_time=0;
2613++DROP TABLE IF EXISTS t1;
2614++CREATE TABLE t(a INT);
2615++[log_start.inc] percona.slow_extended.log_error
2616++CREATE TABLE t(a INT);
2617++ERROR 42S01: Table 't' already exists
2618++[log_stop.inc] percona.slow_extended.log_error
2619++[log_grep.inc] file: percona.slow_extended.log_error pattern: Last_errno: 1050
2620++[log_grep.inc] lines: 1
2621+--- /dev/null
2622++++ b/mysql-test/t/percona_slow_extended_log_error.test
2623+@@ -0,0 +1,15 @@
2624++--let log_file=percona.slow_extended.log_error
2625++SET long_query_time=0;
2626++--disable_warnings
2627++DROP TABLE IF EXISTS t1;
2628++--enable_warnings
2629++CREATE TABLE t(a INT);
2630++--source include/log_start.inc
2631++
2632++--error ER_TABLE_EXISTS_ERROR
2633++CREATE TABLE t(a INT);
2634++
2635++--source include/log_stop.inc
2636++--let grep_pattern = Last_errno: 1050
2637++--source include/log_grep.inc
2638++DROP TABLE t;
2639+--- /dev/null
2640++++ b/mysql-test/suite/sys_vars/t/log_slow_admin_statements_basic.test
2641+@@ -0,0 +1 @@
2642++SELECT @@global.log_slow_admin_statements;
2643+--- /dev/null
2644++++ b/mysql-test/suite/sys_vars/r/log_slow_admin_statements_basic.result
2645+@@ -0,0 +1,3 @@
2646++SELECT @@global.log_slow_admin_statements;
2647++@@global.log_slow_admin_statements
2648++0
2649+--- /dev/null
2650++++ b/mysql-test/r/percona_log_slow_admin_statements.result
2651+@@ -0,0 +1,35 @@
2652++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2653++Variable_name Value
2654++log_slow_admin_statements OFF
2655++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2656++VARIABLE_NAME VARIABLE_VALUE
2657++LOG_SLOW_ADMIN_STATEMENTS OFF
2658++SET GLOBAL log_slow_admin_statements=true;
2659++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2660++Variable_name Value
2661++log_slow_admin_statements ON
2662++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2663++VARIABLE_NAME VARIABLE_VALUE
2664++LOG_SLOW_ADMIN_STATEMENTS ON
2665++SET GLOBAL log_slow_admin_statements=false;
2666++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2667++Variable_name Value
2668++log_slow_admin_statements OFF
2669++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2670++VARIABLE_NAME VARIABLE_VALUE
2671++LOG_SLOW_ADMIN_STATEMENTS OFF
2672++SET GLOBAL log_slow_admin_statements=foo;
2673++ERROR 42000: Variable 'log_slow_admin_statements' can't be set to the value of 'foo'
2674++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2675++Variable_name Value
2676++log_slow_admin_statements OFF
2677++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2678++VARIABLE_NAME VARIABLE_VALUE
2679++LOG_SLOW_ADMIN_STATEMENTS OFF
2680++SET GLOBAL log_slow_admin_statements=default;
2681++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2682++Variable_name Value
2683++log_slow_admin_statements OFF
2684++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2685++VARIABLE_NAME VARIABLE_VALUE
2686++LOG_SLOW_ADMIN_STATEMENTS OFF
2687+--- /dev/null
2688++++ b/mysql-test/r/percona_log_slow_admin_statements-config_false.result
2689+@@ -0,0 +1,6 @@
2690++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2691++Variable_name Value
2692++log_slow_admin_statements OFF
2693++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2694++VARIABLE_NAME VARIABLE_VALUE
2695++LOG_SLOW_ADMIN_STATEMENTS OFF
2696+--- /dev/null
2697++++ b/mysql-test/r/percona_log_slow_admin_statements-config_foo.result
2698+@@ -0,0 +1,7 @@
2699++call mtr.add_suppression("option 'log_slow_admin_statements': boolean value 'foo' wasn't recognized. Set to OFF.");
2700++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2701++Variable_name Value
2702++log_slow_admin_statements OFF
2703++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2704++VARIABLE_NAME VARIABLE_VALUE
2705++LOG_SLOW_ADMIN_STATEMENTS OFF
2706+--- /dev/null
2707++++ b/mysql-test/r/percona_log_slow_admin_statements-config_true.result
2708+@@ -0,0 +1,6 @@
2709++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2710++Variable_name Value
2711++log_slow_admin_statements ON
2712++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2713++VARIABLE_NAME VARIABLE_VALUE
2714++LOG_SLOW_ADMIN_STATEMENTS ON
2715+--- /dev/null
2716++++ b/mysql-test/r/percona_log_slow_admin_statements-config.result
2717+@@ -0,0 +1,6 @@
2718++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2719++Variable_name Value
2720++log_slow_admin_statements ON
2721++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2722++VARIABLE_NAME VARIABLE_VALUE
2723++LOG_SLOW_ADMIN_STATEMENTS ON
2724+--- /dev/null
2725++++ b/mysql-test/t/percona_log_slow_admin_statements-config_false.cnf
2726+@@ -0,0 +1,2 @@
2727++[mysqld.1]
2728++log-slow-admin-statements=false
2729+--- /dev/null
2730++++ b/mysql-test/t/percona_log_slow_admin_statements-config_foo.cnf
2731+@@ -0,0 +1,2 @@
2732++[mysqld.1]
2733++log-slow-admin-statements=foo
2734+--- /dev/null
2735++++ b/mysql-test/t/percona_log_slow_admin_statements-config_true.cnf
2736+@@ -0,0 +1,2 @@
2737++[mysqld.1]
2738++log-slow-admin-statements=true
2739+--- /dev/null
2740++++ b/mysql-test/t/percona_log_slow_admin_statements-config.cnf
2741+@@ -0,0 +1,2 @@
2742++[mysqld.1]
2743++log-slow-admin-statements
2744+--- /dev/null
2745++++ b/mysql-test/t/percona_log_slow_admin_statements.test
2746+@@ -0,0 +1,20 @@
2747++# default value
2748++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2749++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2750++# set value to 'true'
2751++SET GLOBAL log_slow_admin_statements=true;
2752++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2753++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2754++# set value to 'false'
2755++SET GLOBAL log_slow_admin_statements=false;
2756++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2757++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2758++# set value to 'foo'
2759++--error ER_WRONG_VALUE_FOR_VAR
2760++SET GLOBAL log_slow_admin_statements=foo;
2761++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2762++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2763++# set value to default
2764++SET GLOBAL log_slow_admin_statements=default;
2765++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2766++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2767+--- /dev/null
2768++++ b/mysql-test/t/percona_log_slow_admin_statements-config_false.test
2769+@@ -0,0 +1,2 @@
2770++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2771++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2772+--- /dev/null
2773++++ b/mysql-test/t/percona_log_slow_admin_statements-config_foo.test
2774+@@ -0,0 +1,3 @@
2775++call mtr.add_suppression("option 'log_slow_admin_statements': boolean value 'foo' wasn't recognized. Set to OFF.");
2776++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2777++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2778+--- /dev/null
2779++++ b/mysql-test/t/percona_log_slow_admin_statements-config_true.test
2780+@@ -0,0 +1,2 @@
2781++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2782++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2783+--- /dev/null
2784++++ b/mysql-test/t/percona_log_slow_admin_statements-config.test
2785+@@ -0,0 +1,2 @@
2786++SHOW GLOBAL VARIABLES like 'log_slow_admin_statements';
2787++SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME='log_slow_admin_statements';
2788+--- a/mysql-test/r/mysqld--help-notwin.result
2789++++ b/mysql-test/r/mysqld--help-notwin.result
2790+@@ -250,15 +250,31 @@
2791+ --log-slow-admin-statements
2792+ Log slow OPTIMIZE, ANALYZE, ALTER and other
2793+ administrative statements to the slow log if it is open.
2794++ --log-slow-filter=name
2795++ Log only the queries that followed certain execution
2796++ plan. Multiple flags allowed in a comma-separated string.
2797++ [qc_miss, full_scan, full_join, tmp_table,
2798++ tmp_table_on_disk, filesort, filesort_on_disk]
2799+ --log-slow-queries[=name]
2800+ Log slow queries to a table or log file. Defaults logging
2801+ to table mysql.slow_log or hostname-slow.log if
2802+ --log-output=file is used. Must be enabled to activate
2803+ other slow log options. Deprecated option, use
2804+ --slow-query-log/--slow-query-log-file instead.
2805++ --log-slow-rate-limit=#
2806++ Rate limit statement writes to slow log to only those
2807++ from every (1/log_slow_rate_limit) session.
2808+ --log-slow-slave-statements
2809+- Log slow statements executed by slave thread to the slow
2810+- log if it is open.
2811++ Log queries replayed be the slave SQL thread
2812++ --log-slow-sp-statements
2813++ Log slow statements executed by stored procedure to the
2814++ slow log if it is open.
2815++ (Defaults to on; use --skip-log-slow-sp-statements to disable.)
2816++ --log-slow-verbosity=name
2817++ Choose how verbose the messages to your slow log will be.
2818++ Multiple flags allowed in a comma-separated string.
2819++ [microtime, query_plan, innodb, profiling,
2820++ profiling_use_getrusage]
2821+ --log-tc=name Path to transaction coordinator log (used for
2822+ transactions that affect more than one storage engine,
2823+ when binary log is disabled).
2824+@@ -660,6 +676,18 @@
2825+ Log slow queries to given log file. Defaults logging to
2826+ hostname-slow.log. Must be enabled to activate other slow
2827+ log options
2828++ --slow-query-log-timestamp-always
2829++ Timestamp is printed for all records of the slow log even
2830++ if they are same time.
2831++ --slow-query-log-timestamp-precision=name
2832++ Log slow statements executed by stored procedure to the
2833++ slow log if it is open. [second, microsecond]
2834++ --slow-query-log-use-global-control=name
2835++ Choose flags, wich always use the global variables.
2836++ Multiple flags allowed in a comma-separated string.
2837++ [none, log_slow_filter, log_slow_rate_limit,
2838++ log_slow_verbosity, long_query_time,
2839++ min_examined_row_limit, all]
2840+ --socket=name Socket file to use for connection
2841+ --sort-buffer-size=#
2842+ Each thread that needs to do a sort allocates a buffer of
2843+@@ -817,7 +845,11 @@
2844+ log-short-format FALSE
2845+ log-slave-updates FALSE
2846+ log-slow-admin-statements FALSE
2847++log-slow-filter
2848++log-slow-rate-limit 1
2849+ log-slow-slave-statements FALSE
2850++log-slow-sp-statements TRUE
2851++log-slow-verbosity
2852+ log-tc tc.log
2853+ log-tc-size 24576
2854+ log-warnings 1
2855+@@ -933,6 +965,9 @@
2856+ slave-type-conversions
2857+ slow-launch-time 2
2858+ slow-query-log FALSE
2859++slow-query-log-timestamp-always FALSE
2860++slow-query-log-timestamp-precision second
2861++slow-query-log-use-global-control
2862+ sort-buffer-size 2097152
2863+ sporadic-binlog-dump-fail FALSE
2864+ sql-mode
2865
2866=== removed file 'patches/slow_extended.patch'
2867--- patches/slow_extended.patch 2011-12-13 15:06:50 +0000
2868+++ patches/slow_extended.patch 1970-01-01 00:00:00 +0000
2869@@ -1,2772 +0,0 @@
2870-# name : slow_extended.patch
2871-# introduced : 11 or before
2872-# maintainer : Oleg
2873-#
2874-#!!! notice !!!
2875-# Any small change to this file in the main branch
2876-# should be done or reviewed by the maintainer!
2877---- a/include/mysql/plugin_audit.h.pp
2878-+++ b/include/mysql/plugin_audit.h.pp
2879-@@ -186,6 +186,16 @@
2880- char *thd_security_context(void* thd, char *buffer, unsigned int length,
2881- unsigned int max_query_len);
2882- void thd_inc_row_count(void* thd);
2883-+void increment_thd_innodb_stats(void* thd,
2884-+ unsigned long long trx_id,
2885-+ long io_reads,
2886-+ long long io_read,
2887-+ long io_reads_wait_timer,
2888-+ long lock_que_wait_timer,
2889-+ long que_wait_timer,
2890-+ long page_access);
2891-+unsigned long thd_log_slow_verbosity(const void* thd);
2892-+int thd_opt_slow_log();
2893- int mysql_tmpfile(const char *prefix);
2894- int thd_killed(const void* thd);
2895- unsigned long thd_get_thread_id(const void* thd);
2896---- a/include/mysql/plugin_auth.h.pp
2897-+++ b/include/mysql/plugin_auth.h.pp
2898-@@ -186,6 +186,16 @@
2899- char *thd_security_context(void* thd, char *buffer, unsigned int length,
2900- unsigned int max_query_len);
2901- void thd_inc_row_count(void* thd);
2902-+void increment_thd_innodb_stats(void* thd,
2903-+ unsigned long long trx_id,
2904-+ long io_reads,
2905-+ long long io_read,
2906-+ long io_reads_wait_timer,
2907-+ long lock_que_wait_timer,
2908-+ long que_wait_timer,
2909-+ long page_access);
2910-+unsigned long thd_log_slow_verbosity(const void* thd);
2911-+int thd_opt_slow_log();
2912- int mysql_tmpfile(const char *prefix);
2913- int thd_killed(const void* thd);
2914- unsigned long thd_get_thread_id(const void* thd);
2915---- a/include/mysql/plugin_ftparser.h.pp
2916-+++ b/include/mysql/plugin_ftparser.h.pp
2917-@@ -139,6 +139,16 @@
2918- char *thd_security_context(void* thd, char *buffer, unsigned int length,
2919- unsigned int max_query_len);
2920- void thd_inc_row_count(void* thd);
2921-+void increment_thd_innodb_stats(void* thd,
2922-+ unsigned long long trx_id,
2923-+ long io_reads,
2924-+ long long io_read,
2925-+ long io_reads_wait_timer,
2926-+ long lock_que_wait_timer,
2927-+ long que_wait_timer,
2928-+ long page_access);
2929-+unsigned long thd_log_slow_verbosity(const void* thd);
2930-+int thd_opt_slow_log();
2931- int mysql_tmpfile(const char *prefix);
2932- int thd_killed(const void* thd);
2933- unsigned long thd_get_thread_id(const void* thd);
2934---- a/include/mysql/plugin.h
2935-+++ b/include/mysql/plugin.h
2936-@@ -545,6 +545,17 @@
2937- /* Increments the row counter, see THD::row_count */
2938- void thd_inc_row_count(MYSQL_THD thd);
2939-
2940-+void increment_thd_innodb_stats(MYSQL_THD thd,
2941-+ unsigned long long trx_id,
2942-+ long io_reads,
2943-+ long long io_read,
2944-+ long io_reads_wait_timer,
2945-+ long lock_que_wait_timer,
2946-+ long que_wait_timer,
2947-+ long page_access);
2948-+unsigned long thd_log_slow_verbosity(const MYSQL_THD thd);
2949-+int thd_opt_slow_log();
2950-+#define EXTENDED_SLOWLOG
2951- /**
2952- Create a temporary file.
2953-
2954---- /dev/null
2955-+++ b/patch_info/slow_extended.info
2956-@@ -0,0 +1,25 @@
2957-+File=slow_extended.patch
2958-+Name=Extended statistics in slow.log (not InnoDB part)
2959-+Version=1.3
2960-+Author=Percona <info@percona.com>
2961-+License=GPL
2962-+Comment=
2963-+Changelog
2964-+2008-11-26
2965-+YK: Fix inefficient determination of trx, Make not to call useless gettimeofday when don't use slow log. Make log_slow_queries dynamic (bool).
2966-+
2967-+2008-11-07
2968-+VT: Moved log_slow_rate_limit in SHOW VARIABLE into right place
2969-+
2970-+2008-11
2971-+Arjen Lentz: Fixups (backward compatibility) by Arjen Lentz <arjen@openquery.com.au>
2972-+
2973-+2010-07
2974-+1) Fix overflow of query time and lock time (Bug 600360) (slow_extended_fix_overflow.patch merged)
2975-+2) Control global slow feature merged (control_global_slow.patch merged)
2976-+3) Microseconds in slow query log merged (microseconds_in_slow_query_log.patch merged)
2977-+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)
2978-+5) Fix innodb_stats on replication (Bug 600684)
2979-+6) Change variable types (system/command-line)
2980-+2011-01
2981-+Patch profiling_slow.patch was merged
2982---- a/scripts/mysqldumpslow.sh
2983-+++ b/scripts/mysqldumpslow.sh
2984-@@ -102,8 +102,8 @@
2985- s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//;
2986- my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('','');
2987-
2988-- s/^# Query_time: ([0-9.]+)\s+Lock_time: ([0-9.]+)\s+Rows_sent: ([0-9.]+).*\n//;
2989-- my ($t, $l, $r) = ($1, $2, $3);
2990-+ s/^# Query_time: (\d+(\.\d+)?) Lock_time: (\d+(\.\d+)?) Rows_sent: (\d+(\.\d+)?).*\n//;
2991-+ my ($t, $l, $r) = ($1, $3, $5);
2992- $t -= $l unless $opt{l};
2993-
2994- # remove fluff that mysqld writes to log when it (re)starts:
2995---- a/sql/event_scheduler.cc
2996-+++ b/sql/event_scheduler.cc
2997-@@ -195,6 +195,7 @@
2998- thd->client_capabilities|= CLIENT_MULTI_RESULTS;
2999- mysql_mutex_lock(&LOCK_thread_count);
3000- thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
3001-+ thd->write_to_slow_log = TRUE;
3002- mysql_mutex_unlock(&LOCK_thread_count);
3003-
3004- /*
3005---- a/sql/filesort.cc
3006-+++ b/sql/filesort.cc
3007-@@ -193,6 +193,7 @@
3008- {
3009- status_var_increment(thd->status_var.filesort_scan_count);
3010- }
3011-+ thd->query_plan_flags|= QPLAN_FILESORT;
3012- #ifdef CAN_TRUST_RANGE
3013- if (select && select->quick && select->quick->records > 0L)
3014- {
3015-@@ -261,6 +262,7 @@
3016- /* filesort cannot handle zero-length records during merge. */
3017- DBUG_ASSERT(param.sort_length != 0);
3018-
3019-+ thd->query_plan_flags|= QPLAN_FILESORT_DISK;
3020- if (table_sort.buffpek && table_sort.buffpek_len < maxbuffer)
3021- {
3022- my_free(table_sort.buffpek);
3023-@@ -1209,6 +1211,7 @@
3024- DBUG_ENTER("merge_buffers");
3025-
3026- status_var_increment(current_thd->status_var.filesort_merge_passes);
3027-+ current_thd->query_plan_fsort_passes++;
3028- if (param->not_killable)
3029- {
3030- killed= &not_killable;
3031---- a/sql/log.cc
3032-+++ b/sql/log.cc
3033-@@ -715,11 +715,13 @@
3034- */
3035-
3036- bool Log_to_csv_event_handler::
3037-- log_slow(THD *thd, time_t current_time, time_t query_start_arg,
3038-+ log_slow(THD *thd, ulonglong current_utime, time_t query_start_arg,
3039- const char *user_host, uint user_host_len,
3040- ulonglong query_utime, ulonglong lock_utime, bool is_command,
3041- const char *sql_text, uint sql_text_len)
3042- {
3043-+ time_t current_time= my_time_possible_from_micro(current_utime);
3044-+
3045- TABLE_LIST table_list;
3046- TABLE *table;
3047- bool result= TRUE;
3048-@@ -935,14 +937,14 @@
3049- /** Wrapper around MYSQL_LOG::write() for slow log. */
3050-
3051- bool Log_to_file_event_handler::
3052-- log_slow(THD *thd, time_t current_time, time_t query_start_arg,
3053-+ log_slow(THD *thd, ulonglong current_utime, time_t query_start_arg,
3054- const char *user_host, uint user_host_len,
3055- ulonglong query_utime, ulonglong lock_utime, bool is_command,
3056- const char *sql_text, uint sql_text_len)
3057- {
3058- Silence_log_table_errors error_handler;
3059- thd->push_internal_handler(&error_handler);
3060-- bool retval= mysql_slow_log.write(thd, current_time, query_start_arg,
3061-+ bool retval= mysql_slow_log.write(thd, current_utime, query_start_arg,
3062- user_host, user_host_len,
3063- query_utime, lock_utime, is_command,
3064- sql_text, sql_text_len);
3065-@@ -1200,8 +1202,6 @@
3066-
3067- if (*slow_log_handler_list)
3068- {
3069-- time_t current_time;
3070--
3071- /* do not log slow queries from replication threads */
3072- if (thd->slave_thread && !opt_log_slow_slave_statements)
3073- return 0;
3074-@@ -1216,16 +1216,29 @@
3075- /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
3076- user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
3077- sctx->priv_user ? sctx->priv_user : "", "[",
3078-- sctx->user ? sctx->user : "", "] @ ",
3079-+ sctx->user ? sctx->user : (thd->slave_thread ? "SQL_SLAVE" : ""), "] @ ",
3080- sctx->host ? sctx->host : "", " [",
3081- sctx->ip ? sctx->ip : "", "]", NullS) -
3082- user_host_buff);
3083-
3084-- current_time= my_time_possible_from_micro(current_utime);
3085- if (thd->start_utime)
3086- {
3087-- query_utime= (current_utime - thd->start_utime);
3088-- lock_utime= (thd->utime_after_lock - thd->start_utime);
3089-+ if(current_utime < thd->start_utime)
3090-+ {
3091-+ query_utime= 0;
3092-+ }
3093-+ else
3094-+ {
3095-+ query_utime= (current_utime - thd->start_utime);
3096-+ }
3097-+ if(thd->utime_after_lock < thd->start_utime)
3098-+ {
3099-+ lock_utime= 0;
3100-+ }
3101-+ else
3102-+ {
3103-+ lock_utime= (thd->utime_after_lock - thd->start_utime);
3104-+ }
3105- }
3106- else
3107- {
3108-@@ -1240,7 +1253,7 @@
3109- }
3110-
3111- for (current_handler= slow_log_handler_list; *current_handler ;)
3112-- error= (*current_handler++)->log_slow(thd, current_time, thd->start_time,
3113-+ error= (*current_handler++)->log_slow(thd, current_utime, thd->start_time,
3114- user_host_buff, user_host_len,
3115- query_utime, lock_utime, is_command,
3116- query, query_length) || error;
3117-@@ -2656,12 +2669,13 @@
3118- TRUE - error occured
3119- */
3120-
3121--bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
3122-+bool MYSQL_QUERY_LOG::write(THD *thd, ulonglong current_utime,
3123- time_t query_start_arg, const char *user_host,
3124- uint user_host_len, ulonglong query_utime,
3125- ulonglong lock_utime, bool is_command,
3126- const char *sql_text, uint sql_text_len)
3127- {
3128-+ time_t current_time= my_time_possible_from_micro(current_utime);
3129- bool error= 0;
3130- DBUG_ENTER("MYSQL_QUERY_LOG::write");
3131-
3132-@@ -2683,17 +2697,28 @@
3133-
3134- if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
3135- {
3136-- if (current_time != last_time)
3137-+ if (opt_slow_query_log_timestamp_always || current_time != last_time)
3138- {
3139- last_time= current_time;
3140- struct tm start;
3141- localtime_r(&current_time, &start);
3142--
3143-- buff_len= my_snprintf(buff, sizeof buff,
3144-- "# Time: %02d%02d%02d %2d:%02d:%02d\n",
3145-- start.tm_year % 100, start.tm_mon + 1,
3146-- start.tm_mday, start.tm_hour,
3147-- start.tm_min, start.tm_sec);
3148-+ if(opt_slow_query_log_timestamp_precision & SLOG_MICROSECOND)
3149-+ {
3150-+ ulonglong microsecond = current_utime % (1000 * 1000);
3151-+ buff_len= snprintf(buff, sizeof buff,
3152-+ "# Time: %02d%02d%02d %2d:%02d:%02d.%010lld\n",
3153-+ start.tm_year % 100, start.tm_mon + 1,
3154-+ start.tm_mday, start.tm_hour,
3155-+ start.tm_min, start.tm_sec,microsecond);
3156-+ }
3157-+ else
3158-+ {
3159-+ buff_len= my_snprintf(buff, sizeof buff,
3160-+ "# Time: %02d%02d%02d %2d:%02d:%02d\n",
3161-+ start.tm_year % 100, start.tm_mon + 1,
3162-+ start.tm_mday, start.tm_hour,
3163-+ start.tm_min, start.tm_sec);
3164-+ }
3165-
3166- /* Note that my_b_write() assumes it knows the length for this */
3167- if (my_b_write(&log_file, (uchar*) buff, buff_len))
3168-@@ -2710,13 +2735,71 @@
3169- /* For slow query log */
3170- sprintf(query_time_buff, "%.6f", ulonglong2double(query_utime)/1000000.0);
3171- sprintf(lock_time_buff, "%.6f", ulonglong2double(lock_utime)/1000000.0);
3172-+ DBUG_PRINT("info", ("Last_errno: %u", thd->last_errno));
3173- if (my_b_printf(&log_file,
3174-- "# Query_time: %s Lock_time: %s"
3175-- " Rows_sent: %lu Rows_examined: %lu\n",
3176-+ "# Thread_id: %lu Schema: %s Last_errno: %u Killed: %u\n" \
3177-+ "# Query_time: %s Lock_time: %s Rows_sent: %lu Rows_examined: %lu Rows_affected: %lu Rows_read: %lu\n"
3178-+ "# Bytes_sent: %lu Tmp_tables: %lu Tmp_disk_tables: %lu Tmp_table_sizes: %lu\n",
3179-+ (ulong) thd->thread_id, (thd->db ? thd->db : ""),
3180-+ thd->last_errno, (uint) thd->killed,
3181- query_time_buff, lock_time_buff,
3182- (ulong) thd->sent_row_count,
3183-- (ulong) thd->examined_row_count) == (uint) -1)
3184-+ (ulong) thd->examined_row_count,
3185-+ ((long) thd->get_row_count_func() > 0 ) ? (ulong) thd->get_row_count_func() : 0,
3186-+ (ulong) thd->sent_row_count,
3187-+ (ulong) (thd->status_var.bytes_sent - thd->bytes_sent_old),
3188-+ (ulong) thd->tmp_tables_used,
3189-+ (ulong) thd->tmp_tables_disk_used,
3190-+ (ulong) thd->tmp_tables_size) == (uint) -1)
3191- tmp_errno= errno;
3192-+
3193-+#if defined(ENABLED_PROFILING)
3194-+ thd->profiling.print_current(&log_file);
3195-+#endif
3196-+ if (thd->innodb_was_used)
3197-+ {
3198-+ char buf[20];
3199-+ snprintf(buf, 20, "%llX", thd->innodb_trx_id);
3200-+ if (my_b_printf(&log_file,
3201-+ "# InnoDB_trx_id: %s\n", buf) == (uint) -1)
3202-+ tmp_errno=errno;
3203-+ }
3204-+ if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_QUERY_PLAN)) &&
3205-+ my_b_printf(&log_file,
3206-+ "# QC_Hit: %s Full_scan: %s Full_join: %s Tmp_table: %s Tmp_table_on_disk: %s\n" \
3207-+ "# Filesort: %s Filesort_on_disk: %s Merge_passes: %lu\n",
3208-+ ((thd->query_plan_flags & QPLAN_QC) ? "Yes" : "No"),
3209-+ ((thd->query_plan_flags & QPLAN_FULL_SCAN) ? "Yes" : "No"),
3210-+ ((thd->query_plan_flags & QPLAN_FULL_JOIN) ? "Yes" : "No"),
3211-+ ((thd->query_plan_flags & QPLAN_TMP_TABLE) ? "Yes" : "No"),
3212-+ ((thd->query_plan_flags & QPLAN_TMP_DISK) ? "Yes" : "No"),
3213-+ ((thd->query_plan_flags & QPLAN_FILESORT) ? "Yes" : "No"),
3214-+ ((thd->query_plan_flags & QPLAN_FILESORT_DISK) ? "Yes" : "No"),
3215-+ thd->query_plan_fsort_passes) == (uint) -1)
3216-+ tmp_errno=errno;
3217-+ if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_INNODB)) && thd->innodb_was_used)
3218-+ {
3219-+ char buf[3][20];
3220-+ snprintf(buf[0], 20, "%.6f", thd->innodb_io_reads_wait_timer / 1000000.0);
3221-+ snprintf(buf[1], 20, "%.6f", thd->innodb_lock_que_wait_timer / 1000000.0);
3222-+ snprintf(buf[2], 20, "%.6f", thd->innodb_innodb_que_wait_timer / 1000000.0);
3223-+ if (my_b_printf(&log_file,
3224-+ "# InnoDB_IO_r_ops: %lu InnoDB_IO_r_bytes: %lu InnoDB_IO_r_wait: %s\n" \
3225-+ "# InnoDB_rec_lock_wait: %s InnoDB_queue_wait: %s\n" \
3226-+ "# InnoDB_pages_distinct: %lu\n",
3227-+ (ulong) thd->innodb_io_reads,
3228-+ (ulong) thd->innodb_io_read,
3229-+ buf[0], buf[1], buf[2],
3230-+ (ulong) thd->innodb_page_access) == (uint) -1)
3231-+ tmp_errno=errno;
3232-+ }
3233-+ else
3234-+ {
3235-+ if ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_INNODB)) &&
3236-+ my_b_printf(&log_file,"# No InnoDB statistics available for this query\n") == (uint) -1)
3237-+ tmp_errno=errno;
3238-+ }
3239-+
3240- if (thd->db && strcmp(thd->db, db))
3241- { // Database changed
3242- if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1)
3243---- a/sql/log.h
3244-+++ b/sql/log.h
3245-@@ -242,7 +242,7 @@
3246- uint user_host_len, int thread_id,
3247- const char *command_type, uint command_type_len,
3248- const char *sql_text, uint sql_text_len);
3249-- bool write(THD *thd, time_t current_time, time_t query_start_arg,
3250-+ bool write(THD *thd, ulonglong current_time, time_t query_start_arg,
3251- const char *user_host, uint user_host_len,
3252- ulonglong query_utime, ulonglong lock_utime, bool is_command,
3253- const char *sql_text, uint sql_text_len);
3254-@@ -515,7 +515,7 @@
3255- virtual bool init()= 0;
3256- virtual void cleanup()= 0;
3257-
3258-- virtual bool log_slow(THD *thd, time_t current_time,
3259-+ virtual bool log_slow(THD *thd, ulonglong current_time,
3260- time_t query_start_arg, const char *user_host,
3261- uint user_host_len, ulonglong query_utime,
3262- ulonglong lock_utime, bool is_command,
3263-@@ -544,7 +544,7 @@
3264- virtual bool init();
3265- virtual void cleanup();
3266-
3267-- virtual bool log_slow(THD *thd, time_t current_time,
3268-+ virtual bool log_slow(THD *thd, ulonglong current_utime,
3269- time_t query_start_arg, const char *user_host,
3270- uint user_host_len, ulonglong query_utime,
3271- ulonglong lock_utime, bool is_command,
3272-@@ -576,7 +576,7 @@
3273- virtual bool init();
3274- virtual void cleanup();
3275-
3276-- virtual bool log_slow(THD *thd, time_t current_time,
3277-+ virtual bool log_slow(THD *thd, ulonglong current_utime,
3278- time_t query_start_arg, const char *user_host,
3279- uint user_host_len, ulonglong query_utime,
3280- ulonglong lock_utime, bool is_command,
3281---- a/sql/mysqld.cc
3282-+++ b/sql/mysqld.cc
3283-@@ -421,6 +421,10 @@
3284- char* opt_secure_file_priv;
3285- my_bool opt_log_slow_admin_statements= 0;
3286- my_bool opt_log_slow_slave_statements= 0;
3287-+my_bool opt_log_slow_sp_statements= 0;
3288-+my_bool opt_slow_query_log_timestamp_always= 0;
3289-+ulonglong opt_slow_query_log_use_global_control= 0;
3290-+ulong opt_slow_query_log_timestamp_precision= 0;
3291- my_bool lower_case_file_system= 0;
3292- my_bool opt_large_pages= 0;
3293- my_bool opt_super_large_pages= 0;
3294-@@ -5892,14 +5896,10 @@
3295- "Don't log extra information to update and slow-query logs.",
3296- &opt_short_log_format, &opt_short_log_format,
3297- 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3298-- {"log-slow-admin-statements", 0,
3299-- "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to "
3300-- "the slow log if it is open.", &opt_log_slow_admin_statements,
3301-- &opt_log_slow_admin_statements, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3302-- {"log-slow-slave-statements", 0,
3303-+ /*{"log-slow-slave-statements", 0,
3304- "Log slow statements executed by slave thread to the slow log if it is open.",
3305- &opt_log_slow_slave_statements, &opt_log_slow_slave_statements,
3306-- 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3307-+ 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},*/
3308- {"log-slow-queries", OPT_SLOW_QUERY_LOG,
3309- "Log slow queries to a table or log file. Defaults logging to table "
3310- "mysql.slow_log or hostname-slow.log if --log-output=file is used. "
3311-@@ -7288,6 +7288,10 @@
3312-
3313- C_MODE_END
3314-
3315-+/* defined in sys_vars.cc */
3316-+extern void init_log_slow_verbosity();
3317-+extern void init_slow_query_log_use_global_control();
3318-+
3319- /**
3320- Get server options from the command line,
3321- and perform related server initializations.
3322-@@ -7437,6 +7441,8 @@
3323- global_system_variables.long_query_time= (ulonglong)
3324- (global_system_variables.long_query_time_double * 1e6);
3325-
3326-+ init_log_slow_verbosity();
3327-+ init_slow_query_log_use_global_control();
3328- if (opt_short_log_format)
3329- opt_specialflag|= SPECIAL_SHORT_LOG_FORMAT;
3330-
3331---- a/sql/mysqld.h
3332-+++ b/sql/mysqld.h
3333-@@ -116,6 +116,10 @@
3334- extern char* opt_secure_backup_file_priv;
3335- extern size_t opt_secure_backup_file_priv_len;
3336- extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements;
3337-+extern my_bool opt_log_slow_sp_statements;
3338-+extern my_bool opt_slow_query_log_timestamp_always;
3339-+extern ulonglong opt_slow_query_log_use_global_control;
3340-+extern ulong opt_slow_query_log_timestamp_precision;
3341- extern my_bool sp_automatic_privileges, opt_noacl;
3342- extern my_bool opt_old_style_user_limits, trust_function_creators;
3343- extern uint opt_crash_binlog_innodb;
3344---- a/sql/slave.cc
3345-+++ b/sql/slave.cc
3346-@@ -2038,6 +2038,7 @@
3347- + MAX_LOG_EVENT_HEADER; /* note, incr over the global not session var */
3348- thd->slave_thread = 1;
3349- thd->enable_slow_log= opt_log_slow_slave_statements;
3350-+ thd->write_to_slow_log= opt_log_slow_slave_statements;
3351- set_slave_thread_options(thd);
3352- thd->client_capabilities = CLIENT_LOCAL_FILES;
3353- mysql_mutex_lock(&LOCK_thread_count);
3354---- a/sql/sp_head.cc
3355-+++ b/sql/sp_head.cc
3356-@@ -2152,7 +2152,7 @@
3357- DBUG_PRINT("info",(" %.*s: eval args done", (int) m_name.length,
3358- m_name.str));
3359- }
3360-- if (!(m_flags & LOG_SLOW_STATEMENTS) && thd->enable_slow_log)
3361-+ if (!(m_flags & LOG_SLOW_STATEMENTS || opt_log_slow_sp_statements) && thd->enable_slow_log)
3362- {
3363- DBUG_PRINT("info", ("Disabling slow log for the execution"));
3364- save_enable_slow_log= true;
3365---- a/sql/sql_cache.cc
3366-+++ b/sql/sql_cache.cc
3367-@@ -1756,6 +1756,7 @@
3368- response, we can't handle it anyway.
3369- */
3370- (void) trans_commit_stmt(thd);
3371-+ thd->query_plan_flags|= QPLAN_QC;
3372- if (!thd->stmt_da->is_set())
3373- thd->stmt_da->disable_status();
3374-
3375-@@ -1766,6 +1767,7 @@
3376- err_unlock:
3377- unlock();
3378- err:
3379-+ thd->query_plan_flags|= QPLAN_QC_NO;
3380- MYSQL_QUERY_CACHE_MISS(thd->query());
3381- DBUG_RETURN(0); // Query was not cached
3382- }
3383---- a/sql/sql_class.cc
3384-+++ b/sql/sql_class.cc
3385-@@ -616,6 +616,37 @@
3386- thd->warning_info->inc_current_row_for_warning();
3387- }
3388-
3389-+extern "C"
3390-+void increment_thd_innodb_stats(THD* thd,
3391-+ unsigned long long trx_id,
3392-+ long io_reads,
3393-+ long long io_read,
3394-+ long io_reads_wait_timer,
3395-+ long lock_que_wait_timer,
3396-+ long que_wait_timer,
3397-+ long page_access)
3398-+{
3399-+ thd->innodb_was_used= TRUE;
3400-+ thd->innodb_trx_id= trx_id;
3401-+ thd->innodb_io_reads+= io_reads;
3402-+ thd->innodb_io_read+= io_read;
3403-+ thd->innodb_io_reads_wait_timer+= io_reads_wait_timer;
3404-+ thd->innodb_lock_que_wait_timer+= lock_que_wait_timer;
3405-+ thd->innodb_innodb_que_wait_timer+= que_wait_timer;
3406-+ thd->innodb_page_access+= page_access;
3407-+}
3408-+
3409-+extern "C"
3410-+unsigned long thd_log_slow_verbosity(const THD *thd)
3411-+{
3412-+ return (unsigned long) thd->variables.log_slow_verbosity;
3413-+}
3414-+
3415-+extern "C"
3416-+int thd_opt_slow_log()
3417-+{
3418-+ return (int) opt_slow_log;
3419-+}
3420-
3421- /**
3422- Dumps a text description of a thread, its security context
3423-@@ -942,6 +973,8 @@
3424- const char* msg,
3425- MYSQL_ERROR ** cond_hdl)
3426- {
3427-+ last_errno= sql_errno;
3428-+
3429- if (!m_internal_handler)
3430- {
3431- *cond_hdl= NULL;
3432-@@ -1236,6 +1269,8 @@
3433- /* Initialize the Debug Sync Facility. See debug_sync.cc. */
3434- debug_sync_init_thread(this);
3435- #endif /* defined(ENABLED_DEBUG_SYNC) */
3436-+
3437-+ clear_slow_extended();
3438- }
3439-
3440-
3441-@@ -3682,8 +3717,6 @@
3442- backup->in_sub_stmt= in_sub_stmt;
3443- backup->enable_slow_log= enable_slow_log;
3444- backup->limit_found_rows= limit_found_rows;
3445-- backup->examined_row_count= examined_row_count;
3446-- backup->sent_row_count= sent_row_count;
3447- backup->cuted_fields= cuted_fields;
3448- backup->client_capabilities= client_capabilities;
3449- backup->savepoints= transaction.savepoints;
3450-@@ -3691,6 +3724,7 @@
3451- first_successful_insert_id_in_prev_stmt;
3452- backup->first_successful_insert_id_in_cur_stmt=
3453- first_successful_insert_id_in_cur_stmt;
3454-+ reset_sub_statement_state_slow_extended(backup);
3455-
3456- if ((!lex->requires_prelocking() || is_update_query(lex->sql_command)) &&
3457- !is_current_stmt_binlog_format_row())
3458-@@ -3706,13 +3740,74 @@
3459- /* Disable result sets */
3460- client_capabilities &= ~CLIENT_MULTI_RESULTS;
3461- in_sub_stmt|= new_state;
3462-- examined_row_count= 0;
3463-- sent_row_count= 0;
3464- cuted_fields= 0;
3465- transaction.savepoints= 0;
3466- first_successful_insert_id_in_cur_stmt= 0;
3467- }
3468-
3469-+void THD::clear_slow_extended()
3470-+{
3471-+ DBUG_ENTER("THD::clear_slow_extended");
3472-+ sent_row_count= 0;
3473-+ examined_row_count= 0;
3474-+ bytes_sent_old= status_var.bytes_sent;
3475-+ tmp_tables_used= 0;
3476-+ tmp_tables_disk_used= 0;
3477-+ tmp_tables_size= 0;
3478-+ innodb_was_used= FALSE;
3479-+ innodb_trx_id= 0;
3480-+ innodb_io_reads= 0;
3481-+ innodb_io_read= 0;
3482-+ innodb_io_reads_wait_timer= 0;
3483-+ innodb_lock_que_wait_timer= 0;
3484-+ innodb_innodb_que_wait_timer= 0;
3485-+ innodb_page_access= 0;
3486-+ query_plan_flags= QPLAN_NONE;
3487-+ query_plan_fsort_passes= 0;
3488-+ last_errno= 0;
3489-+ DBUG_VOID_RETURN;
3490-+}
3491-+
3492-+void THD::reset_sub_statement_state_slow_extended(Sub_statement_state *backup)
3493-+{
3494-+ DBUG_ENTER("THD::reset_sub_statement_state_slow_extended");
3495-+ backup->sent_row_count= sent_row_count;
3496-+ backup->examined_row_count= examined_row_count;
3497-+ backup->tmp_tables_used= tmp_tables_used;
3498-+ backup->tmp_tables_disk_used= tmp_tables_disk_used;
3499-+ backup->tmp_tables_size= tmp_tables_size;
3500-+ backup->innodb_was_used= innodb_was_used;
3501-+ backup->innodb_io_reads= innodb_io_reads;
3502-+ backup->innodb_io_read= innodb_io_read;
3503-+ backup->innodb_io_reads_wait_timer= innodb_io_reads_wait_timer;
3504-+ backup->innodb_lock_que_wait_timer= innodb_lock_que_wait_timer;
3505-+ backup->innodb_innodb_que_wait_timer= innodb_innodb_que_wait_timer;
3506-+ backup->innodb_page_access= innodb_page_access;
3507-+ backup->query_plan_flags= query_plan_flags;
3508-+ backup->query_plan_fsort_passes= query_plan_fsort_passes;
3509-+ clear_slow_extended();
3510-+ DBUG_VOID_RETURN;
3511-+}
3512-+
3513-+void THD::restore_sub_statement_state_slow_extended(const Sub_statement_state *backup)
3514-+{
3515-+ DBUG_ENTER("THD::restore_sub_statement_state_slow_extended");
3516-+ sent_row_count= backup->sent_row_count;
3517-+ examined_row_count+= backup->examined_row_count;
3518-+ tmp_tables_used+= backup->tmp_tables_used;
3519-+ tmp_tables_disk_used+= backup->tmp_tables_disk_used;
3520-+ tmp_tables_size+= backup->tmp_tables_size;
3521-+ innodb_was_used= (innodb_was_used || backup->innodb_was_used);
3522-+ innodb_io_reads+= backup->innodb_io_reads;
3523-+ innodb_io_read+= backup->innodb_io_read;
3524-+ innodb_io_reads_wait_timer+= backup->innodb_io_reads_wait_timer;
3525-+ innodb_lock_que_wait_timer+= backup->innodb_lock_que_wait_timer;
3526-+ innodb_innodb_que_wait_timer+= backup->innodb_innodb_que_wait_timer;
3527-+ innodb_page_access+= backup->innodb_page_access;
3528-+ query_plan_flags|= backup->query_plan_flags;
3529-+ query_plan_fsort_passes+= backup->query_plan_fsort_passes;
3530-+ DBUG_VOID_RETURN;
3531-+}
3532-
3533- void THD::restore_sub_statement_state(Sub_statement_state *backup)
3534- {
3535-@@ -3753,7 +3848,6 @@
3536- first_successful_insert_id_in_cur_stmt=
3537- backup->first_successful_insert_id_in_cur_stmt;
3538- limit_found_rows= backup->limit_found_rows;
3539-- sent_row_count= backup->sent_row_count;
3540- client_capabilities= backup->client_capabilities;
3541- /*
3542- If we've left sub-statement mode, reset the fatal error flag.
3543-@@ -3771,8 +3865,8 @@
3544- The following is added to the old values as we are interested in the
3545- total complexity of the query
3546- */
3547-- examined_row_count+= backup->examined_row_count;
3548- cuted_fields+= backup->cuted_fields;
3549-+ restore_sub_statement_state_slow_extended(backup);
3550- DBUG_VOID_RETURN;
3551- }
3552-
3553---- a/sql/sql_class.h
3554-+++ b/sql/sql_class.h
3555-@@ -60,6 +60,33 @@
3556- enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
3557- enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON,
3558- DELAY_KEY_WRITE_ALL };
3559-+enum enum_slow_query_log_use_global_control {
3560-+ SLOG_UG_LOG_SLOW_FILTER, SLOG_UG_LOG_SLOW_RATE_LIMIT
3561-+ , SLOG_UG_LOG_SLOW_VERBOSITY, SLOG_UG_LONG_QUERY_TIME
3562-+ , SLOG_UG_MIN_EXAMINED_ROW_LIMIT, SLOG_UG_ALL
3563-+};
3564-+enum enum_log_slow_verbosity {
3565-+ SLOG_V_MICROTIME, SLOG_V_QUERY_PLAN, SLOG_V_INNODB,
3566-+ SLOG_V_PROFILING, SLOG_V_PROFILING_USE_GETRUSAGE,
3567-+ SLOG_V_MINIMAL, SLOG_V_STANDARD, SLOG_V_FULL
3568-+};
3569-+enum enum_slow_query_log_timestamp_precision {
3570-+ SLOG_SECOND, SLOG_MICROSECOND
3571-+};
3572-+#define QPLAN_NONE 0
3573-+#define QPLAN_QC 1 << 0
3574-+#define QPLAN_QC_NO 1 << 1
3575-+#define QPLAN_FULL_SCAN 1 << 2
3576-+#define QPLAN_FULL_JOIN 1 << 3
3577-+#define QPLAN_TMP_TABLE 1 << 4
3578-+#define QPLAN_TMP_DISK 1 << 5
3579-+#define QPLAN_FILESORT 1 << 6
3580-+#define QPLAN_FILESORT_DISK 1 << 7
3581-+enum enum_log_slow_filter {
3582-+ SLOG_F_QC_NO, SLOG_F_FULL_SCAN, SLOG_F_FULL_JOIN,
3583-+ SLOG_F_TMP_TABLE, SLOG_F_TMP_DISK, SLOG_F_FILESORT,
3584-+ SLOG_F_FILESORT_DISK
3585-+};
3586- enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT,
3587- SLAVE_EXEC_MODE_IDEMPOTENT,
3588- SLAVE_EXEC_MODE_LAST_BIT};
3589-@@ -508,6 +535,21 @@
3590-
3591- my_bool sysdate_is_now;
3592-
3593-+#ifndef DBUG_OFF
3594-+ ulonglong query_exec_time;
3595-+ double query_exec_time_double;
3596-+#endif
3597-+ ulong log_slow_rate_limit;
3598-+ ulonglong log_slow_filter;
3599-+ ulonglong log_slow_verbosity;
3600-+
3601-+ ulong innodb_io_reads;
3602-+ ulonglong innodb_io_read;
3603-+ ulong innodb_io_reads_wait_timer;
3604-+ ulong innodb_lock_que_wait_timer;
3605-+ ulong innodb_innodb_que_wait_timer;
3606-+ ulong innodb_page_access;
3607-+
3608- double long_query_time_double;
3609-
3610- } SV;
3611-@@ -1140,6 +1182,24 @@
3612- uint in_sub_stmt;
3613- bool enable_slow_log;
3614- bool last_insert_id_used;
3615-+
3616-+ /*** Following variables used in slow_extended.patch ***/
3617-+ ulong tmp_tables_used;
3618-+ ulong tmp_tables_disk_used;
3619-+ ulonglong tmp_tables_size;
3620-+
3621-+ bool innodb_was_used;
3622-+ ulong innodb_io_reads;
3623-+ ulonglong innodb_io_read;
3624-+ ulong innodb_io_reads_wait_timer;
3625-+ ulong innodb_lock_que_wait_timer;
3626-+ ulong innodb_innodb_que_wait_timer;
3627-+ ulong innodb_page_access;
3628-+
3629-+ ulong query_plan_flags;
3630-+ ulong query_plan_fsort_passes;
3631-+ /*** The variables above used in slow_extended.patch ***/
3632-+
3633- SAVEPOINT *savepoints;
3634- enum enum_check_fields count_cuted_fields;
3635- };
3636-@@ -1588,6 +1648,71 @@
3637- thr_lock_type update_lock_default;
3638- Delayed_insert *di;
3639-
3640-+ /*** Following variables used in slow_extended.patch ***/
3641-+ /*
3642-+ Variable write_to_slow_log:
3643-+ 1) initialized in
3644-+ * sql_connect.cc (log_slow_rate_limit support)
3645-+ * slave.cc (log_slow_slave_statements support)
3646-+ 2) The variable is initialized on the thread startup and remains
3647-+ constant afterwards. This will change when
3648-+ LP #712396 ("log_slow_slave_statements not work on replication
3649-+ threads without RESTART") is implemented.
3650-+ 3) An implementation of LP #688646 ("Make query sampling possible by query") should use it.
3651-+ */
3652-+ bool write_to_slow_log;
3653-+ /*
3654-+ Variable bytes_send_old saves value of thd->status_var.bytes_sent
3655-+ before query execution.
3656-+ */
3657-+ ulonglong bytes_sent_old;
3658-+ /*
3659-+ Variables tmp_tables_*** collect statistics about usage of temporary tables
3660-+ */
3661-+ ulong tmp_tables_used;
3662-+ ulong tmp_tables_disk_used;
3663-+ ulonglong tmp_tables_size;
3664-+ /*
3665-+ Variable innodb_was_used shows used or not InnoDB engine in current query.
3666-+ */
3667-+ bool innodb_was_used;
3668-+ /*
3669-+ Following Variables innodb_*** (is |should be) different from
3670-+ default values only if (innodb_was_used==TRUE)
3671-+ */
3672-+ ulonglong innodb_trx_id;
3673-+ ulong innodb_io_reads;
3674-+ ulonglong innodb_io_read;
3675-+ ulong innodb_io_reads_wait_timer;
3676-+ ulong innodb_lock_que_wait_timer;
3677-+ ulong innodb_innodb_que_wait_timer;
3678-+ ulong innodb_page_access;
3679-+
3680-+ /*
3681-+ Variable query_plan_flags collects information about query plan entites
3682-+ used on query execution.
3683-+ */
3684-+ ulong query_plan_flags;
3685-+ /*
3686-+ Variable query_plan_fsort_passes collects information about file sort passes
3687-+ acquired during query execution.
3688-+ */
3689-+ ulong query_plan_fsort_passes;
3690-+ /*
3691-+ Query can generate several errors/warnings during execution
3692-+ (see THD::handle_condition comment in sql_class.h)
3693-+ Variable last_errno contains the last error/warning acquired during
3694-+ query execution.
3695-+ */
3696-+ uint last_errno;
3697-+ /*** The variables above used in slow_extended.patch ***/
3698-+
3699-+ /*** Following methods used in slow_extended.patch ***/
3700-+ void clear_slow_extended();
3701-+ void reset_sub_statement_state_slow_extended(Sub_statement_state *backup);
3702-+ void restore_sub_statement_state_slow_extended(const Sub_statement_state *backup);
3703-+ /*** The methods above used in slow_extended.patch ***/
3704-+
3705- /* <> 0 if we are inside of trigger or stored function. */
3706- uint in_sub_stmt;
3707-
3708---- a/sql/sql_connect.cc
3709-+++ b/sql/sql_connect.cc
3710-@@ -721,6 +721,15 @@
3711- MYSQL_CONNECTION_START(thd->thread_id, &thd->security_ctx->priv_user[0],
3712- (char *) thd->security_ctx->host_or_ip);
3713-
3714-+ /*
3715-+ If rate limiting of slow log writes is enabled, decide whether to log this
3716-+ new thread's queries or not. Uses extremely simple algorithm. :)
3717-+ */
3718-+ thd->write_to_slow_log= FALSE;
3719-+ if (thd->variables.log_slow_rate_limit <= 1 ||
3720-+ (thd->thread_id % thd->variables.log_slow_rate_limit) == 0)
3721-+ thd->write_to_slow_log= TRUE;
3722-+
3723- prepare_new_connection_state(thd);
3724- return FALSE;
3725- }
3726---- a/sql/sql_parse.cc
3727-+++ b/sql/sql_parse.cc
3728-@@ -114,6 +114,7 @@
3729-
3730- static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
3731- static void sql_kill(THD *thd, ulong id, bool only_kill_query);
3732-+static inline ulonglong get_query_exec_time(THD *thd, ulonglong cur_utime);
3733-
3734- const char *any_db="*any*"; // Special symbol for check_access
3735-
3736-@@ -888,6 +889,7 @@
3737- the slow log only if opt_log_slow_admin_statements is set.
3738- */
3739- thd->enable_slow_log= TRUE;
3740-+ thd->clear_slow_extended();
3741- thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
3742- thd->set_time();
3743- if (!thd->is_valid_time())
3744-@@ -1430,6 +1432,60 @@
3745- DBUG_RETURN(error);
3746- }
3747-
3748-+/**
3749-+ Calculate execution time for the current query.
3750-+
3751-+ For debug builds, check the session value of query_exec_time
3752-+ and if it is not zero, return it instead of the actual execution time.
3753-+
3754-+ SET queries are ignored so that statements changing query_exec_time are not
3755-+ affected by themselves.
3756-+
3757-+ @param thd thread handle
3758-+ @param lex current relative time in microseconds
3759-+
3760-+ @return time in microseconds from utime_after_lock
3761-+*/
3762-+
3763-+static inline ulonglong get_query_exec_time(THD *thd, ulonglong cur_utime)
3764-+{
3765-+ ulonglong res;
3766-+#ifndef DBUG_OFF
3767-+ if (thd->variables.query_exec_time != 0)
3768-+ res= thd->lex->sql_command != SQLCOM_SET_OPTION ?
3769-+ thd->variables.query_exec_time : 0;
3770-+ else
3771-+#endif
3772-+
3773-+ res= cur_utime - thd->utime_after_lock;
3774-+
3775-+ if (res > thd->variables.long_query_time)
3776-+ thd->server_status|= SERVER_QUERY_WAS_SLOW;
3777-+ else
3778-+ thd->server_status&= ~SERVER_QUERY_WAS_SLOW;
3779-+
3780-+ return res;
3781-+}
3782-+
3783-+
3784-+static inline void copy_global_to_session(THD *thd, ulong flag,
3785-+ const ulong *val)
3786-+{
3787-+ my_ptrdiff_t offset = ((char *)val - (char *)&global_system_variables);
3788-+ if (opt_slow_query_log_use_global_control & (1ULL << flag))
3789-+ *(ulong *)((char *) &thd->variables + offset) = *val;
3790-+}
3791-+
3792-+
3793-+static inline void copy_global_to_session(THD *thd, ulong flag,
3794-+ const ulonglong *val)
3795-+{
3796-+ my_ptrdiff_t offset = ((char *)val - (char *)&global_system_variables);
3797-+ if (opt_slow_query_log_use_global_control & (1ULL << flag))
3798-+ *(ulonglong *)((char *) &thd->variables + offset) = *val;
3799-+}
3800-+
3801-+
3802-
3803- void log_slow_statement(THD *thd)
3804- {
3805-@@ -1443,13 +1499,48 @@
3806- if (unlikely(thd->in_sub_stmt))
3807- DBUG_VOID_RETURN; // Don't set time for sub stmt
3808-
3809-+ /* Follow the slow log filter configuration. */
3810-+ if (thd->variables.log_slow_filter != 0 &&
3811-+ (!(thd->variables.log_slow_filter & thd->query_plan_flags) ||
3812-+ ((thd->variables.log_slow_filter & SLOG_F_QC_NO) &&
3813-+ (thd->query_plan_flags & QPLAN_QC))))
3814-+ DBUG_VOID_RETURN;
3815-+
3816-+ ulonglong end_utime_of_query= thd->current_utime();
3817-+ ulonglong query_exec_time= get_query_exec_time(thd, end_utime_of_query);
3818-+
3819-+ /*
3820-+ Low long_query_time value most likely means user is debugging stuff and even
3821-+ though some thread's queries are not supposed to be logged b/c of the rate
3822-+ limit, if one of them takes long enough (>= 1 second) it will be sensible
3823-+ to make an exception and write to slow log anyway.
3824-+ */
3825-+
3826-+ system_variables const &g= global_system_variables;
3827-+ copy_global_to_session(thd, SLOG_UG_LOG_SLOW_FILTER,
3828-+ &g.log_slow_filter);
3829-+ copy_global_to_session(thd, SLOG_UG_LOG_SLOW_RATE_LIMIT,
3830-+ &g.log_slow_rate_limit);
3831-+ copy_global_to_session(thd, SLOG_UG_LOG_SLOW_VERBOSITY,
3832-+ &g.log_slow_verbosity);
3833-+ copy_global_to_session(thd, SLOG_UG_LONG_QUERY_TIME,
3834-+ &g.long_query_time);
3835-+ copy_global_to_session(thd, SLOG_UG_MIN_EXAMINED_ROW_LIMIT,
3836-+ &g.min_examined_row_limit);
3837-+
3838-+ /* Do not log this thread's queries due to rate limiting. */
3839-+ if (thd->write_to_slow_log != TRUE
3840-+ && (thd->variables.long_query_time >= 1000000
3841-+ || (ulong) query_exec_time < 1000000))
3842-+ DBUG_VOID_RETURN;
3843-+
3844-+
3845- /*
3846- Do not log administrative statements unless the appropriate option is
3847- set.
3848- */
3849- if (thd->enable_slow_log)
3850- {
3851-- ulonglong end_utime_of_query= thd->current_utime();
3852- thd_proc_info(thd, "logging slow query");
3853-
3854- if (((thd->server_status & SERVER_QUERY_WAS_SLOW) ||
3855-@@ -5301,7 +5392,8 @@
3856- thd->stmt_da->reset_diagnostics_area();
3857- thd->warning_info->reset_for_next_command();
3858- thd->rand_used= 0;
3859-- thd->sent_row_count= thd->examined_row_count= 0;
3860-+
3861-+ thd->clear_slow_extended();
3862-
3863- thd->reset_current_stmt_binlog_format_row();
3864- thd->binlog_unsafe_warning_flags= 0;
3865---- a/sql/sql_select.cc
3866-+++ b/sql/sql_select.cc
3867-@@ -6902,7 +6902,10 @@
3868- {
3869- join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
3870- if (statistics)
3871-+ {
3872- status_var_increment(join->thd->status_var.select_scan_count);
3873-+ join->thd->query_plan_flags|= QPLAN_FULL_SCAN;
3874-+ }
3875- }
3876- }
3877- else
3878-@@ -6916,7 +6919,10 @@
3879- {
3880- join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
3881- if (statistics)
3882-+ {
3883- status_var_increment(join->thd->status_var.select_full_join_count);
3884-+ join->thd->query_plan_flags|= QPLAN_FULL_JOIN;
3885-+ }
3886- }
3887- }
3888- if (!table->no_keyread)
3889-@@ -10264,6 +10270,7 @@
3890- (ulong) rows_limit,test(group)));
3891-
3892- status_var_increment(thd->status_var.created_tmp_tables);
3893-+ thd->query_plan_flags|= QPLAN_TMP_TABLE;
3894-
3895- if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
3896- temp_pool_slot = bitmap_lock_set_next(&temp_pool);
3897-@@ -11162,6 +11169,7 @@
3898- goto err;
3899- }
3900- status_var_increment(table->in_use->status_var.created_tmp_disk_tables);
3901-+ table->in_use->query_plan_flags|= QPLAN_TMP_DISK;
3902- share->db_record_offset= 1;
3903- DBUG_RETURN(0);
3904- err:
3905-@@ -11180,6 +11188,14 @@
3906- save_proc_info=thd->proc_info;
3907- thd_proc_info(thd, "removing tmp table");
3908-
3909-+ thd->tmp_tables_used++;
3910-+ if (entry->file)
3911-+ {
3912-+ thd->tmp_tables_size += entry->file->stats.data_file_length;
3913-+ if (entry->file->ht->db_type != DB_TYPE_HEAP)
3914-+ thd->tmp_tables_disk_used++;
3915-+ }
3916-+
3917- // Release latches since this can take a long time
3918- ha_release_temporary_latches(thd);
3919-
3920---- a/sql/sql_show.cc
3921-+++ b/sql/sql_show.cc
3922-@@ -1950,8 +1950,17 @@
3923- table->field[4]->store(command_name[tmp->command].str,
3924- command_name[tmp->command].length, cs);
3925- /* MYSQL_TIME */
3926-- table->field[5]->store((longlong)(tmp->start_time ?
3927-- now - tmp->start_time : 0), FALSE);
3928-+ longlong value_in_time_column= 0;
3929-+ if(tmp->start_time)
3930-+ {
3931-+ value_in_time_column = (now - tmp->start_time);
3932-+ if(value_in_time_column > now)
3933-+ {
3934-+ value_in_time_column= 0;
3935-+ }
3936-+ }
3937-+ table->field[5]->store(value_in_time_column, FALSE);
3938-+
3939- /* STATE */
3940- if ((val= thread_state_info(tmp)))
3941- {
3942---- a/sql/sys_vars.cc
3943-+++ b/sql/sys_vars.cc
3944-@@ -972,6 +972,29 @@
3945- NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3946- ON_UPDATE(update_cached_long_query_time));
3947-
3948-+#ifndef DBUG_OFF
3949-+static bool update_cached_query_exec_time(sys_var *self, THD *thd,
3950-+ enum_var_type type)
3951-+{
3952-+ if (type == OPT_SESSION)
3953-+ thd->variables.query_exec_time=
3954-+ double2ulonglong(thd->variables.query_exec_time_double * 1e6);
3955-+ else
3956-+ global_system_variables.query_exec_time=
3957-+ double2ulonglong(global_system_variables.query_exec_time_double * 1e6);
3958-+ return false;
3959-+}
3960-+
3961-+static Sys_var_double Sys_query_exec_time(
3962-+ "query_exec_time",
3963-+ "Pretend queries take this many seconds. When 0 (the default) use the "
3964-+ "actual execution time. Used only for debugging.",
3965-+ SESSION_VAR(query_exec_time_double),
3966-+ NO_CMD_LINE, VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(0),
3967-+ NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
3968-+ ON_UPDATE(update_cached_query_exec_time));
3969-+#endif
3970-+
3971- static bool fix_low_prio_updates(sys_var *self, THD *thd, enum_var_type type)
3972- {
3973- if (type == OPT_SESSION)
3974-@@ -2898,6 +2921,123 @@
3975- DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3976- ON_UPDATE(fix_log_state));
3977-
3978-+const char *log_slow_filter_name[]= { "qc_miss", "full_scan", "full_join",
3979-+ "tmp_table", "tmp_table_on_disk", "filesort", "filesort_on_disk", 0};
3980-+static Sys_var_set Sys_log_slow_filter(
3981-+ "log_slow_filter",
3982-+ "Log only the queries that followed certain execution plan. "
3983-+ "Multiple flags allowed in a comma-separated string. "
3984-+ "[qc_miss, full_scan, full_join, tmp_table, tmp_table_on_disk, "
3985-+ "filesort, filesort_on_disk]",
3986-+ SESSION_VAR(log_slow_filter), CMD_LINE(REQUIRED_ARG),
3987-+ log_slow_filter_name, DEFAULT(0));
3988-+static Sys_var_ulong sys_log_slow_rate_limit(
3989-+ "log_slow_rate_limit","Rate limit statement writes to slow log to only those from every (1/log_slow_rate_limit) session.",
3990-+ SESSION_VAR(log_slow_rate_limit), CMD_LINE(REQUIRED_ARG),
3991-+ VALID_RANGE(1, ULONG_MAX), DEFAULT(1), BLOCK_SIZE(1));
3992-+const char* log_slow_verbosity_name[] = {
3993-+ "microtime", "query_plan", "innodb",
3994-+ "profiling", "profling_use_getrusage",
3995-+ "minimal", "standard", "full", 0
3996-+};
3997-+static ulonglong update_log_slow_verbosity_replace(ulonglong value, ulonglong what, ulonglong by)
3998-+{
3999-+ if((value & what) == what)
4000-+ {
4001-+ value = value & (~what);
4002-+ value = value | by;
4003-+ }
4004-+ return value;
4005-+}
4006-+void update_log_slow_verbosity(ulonglong* value_ptr)
4007-+{
4008-+ ulonglong &value = *value_ptr;
4009-+ ulonglong microtime= ULL(1) << SLOG_V_MICROTIME;
4010-+ ulonglong query_plan= ULL(1) << SLOG_V_QUERY_PLAN;
4011-+ ulonglong innodb= ULL(1) << SLOG_V_INNODB;
4012-+ ulonglong minimal= ULL(1) << SLOG_V_MINIMAL;
4013-+ ulonglong standard= ULL(1) << SLOG_V_STANDARD;
4014-+ ulonglong full= ULL(1) << SLOG_V_FULL;
4015-+ value= update_log_slow_verbosity_replace(value,minimal,microtime);
4016-+ value= update_log_slow_verbosity_replace(value,standard,microtime | query_plan);
4017-+ value= update_log_slow_verbosity_replace(value,full,microtime | query_plan | innodb);
4018-+}
4019-+static bool update_log_slow_verbosity_helper(sys_var */*self*/, THD *thd,
4020-+ enum_var_type type)
4021-+{
4022-+ if(type == OPT_SESSION)
4023-+ {
4024-+ update_log_slow_verbosity(&(thd->variables.log_slow_verbosity));
4025-+ }
4026-+ else
4027-+ {
4028-+ update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
4029-+ }
4030-+ return false;
4031-+}
4032-+void init_slow_query_log_use_global_control()
4033-+{
4034-+ update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
4035-+}
4036-+static Sys_var_set Sys_log_slow_verbosity(
4037-+ "log_slow_verbosity",
4038-+ "Choose how verbose the messages to your slow log will be. "
4039-+ "Multiple flags allowed in a comma-separated string. [microtime, query_plan, innodb, profiling, profiling_use_getrusage]",
4040-+ SESSION_VAR(log_slow_verbosity), CMD_LINE(REQUIRED_ARG),
4041-+ log_slow_verbosity_name, DEFAULT(SLOG_V_MICROTIME),
4042-+ NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
4043-+ ON_UPDATE(update_log_slow_verbosity_helper));
4044-+static Sys_var_mybool Sys_log_slow_slave_statements(
4045-+ "log_slow_slave_statements",
4046-+ "Log queries replayed be the slave SQL thread",
4047-+ GLOBAL_VAR(opt_log_slow_slave_statements), CMD_LINE(OPT_ARG),
4048-+ DEFAULT(FALSE));
4049-+static Sys_var_mybool Sys_log_slow_admin_statements(
4050-+ "log_slow_admin_statements",
4051-+ "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements"
4052-+ " to the slow log if it is open.",
4053-+ GLOBAL_VAR(opt_log_slow_admin_statements), CMD_LINE(OPT_ARG),
4054-+ DEFAULT(FALSE));
4055-+static Sys_var_mybool Sys_log_slow_sp_statements(
4056-+ "log_slow_sp_statements",
4057-+ "Log slow statements executed by stored procedure to the slow log if it is open.",
4058-+ GLOBAL_VAR(opt_log_slow_sp_statements), CMD_LINE(OPT_ARG),
4059-+ DEFAULT(TRUE));
4060-+static Sys_var_mybool Sys_slow_query_log_timestamp_always(
4061-+ "slow_query_log_timestamp_always",
4062-+ "Timestamp is printed for all records of the slow log even if they are same time.",
4063-+ GLOBAL_VAR(opt_slow_query_log_timestamp_always), CMD_LINE(OPT_ARG),
4064-+ DEFAULT(FALSE));
4065-+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};
4066-+static bool update_slow_query_log_use_global_control(sys_var */*self*/, THD */*thd*/,
4067-+ enum_var_type /*type*/)
4068-+{
4069-+ if(opt_slow_query_log_use_global_control & (ULL(1) << SLOG_UG_ALL))
4070-+ {
4071-+ opt_slow_query_log_use_global_control=
4072-+ SLOG_UG_LOG_SLOW_FILTER | SLOG_UG_LOG_SLOW_RATE_LIMIT | SLOG_UG_LOG_SLOW_VERBOSITY |
4073-+ SLOG_UG_LONG_QUERY_TIME | SLOG_UG_MIN_EXAMINED_ROW_LIMIT;
4074-+ }
4075-+ return false;
4076-+}
4077-+void init_log_slow_verbosity()
4078-+{
4079-+ update_slow_query_log_use_global_control(0,0,OPT_GLOBAL);
4080-+}
4081-+static Sys_var_set Sys_slow_query_log_use_global_control(
4082-+ "slow_query_log_use_global_control",
4083-+ "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]",
4084-+ GLOBAL_VAR(opt_slow_query_log_use_global_control), CMD_LINE(REQUIRED_ARG),
4085-+ slow_query_log_use_global_control_name, DEFAULT(0),
4086-+ NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
4087-+ ON_UPDATE(update_slow_query_log_use_global_control));
4088-+const char *slow_query_log_timestamp_precision_name[]= { "second", "microsecond", 0 };
4089-+static Sys_var_enum Sys_slow_query_log_timestamp_precision(
4090-+ "slow_query_log_timestamp_precision",
4091-+ "Log slow statements executed by stored procedure to the slow log if it is open. [second, microsecond]",
4092-+ GLOBAL_VAR(opt_slow_query_log_timestamp_precision), CMD_LINE(REQUIRED_ARG),
4093-+ slow_query_log_timestamp_precision_name, DEFAULT(SLOG_SECOND));
4094-+
4095- /* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
4096- static Sys_var_mybool Sys_log_slow(
4097- "log_slow_queries",
4098---- a/sql/sql_profile.cc
4099-+++ b/sql/sql_profile.cc
4100-@@ -243,7 +243,8 @@
4101- {
4102- time_usecs= (double) my_getsystime() / 10.0; /* 1 sec was 1e7, now is 1e6 */
4103- #ifdef HAVE_GETRUSAGE
4104-- getrusage(RUSAGE_SELF, &rusage);
4105-+ if ((profile->get_profiling())->enabled_getrusage())
4106-+ getrusage(RUSAGE_SELF, &rusage);
4107- #elif defined(_WIN32)
4108- FILETIME ftDummy;
4109- // NOTE: Get{Process|Thread}Times has a granularity of the clock interval,
4110-@@ -251,6 +252,19 @@
4111- // measurable by this function.
4112- GetProcessTimes(GetCurrentProcess(), &ftDummy, &ftDummy, &ftKernel, &ftUser);
4113- #endif
4114-+
4115-+#ifdef HAVE_CLOCK_GETTIME
4116-+ struct timespec tp;
4117-+
4118-+ if (!(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
4119-+ {
4120-+ cpu_time_usecs= tp.tv_sec*1000000000.0 + tp.tv_nsec;
4121-+ }
4122-+ else
4123-+#endif
4124-+ {
4125-+ cpu_time_usecs= 0;
4126-+ }
4127- }
4128-
4129-
4130-@@ -366,7 +380,8 @@
4131- finish_current_query();
4132- }
4133-
4134-- enabled= ((thd->variables.option_bits & OPTION_PROFILING) != 0);
4135-+ enabled= ((thd->variables.option_bits & OPTION_PROFILING) != 0) ||
4136-+ ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING)) != 0);
4137-
4138- if (! enabled) DBUG_VOID_RETURN;
4139-
4140-@@ -404,7 +419,8 @@
4141- status_change("ending", NULL, NULL, 0);
4142-
4143- if ((enabled) && /* ON at start? */
4144-- ((thd->variables.option_bits & OPTION_PROFILING) != 0) && /* and ON at end? */
4145-+ (((thd->variables.option_bits & OPTION_PROFILING) != 0) ||
4146-+ ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING)) != 0)) && /* and ON at end? */
4147- (current->query_source != NULL) &&
4148- (! current->entries.is_empty()))
4149- {
4150-@@ -505,6 +521,118 @@
4151- DBUG_VOID_RETURN;
4152- }
4153-
4154-+bool PROFILING::enabled_getrusage()
4155-+{
4156-+ return ((thd->variables.log_slow_verbosity & (ULL(1) << SLOG_V_PROFILING_USE_GETRUSAGE)) != 0);
4157-+}
4158-+
4159-+/**
4160-+ For a given profile entry specified by a name and 2 time measurements,
4161-+ print its normalized name (i.e. with all spaces replaced with underscores)
4162-+ along with its wall clock and CPU time.
4163-+*/
4164-+
4165-+static void my_b_print_status(IO_CACHE *log_file, const char *status,
4166-+ PROF_MEASUREMENT *start, PROF_MEASUREMENT *stop)
4167-+{
4168-+ DBUG_ENTER("my_b_print_status");
4169-+ DBUG_ASSERT(log_file != NULL && status != NULL);
4170-+ char query_time_buff[22+7];
4171-+ const char *tmp;
4172-+
4173-+ my_b_printf(log_file, "Profile_");
4174-+ for (tmp= status; *tmp; tmp++)
4175-+ my_b_write_byte(log_file, *tmp == ' ' ? '_' : *tmp);
4176-+
4177-+ snprintf(query_time_buff, sizeof(query_time_buff), "%.6f",
4178-+ (stop->time_usecs - start->time_usecs) / (1000.0 * 1000));
4179-+ my_b_printf(log_file, ": %s ", query_time_buff);
4180-+
4181-+ my_b_printf(log_file, "Profile_");
4182-+ for (tmp= status; *tmp; tmp++)
4183-+ my_b_write_byte(log_file, *tmp == ' ' ? '_' : *tmp);
4184-+ my_b_printf(log_file, "_cpu: ");
4185-+
4186-+ snprintf(query_time_buff, sizeof(query_time_buff), "%.6f",
4187-+ (stop->cpu_time_usecs - start->cpu_time_usecs) /
4188-+ (1000.0 * 1000 * 1000));
4189-+ my_b_printf(log_file, "%s ", query_time_buff);
4190-+
4191-+ DBUG_VOID_RETURN;
4192-+}
4193-+
4194-+/**
4195-+ Print output for current query to file
4196-+*/
4197-+
4198-+int PROFILING::print_current(IO_CACHE *log_file)
4199-+{
4200-+ DBUG_ENTER("PROFILING::print_current");
4201-+ ulonglong row_number= 0;
4202-+
4203-+ QUERY_PROFILE *query;
4204-+ /* Get current query */
4205-+ if (current == NULL)
4206-+ {
4207-+ DBUG_RETURN(0);
4208-+ }
4209-+
4210-+ query= current;
4211-+
4212-+ my_b_printf(log_file, "# ");
4213-+
4214-+ void *entry_iterator;
4215-+ PROF_MEASUREMENT *entry= NULL, *previous= NULL, *first= NULL;
4216-+ /* ...and for each query, go through all its state-change steps. */
4217-+ for (entry_iterator= query->entries.new_iterator();
4218-+ entry_iterator != NULL;
4219-+ entry_iterator= query->entries.iterator_next(entry_iterator),
4220-+ previous=entry, row_number++)
4221-+ {
4222-+ entry= query->entries.iterator_value(entry_iterator);
4223-+
4224-+ /* Skip the first. We count spans of fence, not fence-posts. */
4225-+ if (previous == NULL) {first= entry; continue;}
4226-+
4227-+ if (thd->lex->sql_command == SQLCOM_SHOW_PROFILE)
4228-+ {
4229-+ /*
4230-+ We got here via a SHOW command. That means that we stored
4231-+ information about the query we wish to show and that isn't
4232-+ in a WHERE clause at a higher level to filter out rows we
4233-+ wish to exclude.
4234-+
4235-+ Because that functionality isn't available in the server yet,
4236-+ we must filter here, at the wrong level. Once one can con-
4237-+ struct where and having conditions at the SQL layer, then this
4238-+ condition should be ripped out.
4239-+ */
4240-+ if (thd->lex->profile_query_id == 0) /* 0 == show final query */
4241-+ {
4242-+ if (query != last)
4243-+ continue;
4244-+ }
4245-+ else
4246-+ {
4247-+ if (thd->lex->profile_query_id != query->profiling_query_id)
4248-+ continue;
4249-+ }
4250-+ }
4251-+
4252-+ my_b_print_status(log_file, previous->status, previous, entry);
4253-+ }
4254-+
4255-+ my_b_write_byte(log_file, '\n');
4256-+ if ((entry != NULL) && (first != NULL))
4257-+ {
4258-+ my_b_printf(log_file, "# ");
4259-+ my_b_print_status(log_file, "total", first, entry);
4260-+ my_b_write_byte(log_file, '\n');
4261-+ }
4262-+
4263-+ DBUG_RETURN(0);
4264-+}
4265-+
4266- /**
4267- Fill the information schema table, "query_profile", as defined in show.cc .
4268- There are two ways to get to this function: Selecting from the information
4269-@@ -600,6 +728,8 @@
4270-
4271- #ifdef HAVE_GETRUSAGE
4272-
4273-+ if (enabled_getrusage())
4274-+ {
4275- my_decimal cpu_utime_decimal, cpu_stime_decimal;
4276-
4277- double2my_decimal(E_DEC_FATAL_ERROR,
4278-@@ -687,6 +817,7 @@
4279- table->field[14]->store((uint32)(entry->rusage.ru_nswap -
4280- previous->rusage.ru_nswap), true);
4281- table->field[14]->set_notnull();
4282-+ }
4283- #else
4284- /* TODO: Add swap info for non-BSD systems */
4285- #endif
4286---- a/sql/sql_profile.h
4287-+++ b/sql/sql_profile.h
4288-@@ -164,11 +164,15 @@
4289- */
4290- class PROF_MEASUREMENT
4291- {
4292--private:
4293-- friend class QUERY_PROFILE;
4294-- friend class PROFILING;
4295--
4296- QUERY_PROFILE *profile;
4297-+
4298-+ char *allocated_status_memory;
4299-+
4300-+ void set_label(const char *status_arg, const char *function_arg,
4301-+ const char *file_arg, unsigned int line_arg);
4302-+ void clean_up();
4303-+
4304-+public:
4305- char *status;
4306- #ifdef HAVE_GETRUSAGE
4307- struct rusage rusage;
4308-@@ -181,12 +185,7 @@
4309- unsigned int line;
4310-
4311- double time_usecs;
4312-- char *allocated_status_memory;
4313--
4314-- void set_label(const char *status_arg, const char *function_arg,
4315-- const char *file_arg, unsigned int line_arg);
4316-- void clean_up();
4317--
4318-+ double cpu_time_usecs;
4319- PROF_MEASUREMENT();
4320- PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char *status_arg);
4321- PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char *status_arg,
4322-@@ -231,6 +230,11 @@
4323-
4324- /* Show this profile. This is called by PROFILING. */
4325- bool show(uint options);
4326-+
4327-+public:
4328-+
4329-+ inline PROFILING * get_profiling() { return profiling; };
4330-+
4331- };
4332-
4333-
4334-@@ -276,9 +280,11 @@
4335-
4336- /* SHOW PROFILES */
4337- bool show_profiles();
4338-+ bool enabled_getrusage();
4339-
4340- /* ... from INFORMATION_SCHEMA.PROFILING ... */
4341- int fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond);
4342-+ int print_current(IO_CACHE *log_file);
4343- };
4344-
4345- # endif /* HAVE_PROFILING */
4346---- /dev/null
4347-+++ b/mysql-test/include/log_grep.inc
4348-@@ -0,0 +1,17 @@
4349-+--disable_query_log
4350-+--echo [log_grep.inc] file: $log_file pattern: $grep_pattern
4351-+perl;
4352-+ $log_file= $ENV{'log_file'};
4353-+ $log_file_full_path= $ENV{'log_file_full_path'};
4354-+ $grep_pattern= $ENV{'grep_pattern'};
4355-+
4356-+ open(FILE, "$log_file_full_path")
4357-+ or die("Cannot open file $log_file_full_path: $!\n");
4358-+
4359-+ $lines = 0;
4360-+ while(<FILE>) {
4361-+ $lines++ if (/$grep_pattern/);
4362-+ }
4363-+ close(FILE);
4364-+ print "[log_grep.inc] lines: $lines\n";
4365-+EOF
4366---- /dev/null
4367-+++ b/mysql-test/include/log_start.inc
4368-@@ -0,0 +1,16 @@
4369-+--disable_query_log
4370-+--let log_file_full_path = $MYSQLTEST_VARDIR/$log_file
4371-+SET @slow_query_log_old=@@slow_query_log;
4372-+SET @slow_query_log_file_old= @@slow_query_log_file;
4373-+SET GLOBAL slow_query_log=OFF;
4374-+perl;
4375-+ $log_file_full_path= $ENV{'log_file_full_path'};
4376-+ unlink $log_file_full_path;
4377-+ open(FILE, '>', $log_file_full_path)
4378-+ or die "Cannot create log file $log_file_full_path, reason: $!";
4379-+ close(FILE);
4380-+EOF
4381-+--echo [log_start.inc] $log_file
4382-+EVAL SET GLOBAL slow_query_log_file="$log_file_full_path";
4383-+SET GLOBAL slow_query_log=ON;
4384-+--enable_query_log
4385-\ No newline at end of file
4386---- /dev/null
4387-+++ b/mysql-test/include/log_stop.inc
4388-@@ -0,0 +1,7 @@
4389-+--disable_query_log
4390-+FLUSH LOGS;
4391-+SET GLOBAL slow_query_log=OFF;
4392-+--echo [log_stop.inc] $log_file
4393-+SET GLOBAL slow_query_log_file= @slow_query_log_file_old;
4394-+SET GLOBAL slow_query_log= @slow_query_log_old;
4395-+--enable_query_log
4396---- /dev/null
4397-+++ b/mysql-test/r/percona_bug643149.result
4398-@@ -0,0 +1,21 @@
4399-+SET @old_slow_query_log_file=@@global.slow_query_log_file;
4400-+SET GLOBAL slow_query_log=on;
4401-+SET LOCAL log_slow_verbosity='profiling';
4402-+SET LOCAL long_query_time=0;
4403-+SET GLOBAL slow_query_log_file='MYSQLTEST_VARDIR/percona_bug643149_slow.log';;
4404-+SELECT 1;
4405-+1
4406-+1
4407-+# User@Host: root[root] @ localhost []
4408-+# Thread_id: X Schema: test Last_errno: X Killed: X
4409-+# Query_time: X.X Lock_time: X.X Rows_sent: X Rows_examined: X Rows_affected: X Rows_read: X
4410-+# Bytes_sent: X Tmp_tables: X Tmp_disk_tables: X Tmp_table_sizes: X
4411-+# 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
4412-+# Profile_total: X.X Profile_total_cpu: X.X
4413-+# User@Host: root[root] @ localhost []
4414-+# Thread_id: X Schema: test Last_errno: X Killed: X
4415-+# Query_time: X.X Lock_time: X.X Rows_sent: X Rows_examined: X Rows_affected: X Rows_read: X
4416-+# Bytes_sent: X Tmp_tables: X Tmp_disk_tables: X Tmp_table_sizes: X
4417-+# 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
4418-+# Profile_total: X.X Profile_total_cpu: X.X
4419-+SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
4420---- /dev/null
4421-+++ b/mysql-test/r/percona_log_slow_filter-cl.result
4422-@@ -0,0 +1,6 @@
4423-+SHOW VARIABLES LIKE 'log_slow_filter';
4424-+Variable_name Value
4425-+log_slow_filter full_join
4426-+SHOW GLOBAL VARIABLES LIKE 'log_slow_filter';
4427-+Variable_name Value
4428-+log_slow_filter full_join
4429---- /dev/null
4430-+++ b/mysql-test/r/percona_log_slow_filter.result
4431-@@ -0,0 +1,15 @@
4432-+CREATE TABLE t(id INT PRIMARY KEY);
4433-+INSERT INTO t VALUES(1);
4434-+INSERT INTO t VALUES(2);
4435-+INSERT INTO t VALUES(3);
4436-+SET long_query_time=1;
4437-+SET log_slow_filter=full_join;
4438-+[log_start.inc] percona.slow_extended.log_slow_filter
4439-+SET query_exec_time = 1.1;
4440-+SELECT * FROM t AS t1, t AS t2;
4441-+SET query_exec_time = default;
4442-+[log_stop.inc] percona.slow_extended.log_slow_filter
4443-+SET log_slow_filter=default;
4444-+SET long_query_time=default;
4445-+[log_grep.inc] file: percona.slow_extended.log_slow_filter pattern: Query_time
4446-+[log_grep.inc] lines: 1
4447---- /dev/null
4448-+++ b/mysql-test/r/percona_log_slow_slave_statements-cl.result
4449-@@ -0,0 +1,6 @@
4450-+SHOW VARIABLES LIKE 'log_slow_slave_statements';
4451-+Variable_name Value
4452-+log_slow_slave_statements ON
4453-+SHOW GLOBAL VARIABLES LIKE 'log_slow_slave_statements';
4454-+Variable_name Value
4455-+log_slow_slave_statements ON
4456---- /dev/null
4457-+++ b/mysql-test/r/percona_log_slow_slave_statements-innodb.result
4458-@@ -0,0 +1,18 @@
4459-+include/master-slave.inc
4460-+[connection master]
4461-+DROP TABLE IF EXISTS t;
4462-+CREATE TABLE t(id INT,data CHAR(30)) ENGINE=InnoDB;
4463-+INSERT INTO t VALUES
4464-+(1,"aaaaabbbbbcccccdddddeeeeefffff"),
4465-+(2,"aaaaabbbbbcccccdddddeeeeefffff"),
4466-+(3,"aaaaabbbbbcccccdddddeeeeefffff"),
4467-+(4,"aaaaabbbbbcccccdddddeeeeefffff"),
4468-+(5,"aaaaabbbbbcccccdddddeeeeefffff");
4469-+INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
4470-+INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
4471-+[log_start.inc] percona.slow_extended.log_slow_slave_statements-innodb
4472-+INSERT INTO t SELECT t.id,t.data from t;
4473-+[log_stop.inc] percona.slow_extended.log_slow_slave_statements-innodb
4474-+[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements-innodb pattern: InnoDB_IO_r_ops
4475-+[log_grep.inc] lines: 1
4476-+include/rpl_end.inc
4477---- /dev/null
4478-+++ b/mysql-test/r/percona_log_slow_slave_statements.result
4479-@@ -0,0 +1,44 @@
4480-+include/master-slave.inc
4481-+[connection master]
4482-+DROP TABLE IF EXISTS t;
4483-+CREATE TABLE t(id INT);
4484-+[log_start.inc] percona.slow_extended.log_slow_slave_statements
4485-+LINE 1
4486-+LOG_SLOW_SLAVE_STATAMENTS is OFF
4487-+LOG_SLOW_SLAVE_STATEMENTS=ON
4488-+LOG_SLOW_SLAVE_STATAMENTS is ON
4489-+LINE 2
4490-+include/restart_slave.inc
4491-+LOG_SLOW_SLAVE_STATAMENTS is ON
4492-+LINE 3
4493-+LOG_SLOW_SLAVE_STATAMENTS is ON
4494-+LOG_SLOW_SLAVE_STATEMENTS=OFF
4495-+LOG_SLOW_SLAVE_STATAMENTS is OFF
4496-+LINE 4
4497-+include/restart_slave.inc
4498-+LOG_SLOW_SLAVE_STATAMENTS is OFF
4499-+LINE 5
4500-+LOG_SLOW_SLAVE_STATAMENTS is OFF
4501-+LOG_SLOW_SLAVE_STATEMENTS=ON
4502-+LOG_SLOW_SLAVE_STATAMENTS is ON
4503-+LINE 6
4504-+include/restart_slave.inc
4505-+LOG_SLOW_SLAVE_STATAMENTS is ON
4506-+LINE 7
4507-+[log_stop.inc] percona.slow_extended.log_slow_slave_statements
4508-+SET GLOBAL log_slow_slave_statements=default;
4509-+[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(1\)
4510-+[log_grep.inc] lines: 0
4511-+[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(2\)
4512-+[log_grep.inc] lines: 0
4513-+[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(3\)
4514-+[log_grep.inc] lines: 1
4515-+[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(4\)
4516-+[log_grep.inc] lines: 0
4517-+[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(5\)
4518-+[log_grep.inc] lines: 0
4519-+[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(6\)
4520-+[log_grep.inc] lines: 0
4521-+[log_grep.inc] file: percona.slow_extended.log_slow_slave_statements pattern: INSERT INTO t VALUES \(7\)
4522-+[log_grep.inc] lines: 1
4523-+include/rpl_end.inc
4524---- /dev/null
4525-+++ b/mysql-test/r/percona_log_slow_sp_statements-cl.result
4526-@@ -0,0 +1,6 @@
4527-+SHOW VARIABLES LIKE 'log_slow_sp_statements';
4528-+Variable_name Value
4529-+log_slow_sp_statements ON
4530-+SHOW GLOBAL VARIABLES LIKE 'log_slow_sp_statements';
4531-+Variable_name Value
4532-+log_slow_sp_statements ON
4533---- /dev/null
4534-+++ b/mysql-test/r/percona_log_slow_sp_statements.result
4535-@@ -0,0 +1,24 @@
4536-+SET long_query_time=1;
4537-+SET GLOBAL log_slow_sp_statements=ON;
4538-+SET SESSION query_exec_time=0.1;
4539-+[log_start.inc] percona.slow_extended.log_slow_sp_statements
4540-+CREATE PROCEDURE test_f()
4541-+BEGIN
4542-+SET SESSION query_exec_time=1.1; SELECT 1;
4543-+SET SESSION query_exec_time=2.1; SELECT 1;
4544-+SET SESSION query_exec_time=3.1; SELECT 1;
4545-+SET SESSION query_exec_time=0.1;
4546-+END^
4547-+CALL test_f();
4548-+1
4549-+1
4550-+1
4551-+1
4552-+1
4553-+1
4554-+[log_stop.inc] percona.slow_extended.log_slow_sp_statements
4555-+SET SESSION query_exec_time=default;
4556-+SET GLOBAL log_slow_sp_statements=default;
4557-+SET long_query_time=default;
4558-+[log_grep.inc] file: percona.slow_extended.log_slow_sp_statements pattern: Query_time
4559-+[log_grep.inc] lines: 3
4560---- /dev/null
4561-+++ b/mysql-test/r/percona_log_slow_verbosity-cl.result
4562-@@ -0,0 +1,6 @@
4563-+SHOW VARIABLES LIKE 'log_slow_verbosity';
4564-+Variable_name Value
4565-+log_slow_verbosity microtime,query_plan,innodb
4566-+SHOW GLOBAL VARIABLES LIKE 'log_slow_verbosity';
4567-+Variable_name Value
4568-+log_slow_verbosity microtime,query_plan,innodb
4569---- /dev/null
4570-+++ b/mysql-test/r/percona_log_slow_verbosity.result
4571-@@ -0,0 +1,16 @@
4572-+SET SESSION long_query_time=1;
4573-+[log_start.inc] percona.slow_extended.log_slow_verbosity
4574-+SET SESSION query_exec_time=2.1;
4575-+SELECT 1;
4576-+1
4577-+1
4578-+SET SESSION log_slow_verbosity=innodb;
4579-+SELECT 1;
4580-+1
4581-+1
4582-+SET SESSION query_exec_time=default;
4583-+[log_stop.inc] percona.slow_extended.log_slow_verbosity
4584-+SET log_slow_verbosity=default;
4585-+SET long_query_time=default;
4586-+[log_grep.inc] file: percona.slow_extended.log_slow_verbosity pattern: No InnoDB statistics available for this query
4587-+[log_grep.inc] lines: 1
4588---- /dev/null
4589-+++ b/mysql-test/r/percona_long_query_time.result
4590-@@ -0,0 +1,33 @@
4591-+SET long_query_time=2;
4592-+[log_start.inc] percona.slow_extended.long_query_time
4593-+SET SESSION query_exec_time=1.1;
4594-+SELECT 1;
4595-+1
4596-+1
4597-+SET SESSION query_exec_time=3.1;
4598-+SELECT 1;
4599-+1
4600-+1
4601-+SET SESSION query_exec_time=5.1;
4602-+SELECT 1;
4603-+1
4604-+1
4605-+SET long_query_time=4;
4606-+SET SESSION query_exec_time=1.1;
4607-+SELECT 1;
4608-+1
4609-+1
4610-+SET SESSION query_exec_time=3.1;
4611-+SELECT 1;
4612-+1
4613-+1
4614-+SET SESSION query_exec_time=5.1;
4615-+SELECT 1;
4616-+1
4617-+1
4618-+SET SESSION query_exec_time=default;
4619-+SET long_query_time=2;
4620-+[log_stop.inc] percona.slow_extended.long_query_time
4621-+SET long_query_time=default;
4622-+[log_grep.inc] file: percona.slow_extended.long_query_time pattern: Query_time
4623-+[log_grep.inc] lines: 3
4624---- /dev/null
4625-+++ b/mysql-test/r/percona_slow_query_log_timestamp_always-cl.result
4626-@@ -0,0 +1,6 @@
4627-+SHOW VARIABLES LIKE 'slow_query_log_timestamp_always';
4628-+Variable_name Value
4629-+slow_query_log_timestamp_always ON
4630-+SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_always';
4631-+Variable_name Value
4632-+slow_query_log_timestamp_always ON
4633---- /dev/null
4634-+++ b/mysql-test/r/percona_slow_query_log_timestamp_always.result
4635-@@ -0,0 +1,41 @@
4636-+SET long_query_time=2;
4637-+SET GLOBAL slow_query_log_timestamp_always=ON;
4638-+[log_start.inc] percona.slow_extended.slow_query_log_timestamp_always
4639-+SET SESSION query_exec_time=2.1;
4640-+SELECT 1;
4641-+1
4642-+1
4643-+SELECT 1;
4644-+1
4645-+1
4646-+SELECT 1;
4647-+1
4648-+1
4649-+SET GLOBAL slow_query_log_timestamp_always=OFF;
4650-+SET SESSION query_exec_time=2.1;
4651-+SELECT 1;
4652-+1
4653-+1
4654-+SELECT 1;
4655-+1
4656-+1
4657-+SELECT 1;
4658-+1
4659-+1
4660-+SET GLOBAL slow_query_log_timestamp_always=ON;
4661-+SET SESSION query_exec_time=2.1;
4662-+SELECT 1;
4663-+1
4664-+1
4665-+SELECT 1;
4666-+1
4667-+1
4668-+SELECT 1;
4669-+1
4670-+1
4671-+SET SESSION query_exec_time=default;
4672-+[log_stop.inc] percona.slow_extended.slow_query_log_timestamp_always
4673-+SET GLOBAL slow_query_log_timestamp_always=default;
4674-+SET long_query_time=default;
4675-+[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_always pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
4676-+[log_grep.inc] lines: 6
4677---- /dev/null
4678-+++ b/mysql-test/r/percona_slow_query_log_timestamp_precision-cl.result
4679-@@ -0,0 +1,6 @@
4680-+SHOW VARIABLES LIKE 'slow_query_log_timestamp_precision';
4681-+Variable_name Value
4682-+slow_query_log_timestamp_precision microsecond
4683-+SHOW GLOBAL VARIABLES LIKE 'slow_query_log_timestamp_precision';
4684-+Variable_name Value
4685-+slow_query_log_timestamp_precision microsecond
4686---- /dev/null
4687-+++ b/mysql-test/r/percona_slow_query_log_timestamp_precision.result
4688-@@ -0,0 +1,18 @@
4689-+SET long_query_time=2;
4690-+[log_start.inc] percona.slow_extended.slow_query_log_timestamp_precision
4691-+SET SESSION query_exec_time=2.1;
4692-+SELECT 1;
4693-+1
4694-+1
4695-+SET GLOBAL slow_query_log_timestamp_precision='microsecond';
4696-+SELECT 1;
4697-+1
4698-+1
4699-+SET SESSION query_exec_time=default;
4700-+[log_stop.inc] percona.slow_extended.slow_query_log_timestamp_precision
4701-+SET GLOBAL slow_query_log_timestamp_precision=default;
4702-+SET long_query_time=default;
4703-+[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_precision pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+.[0-9]+
4704-+[log_grep.inc] lines: 1
4705-+[log_grep.inc] file: percona.slow_extended.slow_query_log_timestamp_precision pattern: # Time: [0-9]+[ ]+[0-9]+:[0-9]+:[0-9]+
4706-+[log_grep.inc] lines: 2
4707---- /dev/null
4708-+++ b/mysql-test/r/percona_slow_query_log_use_global_control.result
4709-@@ -0,0 +1,18 @@
4710-+SET GLOBAL long_query_time=1;
4711-+[log_start.inc] percona.slow_extended.slow_query_log_use_global_control
4712-+SET SESSION query_exec_time=1.1;
4713-+SELECT 1;
4714-+1
4715-+1
4716-+SET GLOBAL log_slow_verbosity=innodb;
4717-+SET GLOBAL slow_query_log_use_global_control="log_slow_verbosity,long_query_time";
4718-+SELECT 1;
4719-+1
4720-+1
4721-+SET SESSION query_exec_time=default;
4722-+[log_stop.inc] percona.slow_extended.slow_query_log_use_global_control
4723-+SET GLOBAL slow_query_log_use_global_control=default;
4724-+SET GLOBAL log_slow_verbosity=default;
4725-+SET GLOBAL long_query_time=default;
4726-+[log_grep.inc] file: percona.slow_extended.slow_query_log_use_global_control pattern: No InnoDB statistics available for this query
4727-+[log_grep.inc] lines: 1
4728---- /dev/null
4729-+++ b/mysql-test/t/percona_bug643149.test
4730-@@ -0,0 +1,49 @@
4731-+#
4732-+# This test suffers from server
4733-+# Bug#38124 "general_log_file" variable silently unset when using expression
4734-+# In short:
4735-+# SET GLOBAL general_log_file = @<whatever>
4736-+# SET GLOBAL slow_query_log = @<whatever>
4737-+# cause that the value of these server system variables is set to default
4738-+# instead of the assigned values. There comes no error message or warning.
4739-+# If this bug is fixed please
4740-+# 1. try this test with "let $fixed_bug38124 = 0;"
4741-+# 2. remove all workarounds if 1. was successful.
4742-+--source include/have_profiling.inc
4743-+let $fixed_bug38124 = 0;
4744-+
4745-+SET @old_slow_query_log_file=@@global.slow_query_log_file;
4746-+SET GLOBAL slow_query_log=on;
4747-+SET LOCAL log_slow_verbosity='profiling';
4748-+SET LOCAL long_query_time=0;
4749-+
4750-+let slogfile=$MYSQLTEST_VARDIR/percona_bug643149_slow.log;
4751-+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
4752-+--eval SET GLOBAL slow_query_log_file='$slogfile';
4753-+
4754-+SELECT 1;
4755-+
4756-+perl;
4757-+ $slogfile= $ENV{'slogfile'};
4758-+
4759-+ open(FILE, "$slogfile") or
4760-+ die("Unable to read slow query log file $slogfile: $!\n");
4761-+ while(<FILE>) {
4762-+ next if (!/^#/);
4763-+ next if (/^# Time:/);
4764-+ s/[0-9]+/X/g;
4765-+ print;
4766-+ }
4767-+
4768-+ close(FILE);
4769-+EOF
4770-+
4771-+SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
4772-+
4773-+if(!$fixed_bug38124)
4774-+{
4775-+ --disable_query_log
4776-+ let $my_var = `SELECT @old_slow_query_log_file`;
4777-+ eval SET @@global.slow_query_log_file = '$my_var';
4778-+ --enable_query_log
4779-+}
4780---- /dev/null
4781-+++ b/mysql-test/t/percona_log_slow_filter-cl-master.opt
4782-@@ -0,0 +1 @@
4783-+--log_slow_filter=full_join
4784---- /dev/null
4785-+++ b/mysql-test/t/percona_log_slow_filter-cl.test
4786-@@ -0,0 +1,2 @@
4787-+SHOW VARIABLES LIKE 'log_slow_filter';
4788-+SHOW GLOBAL VARIABLES LIKE 'log_slow_filter';
4789---- /dev/null
4790-+++ b/mysql-test/t/percona_log_slow_filter.test
4791-@@ -0,0 +1,26 @@
4792-+--source include/have_debug.inc
4793-+
4794-+CREATE TABLE t(id INT PRIMARY KEY);
4795-+INSERT INTO t VALUES(1);
4796-+INSERT INTO t VALUES(2);
4797-+INSERT INTO t VALUES(3);
4798-+
4799-+SET long_query_time=1;
4800-+SET log_slow_filter=full_join;
4801-+--let log_file=percona.slow_extended.log_slow_filter
4802-+--source include/log_start.inc
4803-+
4804-+SET query_exec_time = 1.1;
4805-+--disable_result_log
4806-+SELECT * FROM t AS t1, t AS t2;
4807-+--enable_result_log
4808-+SET query_exec_time = default;
4809-+
4810-+--source include/log_stop.inc
4811-+SET log_slow_filter=default;
4812-+SET long_query_time=default;
4813-+
4814-+--let grep_pattern = Query_time
4815-+--source include/log_grep.inc
4816-+
4817-+DROP TABLE t;
4818---- /dev/null
4819-+++ b/mysql-test/t/percona_log_slow_slave_statements-cl-master.opt
4820-@@ -0,0 +1 @@
4821-+--log_slow_slave_statements
4822-\ No newline at end of file
4823---- /dev/null
4824-+++ b/mysql-test/t/percona_log_slow_slave_statements-cl.test
4825-@@ -0,0 +1,3 @@
4826-+SHOW VARIABLES LIKE 'log_slow_slave_statements';
4827-+SHOW GLOBAL VARIABLES LIKE 'log_slow_slave_statements';
4828-+
4829---- /dev/null
4830-+++ b/mysql-test/t/percona_log_slow_slave_statements-innodb-slave.opt
4831-@@ -0,0 +1 @@
4832-+--long_query_time=0 --log_slow_slave_statements --log_slow_verbosity=innodb
4833-\ No newline at end of file
4834---- /dev/null
4835-+++ b/mysql-test/t/percona_log_slow_slave_statements-innodb.test
4836-@@ -0,0 +1,42 @@
4837-+--source include/have_binlog_format_statement.inc
4838-+--source include/master-slave.inc
4839-+--source include/have_innodb.inc
4840-+--let log_file=percona.slow_extended.log_slow_slave_statements-innodb
4841-+
4842-+connection master;
4843-+-- disable_warnings
4844-+DROP TABLE IF EXISTS t;
4845-+-- enable_warnings
4846-+
4847-+CREATE TABLE t(id INT,data CHAR(30)) ENGINE=InnoDB;
4848-+INSERT INTO t VALUES
4849-+(1,"aaaaabbbbbcccccdddddeeeeefffff"),
4850-+(2,"aaaaabbbbbcccccdddddeeeeefffff"),
4851-+(3,"aaaaabbbbbcccccdddddeeeeefffff"),
4852-+(4,"aaaaabbbbbcccccdddddeeeeefffff"),
4853-+(5,"aaaaabbbbbcccccdddddeeeeefffff");
4854-+INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
4855-+INSERT INTO t SELECT t2.id,t2.data from t as t1, t as t2;
4856-+sync_slave_with_master;
4857-+
4858-+connection slave;
4859-+--source include/log_start.inc
4860-+
4861-+connection master;
4862-+INSERT INTO t SELECT t.id,t.data from t;
4863-+sync_slave_with_master;
4864-+
4865-+connection slave;
4866-+--source include/log_stop.inc
4867-+
4868-+--enable_query_log
4869-+--enable_result_log
4870-+
4871-+--let grep_pattern = InnoDB_IO_r_ops
4872-+--source include/log_grep.inc
4873-+
4874-+connection master;
4875-+DROP TABLE t;
4876-+sync_slave_with_master;
4877-+
4878-+--source include/rpl_end.inc
4879---- /dev/null
4880-+++ b/mysql-test/t/percona_log_slow_slave_statements-slave.opt
4881-@@ -0,0 +1 @@
4882-+--long_query_time=0
4883-\ No newline at end of file
4884---- /dev/null
4885-+++ b/mysql-test/t/percona_log_slow_slave_statements.test
4886-@@ -0,0 +1,117 @@
4887-+-- source include/have_binlog_format_statement.inc
4888-+-- source include/master-slave.inc
4889-+--let log_file=percona.slow_extended.log_slow_slave_statements
4890-+--let show=SELECT Variable_value FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE Variable_name LIKE 'log_slow_slave_statements';
4891-+
4892-+connection master;
4893-+-- disable_warnings
4894-+DROP TABLE IF EXISTS t;
4895-+-- enable_warnings
4896-+
4897-+CREATE TABLE t(id INT);
4898-+sync_slave_with_master;
4899-+
4900-+connection slave;
4901-+--source include/log_start.inc
4902-+
4903-+--disable_query_log
4904-+--disable_result_log
4905-+
4906-+--echo LINE 1
4907-+connection master;
4908-+INSERT INTO t VALUES (1);
4909-+sync_slave_with_master;
4910-+
4911-+connection slave;
4912-+--let value=`$show`
4913-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4914-+--echo LOG_SLOW_SLAVE_STATEMENTS=ON
4915-+SET GLOBAL log_slow_slave_statements=ON;
4916-+--let value=`$show`
4917-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4918-+
4919-+--echo LINE 2
4920-+connection master;
4921-+INSERT INTO t VALUES (2);
4922-+sync_slave_with_master;
4923-+
4924-+--source include/restart_slave_sql.inc
4925-+
4926-+connection slave;
4927-+--let value=`$show`
4928-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4929-+
4930-+--echo LINE 3
4931-+connection master;
4932-+INSERT INTO t VALUES (3);
4933-+sync_slave_with_master;
4934-+
4935-+connection slave;
4936-+--let value=`$show`
4937-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4938-+--echo LOG_SLOW_SLAVE_STATEMENTS=OFF
4939-+SET GLOBAL log_slow_slave_statements=OFF;
4940-+--let value=`$show`
4941-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4942-+
4943-+--echo LINE 4
4944-+connection master;
4945-+INSERT INTO t VALUES (4);
4946-+sync_slave_with_master;
4947-+
4948-+--source include/restart_slave_sql.inc
4949-+
4950-+connection slave;
4951-+--let value=`$show`
4952-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4953-+
4954-+--echo LINE 5
4955-+connection master;
4956-+INSERT INTO t VALUES (5);
4957-+sync_slave_with_master;
4958-+
4959-+connection slave;
4960-+--let value=`$show`
4961-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4962-+--echo LOG_SLOW_SLAVE_STATEMENTS=ON
4963-+SET GLOBAL log_slow_slave_statements=ON;
4964-+--let value=`$show`
4965-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4966-+
4967-+--echo LINE 6
4968-+connection master;
4969-+INSERT INTO t VALUES (6);
4970-+sync_slave_with_master;
4971-+
4972-+--source include/restart_slave_sql.inc
4973-+
4974-+connection slave;
4975-+--let value=`$show`
4976-+--echo LOG_SLOW_SLAVE_STATAMENTS is $value
4977-+
4978-+--echo LINE 7
4979-+connection master;
4980-+INSERT INTO t VALUES (7);
4981-+sync_slave_with_master;
4982-+
4983-+--enable_query_log
4984-+--enable_result_log
4985-+
4986-+connection slave;
4987-+--source include/log_stop.inc
4988-+SET GLOBAL log_slow_slave_statements=default;
4989-+
4990-+connection slave;
4991-+--let i=1
4992-+while($i < 8)
4993-+{
4994-+--let grep_pattern= INSERT INTO t VALUES \($i\)
4995-+--source include/log_grep.inc
4996-+ inc $i;
4997-+}
4998-+
4999-+connection master;
5000-+DROP TABLE t;
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches