From 90598531361b2e24079a13f2ce0e7e20f18494f5 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Sat, 3 Aug 2013 14:01:25 -0700 Subject: [PATCH 1/3] Handle IF [NOT] EXITS for ddl statements in distill. --- lib/QueryRewriter.pm | 2 ++ t/lib/QueryRewriter.t | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/QueryRewriter.pm b/lib/QueryRewriter.pm index da57f202..aed3832b 100644 --- a/lib/QueryRewriter.pm +++ b/lib/QueryRewriter.pm @@ -298,6 +298,8 @@ sub distill_verbs { eval $QueryParser::tbl_ident; my ( $dds ) = $query =~ /^\s*($QueryParser::data_def_stmts)\b/i; if ( $dds) { + # https://bugs.launchpad.net/percona-toolkit/+bug/821690 + $query =~ s/\s+IF(?:\s+NOT)?\s+EXISTS/ /i; my ( $obj ) = $query =~ m/$dds.+(DATABASE|TABLE)\b/i; $obj = uc $obj if $obj; PTDEBUG && _d('Data def statment:', $dds, 'obj:', $obj); diff --git a/t/lib/QueryRewriter.t b/t/lib/QueryRewriter.t index 269ae97a..4b6d6c61 100644 --- a/t/lib/QueryRewriter.t +++ b/t/lib/QueryRewriter.t @@ -1440,6 +1440,20 @@ is( "distill REPLACE without INTO (bug 984053)" ); +# IF EXISTS +# https://bugs.launchpad.net/percona-toolkit/+bug/821690 +is( + $qr->distill("DROP TABLE IF EXISTS foo"), + "DROP TABLE foo", + "distill DROP TABLE IF EXISTS foo (bug 821690)" +); + +is( + $qr->distill("CREATE TABLE IF NOT EXISTS foo"), + "CREATE TABLE foo", + "distill CREATE TABLE IF NOT EXISTS foo", +); + # ############################################################################# # Done. # ############################################################################# From 8773236f7ef2197683c93eba42b947587c1978f3 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Sat, 3 Aug 2013 14:04:05 -0700 Subject: [PATCH 2/3] Update QueryRewriter in pqd. --- bin/pt-query-digest | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 0191b365..74974aee 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -2962,6 +2962,7 @@ sub distill_verbs { eval $QueryParser::tbl_ident; my ( $dds ) = $query =~ /^\s*($QueryParser::data_def_stmts)\b/i; if ( $dds) { + $query =~ s/\s+IF(?:\s+NOT)?\s+EXISTS/ /i; my ( $obj ) = $query =~ m/$dds.+(DATABASE|TABLE)\b/i; $obj = uc $obj if $obj; PTDEBUG && _d('Data def statment:', $dds, 'obj:', $obj); From 952ebc574c954cc1bd034035c883e95e789a04e4 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Sat, 3 Aug 2013 14:06:08 -0700 Subject: [PATCH 3/3] Fix 'unexpectedly succeeded' in t/pt-query-digest/processlist.t. --- t/pt-query-digest/processlist.t | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/t/pt-query-digest/processlist.t b/t/pt-query-digest/processlist.t index 0654db34..925dd36d 100644 --- a/t/pt-query-digest/processlist.t +++ b/t/pt-query-digest/processlist.t @@ -27,9 +27,6 @@ my $dbh = $sb->get_dbh_for('master'); if ( !$dbh ) { plan skip_all => 'Cannot connect to sandbox master'; } -else { - plan tests => 3; -} my @args = qw(-F /tmp/12345/my.sandbox.cnf --processlist h=127.1 --report-format query_report); @@ -58,21 +55,18 @@ my $output = output( # the usual stddev. -- stddev doesn't matter much. It's the other vals # that indicate that --processlist works. $exec =~ s/(\S+) 3s$/786ms 3s/; -TODO: { - local $::TODO = "This is a timing-related test, which may occasionally fail"; - ok( - no_diff( - $exec, - "t/pt-query-digest/samples/proclist001.txt", - cmd_output => 1, - ), - "--processlist correctly observes and measures multiple queries" - ); -} +ok( + no_diff( + $exec, + "t/pt-query-digest/samples/proclist001.txt", + cmd_output => 1, + ), + "--processlist correctly observes and measures multiple queries" +); # ############################################################################# # Done. # ############################################################################# $sb->wipe_clean($dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); -exit; +done_testing;