From 5cce618f861af8dc5d5f310ee373c283a9023b31 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Fri, 3 May 2013 10:19:42 -0300 Subject: [PATCH 1/2] Fix for 1176010: pt-query-digest should know how to group quoted and unquoted database names --- bin/pt-query-digest | 19 ++++++++-- t/lib/samples/slowlogs/slow057.txt | 23 ++++++++++++ t/pt-query-digest/samples/slow057.txt | 52 +++++++++++++++++++++++++++ t/pt-query-digest/slowlog_analyses.t | 12 +++++++ 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 t/lib/samples/slowlogs/slow057.txt create mode 100644 t/pt-query-digest/samples/slow057.txt diff --git a/bin/pt-query-digest b/bin/pt-query-digest index a3d6c2b2..e02ccf3b 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -12940,13 +12940,16 @@ sub main { return [ grep { $_->[0] != $cxn } @{ $sth->fetchall_arrayref(); } ]; }; - + $pipeline->add( name => ref $pl, process => sub { my ( $args ) = @_; my $event = $pl->parse_event(code => $code); - $args->{event} = $event if $event; + if ( $event ) { + sanitize_event($event); + $args->{event} = $event; + } return $args; }, ); @@ -13006,6 +13009,7 @@ sub main { stats => $args->{stats}, ); if ( $event ) { + sanitize_event($event); $args->{event} = $event; return $args; } @@ -14229,6 +14233,17 @@ sub save_resume_offset { return; } +# Quoted and unquoted values should be treated the same +# See https://bugs.launchpad.net/percona-toolkit/+bug/1176010 +sub sanitize_event { + my ($event) = @_; + foreach my $value ( values %$event ) { + if ( $value && $value =~ /\A`(.+)`\z/sm ) { + $value = $1 + } + } +} + sub _d { my ($package, undef, $line) = caller 0; @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } diff --git a/t/lib/samples/slowlogs/slow057.txt b/t/lib/samples/slowlogs/slow057.txt new file mode 100644 index 00000000..f84c887c --- /dev/null +++ b/t/lib/samples/slowlogs/slow057.txt @@ -0,0 +1,23 @@ +# User@Host: meow[meow] @ [1.2.3.8] +# Thread_id: 5 Schema: db +# Query_time: 0.000002 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 +# No InnoDB statistics available for this query +# administrator command: Quit; +# User@Host: meow[meow] @ [1.2.3.8] +# Thread_id: 6 Schema: db2 +# Query_time: 0.000899 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 +# No InnoDB statistics available for this query +use db; +SET NAMES utf8; +# User@Host: meow[meow] @ [1.2.3.8] +# Thread_id: 7 Schema: db +# Query_time: 0.018799 Lock_time: 0.009453 Rows_sent: 0 Rows_examined: 0 +# No InnoDB statistics available for this query +use `db`; +# administrator command: Quit; +# User@Host: meow[meow] @ [1.2.3.8] +# Thread_id: 9 Schema: db2 +# Query_time: 0.000899 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 +# No InnoDB statistics available for this query +use db; +SET NAMES utf8; diff --git a/t/pt-query-digest/samples/slow057.txt b/t/pt-query-digest/samples/slow057.txt new file mode 100644 index 00000000..042be145 --- /dev/null +++ b/t/pt-query-digest/samples/slow057.txt @@ -0,0 +1,52 @@ + +# Query 1: 0 QPS, 0x concurrency, ID 0xAA353644DE4C4CB4 at byte 434 ______ +# This item is included in the report because it matches --limit. +# Scores: V/M = 0.02 +# Attribute pct total min max avg 95% stddev median +# ============ === ======= ======= ======= ======= ======= ======= ======= +# Count 50 2 +# Exec time 91 19ms 2us 19ms 9ms 19ms 13ms 9ms +# Lock time 100 9ms 0 9ms 5ms 9ms 7ms 5ms +# Rows sent 0 0 0 0 0 0 0 0 +# Rows examine 0 0 0 0 0 0 0 0 +# Query size 65 54 27 27 27 27 0 27 +# String: +# Databases db +# Hosts +# Users meow +# Query_time distribution +# 1us ################################################################ +# 10us +# 100us +# 1ms +# 10ms ################################################################ +# 100ms +# 1s +# 10s+ +administrator command: Quit\G + +# Query 2: 0 QPS, 0x concurrency, ID 0xCC47B42511EA22DD at byte 662 ______ +# This item is included in the report because it matches --limit. +# Scores: V/M = 0.00 +# Attribute pct total min max avg 95% stddev median +# ============ === ======= ======= ======= ======= ======= ======= ======= +# Count 50 2 +# Exec time 8 2ms 899us 899us 899us 899us 0 899us +# Lock time 0 0 0 0 0 0 0 0 +# Rows sent 0 0 0 0 0 0 0 0 +# Rows examine 0 0 0 0 0 0 0 0 +# Query size 34 28 14 14 14 14 0 14 +# String: +# Databases db +# Hosts +# Users meow +# Query_time distribution +# 1us +# 10us +# 100us ################################################################ +# 1ms +# 10ms +# 100ms +# 1s +# 10s+ +SET NAMES utf8\G diff --git a/t/pt-query-digest/slowlog_analyses.t b/t/pt-query-digest/slowlog_analyses.t index 634eb4c5..5c3eb68f 100644 --- a/t/pt-query-digest/slowlog_analyses.t +++ b/t/pt-query-digest/slowlog_analyses.t @@ -393,6 +393,18 @@ ok( 'Analysis for slow056 (no query bug 1082599)' ); +# ############################################################################# +# Bug 1176010: pt-query-digest should know how to group quoted and unquoted database names +# https://bugs.launchpad.net/percona-toolkit/+bug/1176010 +############################################################################# +ok( + no_diff( + sub { pt_query_digest::main(@args, $sample.'slow057.txt') }, + "t/pt-query-digest/samples/slow057.txt", + ), + 'Analysis for slow057 (no grouping bug 1176010)' +); + # ############################################################################# # Done. # ############################################################################# From 53881e3d99d92d3f128f55a153ec506ae140d110 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 26 Jun 2013 16:06:29 -0700 Subject: [PATCH 2/2] Tweak sanitize_evnet(). --- bin/pt-query-digest | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/pt-query-digest b/bin/pt-query-digest index e02ccf3b..089ecd51 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -12940,7 +12940,7 @@ sub main { return [ grep { $_->[0] != $cxn } @{ $sth->fetchall_arrayref(); } ]; }; - + $pipeline->add( name => ref $pl, process => sub { @@ -14233,15 +14233,21 @@ sub save_resume_offset { return; } -# Quoted and unquoted values should be treated the same -# See https://bugs.launchpad.net/percona-toolkit/+bug/1176010 sub sanitize_event { my ($event) = @_; - foreach my $value ( values %$event ) { - if ( $value && $value =~ /\A`(.+)`\z/sm ) { - $value = $1 - } + + # Quoted and unquoted values should be treated the same + # https://bugs.launchpad.net/percona-toolkit/+bug/1176010 + if ( $event->{db} ) { + $event->{db} =~ s/^`//; + $event->{db} =~ s/`$//; } + if ( $event->{Schema} ) { + $event->{Schema} =~ s/^`//; + $event->{Schema} =~ s/`$//; + } + + return; } sub _d {