Skip to content

Commit c47d3c2

Browse files
author
Anushree Prakash B
committed
Bug#24007040 - MYSQLDUMPSLOW ON MYSQL 5.7 DOESN'T FOLLOW
DATETIME FORMAT CHANGE DESCRIPTION: ============ On MySQL 5.7, make_iso8601_timestamp() is used to build timestamp string. This format is different from the timestamp format of the previous versions. As a result, mysqldumpslow cannot identify each entry and fails to summarize the queries in slow-query-log. ANALYSIS: ========= The script's earlier regex pattern was not able to parse the iso8601 timestamp format. As per the iso8601 timestamp format, the timestamp can either be in the form of YYYY-MM-DDTHH:MM:SS.SZ or YYYY-MM-DDTHH:MM:SS.S[+-]HH:MM FIX ==== Change the regex pattern for the timestamp according to the iso8601 timestamp pattern. mysqldumpslow script should then be able to summarize the queries correctly.
1 parent cfbb8e0 commit c47d3c2

File tree

4 files changed

+115
-4
lines changed

4 files changed

+115
-4
lines changed

mysql-test/mysql-test-run.pl

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/perl
22
# -*- cperl -*-
33

4-
# Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
4+
# Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -2777,6 +2777,17 @@ sub environment_setup {
27772777
$ENV{'MYSQLD_SAFE'}= $mysqld_safe;
27782778
}
27792779

2780+
# ----------------------------------------------------
2781+
# mysqldumpslow
2782+
# ----------------------------------------------------
2783+
my $mysqldumpslow=
2784+
mtr_pl_maybe_exists("$bindir/scripts/mysqldumpslow") ||
2785+
mtr_pl_maybe_exists("$path_client_bindir/mysqldumpslow");
2786+
if ($mysqldumpslow)
2787+
{
2788+
$ENV{'MYSQLDUMPSLOW'}= $mysqldumpslow;
2789+
}
2790+
27802791

27812792
# ----------------------------------------------------
27822793
# perror
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
SET @old_log_output= @@global.log_output;
2+
SET @old_slow_query_log= @@global.slow_query_log;
3+
SET @old_slow_query_log_file= @@global.slow_query_log_file;
4+
SET GLOBAL slow_query_log_file= '.../log/slow_query_temp.log';
5+
SET GLOBAL log_output= 'FILE';
6+
SET GLOBAL slow_query_log= 'ON';
7+
SET SESSION long_query_time= 0;
8+
SHOW VARIABLES LIKE "%long_query_time%";
9+
Variable_name Value
10+
long_query_time 0.000000
11+
SHOW VARIABLES LIKE "%long_query_time%";
12+
Variable_name Value
13+
long_query_time 0.000000
14+
SHOW VARIABLES LIKE "%long_query_time%";
15+
Variable_name Value
16+
long_query_time 0.000000
17+
SHOW VARIABLES LIKE "%long_query_time%";
18+
Variable_name Value
19+
long_query_time 0.000000
20+
SHOW VARIABLES LIKE "%long_query_time%";
21+
Variable_name Value
22+
long_query_time 0.000000
23+
SELECT 1;
24+
1
25+
1
26+
SELECT 1;
27+
1
28+
1
29+
SELECT 1;
30+
1
31+
1
32+
SELECT 1;
33+
1
34+
1
35+
"Running mysqldumpslow on the slow-query-log"
36+
Count: 5 SHOW VARIABLES LIKE "%long_query_time%"
37+
38+
Count: 4 SELECT 1
39+
40+
Count: 1 SET SESSION long_query_time= 0
41+
42+
SET GLOBAL log_output= @old_log_output;
43+
SET GLOBAL slow_query_log= @old_slow_query_log;
44+
SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
45+
End of test!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# === Purpose ===
2+
#
3+
# This test case will verify that the mysqldumpslow script
4+
# correctly parses the iso8601 timestamp and is able
5+
# to summarize the queries correctly.
6+
#
7+
# ==== Related Bugs and Worklogs ====
8+
#
9+
# Bug#24007040 - MYSQLDUMPSLOW ON MYSQL 5.7 DOESN'T FOLLOW
10+
# DATETIME FORMAT CHANGE
11+
#
12+
--source include/not_embedded.inc
13+
--source include/not_windows.inc
14+
15+
# Save the old values of these variables to be restored at the end
16+
SET @old_log_output= @@global.log_output;
17+
SET @old_slow_query_log= @@global.slow_query_log;
18+
SET @old_slow_query_log_file= @@global.slow_query_log_file;
19+
20+
# Enable the logging of queries to slow-query-log.
21+
# For testing purpose, let's log all the queries.
22+
--replace_result $MYSQLTEST_VARDIR ...
23+
eval SET GLOBAL slow_query_log_file= '$MYSQLTEST_VARDIR/log/slow_query_temp.log';
24+
SET GLOBAL log_output= 'FILE';
25+
SET GLOBAL slow_query_log= 'ON';
26+
SET SESSION long_query_time= 0;
27+
28+
# Populating the slow-query-log with more than one identical queries.
29+
let $1= 5;
30+
while ($1)
31+
{
32+
SHOW VARIABLES LIKE "%long_query_time%";
33+
dec $1;
34+
}
35+
36+
let $2= 4;
37+
while($2)
38+
{
39+
SELECT 1;
40+
dec $2;
41+
}
42+
43+
# Run mysqldumpslow
44+
--echo "Running mysqldumpslow on the slow-query-log"
45+
# Masking out the non-deterministic parameters from the results.
46+
--replace_regex /Time.*//
47+
--exec $MYSQLDUMPSLOW '$MYSQLTEST_VARDIR/log/slow_query_temp.log' -a -s c
48+
49+
# clean-up
50+
--remove_file $MYSQLTEST_VARDIR/log/slow_query_temp.log
51+
SET GLOBAL log_output= @old_log_output;
52+
SET GLOBAL slow_query_log= @old_slow_query_log;
53+
SET GLOBAL slow_query_log_file=@old_slow_query_log_file;
54+
55+
--echo End of test!

scripts/mysqldumpslow.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/usr/bin/perl
1+
#!/usr/bin/env perl
22

3-
# Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
44
#
55
# This program is free software; you can redistribute it and/or
66
# modify it under the terms of the GNU Library General Public
@@ -98,7 +98,7 @@ while ( defined($_ = shift @pending) or defined($_ = <>) ) {
9898
next;
9999
}
100100

101-
s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//;
101+
s/^#? Time: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+(Z|[+-]\d{2}:\d{2}).*\n//;
102102
my ($user,$host,$dummy,$thread_id) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+)\s+\S+(\s+Id:\s+(\d+))?.*\n// ? ($1,$2,$3,$4) : ('','','','','');
103103

104104
s/^# Query_time: ([0-9.]+)\s+Lock_time: ([0-9.]+)\s+Rows_sent: ([0-9.]+).*\n//;

0 commit comments

Comments
 (0)