diff --git a/lib/QueryParser.pm b/lib/QueryParser.pm index b6f56f20..5b3f1633 100644 --- a/lib/QueryParser.pm +++ b/lib/QueryParser.pm @@ -98,7 +98,7 @@ sub get_tables { # These keywords may appear between UPDATE or SELECT and the table refs. # They need to be removed so that they are not mistaken for tables. - $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN)//ig; + $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN|DELAYED) / /ig; # Another special case: LOCK TABLES tbl [[AS] alias] READ|WRITE, etc. # We strip the LOCK TABLES stuff and append "FROM" to fake a SELECT @@ -110,9 +110,16 @@ sub get_tables { $query = "FROM $query"; } - $query =~ s/\\["']//g; # quoted strings - $query =~ s/".*?"/?/sg; # quoted strings - $query =~ s/'.*?'/?/sg; # quoted strings + $query =~ s/\\["']//g; # quoted strings + $query =~ s/".*?"/?/sg; # quoted strings + $query =~ s/'.*?'/?/sg; # quoted strings + + # INSERT and REPLACE without INTO + # https://bugs.launchpad.net/percona-toolkit/+bug/984053 + if ( $query =~ m/\A\s*(?:INSERT|REPLACE)\s+(?!INTO)/i ) { + # Add INTO so the reset of the code work as usual. + $query =~ s/\A\s*((?:INSERT|REPLACE))\s+/$1 INTO /i; + } my @tables; foreach my $tbls ( $query =~ m/$tbl_regex/gio ) { diff --git a/lib/QueryRewriter.pm b/lib/QueryRewriter.pm index 3cbf6228..da254359 100644 --- a/lib/QueryRewriter.pm +++ b/lib/QueryRewriter.pm @@ -246,6 +246,11 @@ sub distill_verbs { $query =~ m/\A\s*UNLOCK TABLES/i && return "UNLOCK"; $query =~ m/\A\s*xa\s+(\S+)/i && return "XA_$1"; + if ( $query =~ m/\A\s*LOAD/i ) { + my ($tbl) = $query =~ m/INTO TABLE\s+(\S+)/i; + return "LOAD DATA $tbl"; + } + if ( $query =~ m/\Aadministrator command:/ ) { $query =~ s/administrator command:/ADMIN/; $query = uc $query; @@ -386,6 +391,9 @@ sub distill { map { $verbs =~ s/$_/$alias_for{$_}/ } keys %alias_for; $query = $verbs; } + elsif ( $verbs && $verbs =~ m/^LOAD DATA/ ) { + return $verbs; + } else { # For everything else, distill the tables. my @tables = $self->__distill_tables($query, $table, %args);