diff --git a/bin/pt-query-digest b/bin/pt-query-digest index a0d0c8e7..08fb9a82 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -7924,8 +7924,9 @@ override query_report => sub { query_count => $times_seen, $args{anon} ? () : ( example => { - query => substr($sample->{arg}, 0, $self->max_query_length), - ts => $sample->{ts} ? parse_timestamp($sample->{ts}) : undef, + query => substr($sample->{arg}, 0, $self->max_query_length), + ts => $sample->{ts} ? parse_timestamp($sample->{ts}) : undef, + Query_time => $sample->{Query_time}, }, ), }; @@ -10311,8 +10312,16 @@ use constant PTDEBUG => $ENV{PTDEBUG} || 0; sub check_recursion_method { my ($methods) = @_; - if ( @$methods != 1 ) { - if ( grep({ !m/processlist|hosts/i } @$methods) + foreach my $method ( @$methods ) { + die "Invalid recursion method: " . ($method || 'undef') . "\n" + unless $method && $method =~ m/^(?:processlist$|hosts$|none$|cluster|dsn=)/i; + } + + if ( @$methods > 1 ) { + if ( grep( { m/none/ } @$methods) && grep( {! m/none/ } @$methods) ) { + die "--recursion-method=none cannot be combined with other methods\n"; + } + elsif ( grep({ !m/processlist|hosts/i } @$methods) && $methods->[0] !~ /^dsn=/i ) { die "Invalid combination of recursion methods: " @@ -10320,11 +10329,8 @@ sub check_recursion_method { . "Only hosts and processlist may be combined.\n" } } - else { - my ($method) = @$methods; - die "Invalid recursion method: " . ( $method || 'undef' ) - unless $method && $method =~ m/^(?:processlist$|hosts$|none$|dsn=)/i; - } + + return; } sub new { diff --git a/lib/JSONReportFormatter.pm b/lib/JSONReportFormatter.pm index 4e8fa320..badbc267 100644 --- a/lib/JSONReportFormatter.pm +++ b/lib/JSONReportFormatter.pm @@ -230,8 +230,9 @@ override query_report => sub { query_count => $times_seen, $args{anon} ? () : ( example => { - query => substr($sample->{arg}, 0, $self->max_query_length), - ts => $sample->{ts} ? parse_timestamp($sample->{ts}) : undef, + query => substr($sample->{arg}, 0, $self->max_query_length), + ts => $sample->{ts} ? parse_timestamp($sample->{ts}) : undef, + Query_time => $sample->{Query_time}, }, ), }; diff --git a/t/lib/samples/JSONReportFormatter/report001.json b/t/lib/samples/JSONReportFormatter/report001.json index 27d57183..04030785 100644 --- a/t/lib/samples/JSONReportFormatter/report001.json +++ b/t/lib/samples/JSONReportFormatter/report001.json @@ -5,6 +5,7 @@ "checksum" : "82860EDA9A88FCC5", "distillate" : "SELECT users", "example" : { + "Query_time" : "8.000652", "query" : "SELECT id FROM users WHERE name='foo'", "ts" : "2007-10-15 21:43:52" }, @@ -84,6 +85,7 @@ "checksum" : "1087A32FED3B7EBB", "distillate" : "INSERT articles", "example" : { + "Query_time" : "1.001943", "query" : "INSERT IGNORE INTO articles (id, body,)VALUES(3558268,'sample text')", "ts" : "2007-10-15 21:43:52" }, diff --git a/t/pt-query-digest/samples/json/slow002.txt b/t/pt-query-digest/samples/json/slow002.txt index cfe365ed..45c102b3 100644 --- a/t/pt-query-digest/samples/json/slow002.txt +++ b/t/pt-query-digest/samples/json/slow002.txt @@ -6,6 +6,7 @@ "checksum" : "66825DDC008FFA89", "distillate" : "UPDATE db?.tuningdetail_?_? db?.gonzo", "example" : { + "Query_time" : "0.726052", "as_select" : "select n.column1 = a.column1, n.word3 = a.word3 from db2.tuningdetail_21_265507 n\n inner join db1.gonzo a using(gonzo) ", "query" : "update db2.tuningdetail_21_265507 n\n inner join db1.gonzo a using(gonzo) \n set n.column1 = a.column1, n.word3 = a.word3", "ts" : "2007-12-18 11:48:27" diff --git a/t/pt-query-digest/samples/json/tcpdump021.txt b/t/pt-query-digest/samples/json/tcpdump021.txt index 22ec71a3..cd2ae6b5 100644 --- a/t/pt-query-digest/samples/json/tcpdump021.txt +++ b/t/pt-query-digest/samples/json/tcpdump021.txt @@ -6,6 +6,7 @@ "checksum" : "AA8E9FA785927259", "distillate" : "SELECT d.t", "example" : { + "Query_time" : "0.000286", "as_select" : "SELECT i FROM d.t WHERE i=?", "query" : "PREPARE SELECT i FROM d.t WHERE i=?", "ts" : "2009-12-08 09:23:49.637394" @@ -82,6 +83,7 @@ "checksum" : "3F79759E7FA2F117", "distillate" : "SELECT d.t", "example" : { + "Query_time" : "0.000281", "as_select" : "SELECT i FROM d.t WHERE i=\"3\"", "query" : "EXECUTE SELECT i FROM d.t WHERE i=\"3\"", "ts" : "2009-12-08 09:23:49.637892" @@ -158,6 +160,7 @@ "checksum" : "AA353644DE4C4CB4", "distillate" : "ADMIN QUIT", "example" : { + "Query_time" : "0.000000", "query" : "administrator command: Quit", "ts" : "2009-12-08 09:23:49.638381" },