mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-22 10:58:42 +00:00
Fix QueryParser and QueryRewriter to handle LOAD DATA and INSERT/REPLACE without INTO.
This commit is contained in:
@@ -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
|
||||
@@ -114,6 +114,13 @@ sub get_tables {
|
||||
$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 ) {
|
||||
PTDEBUG && _d('Match tables:', $tbls);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user