Fix get_tables() for LOAD DATA.

This commit is contained in:
Daniel Nichter
2013-08-03 12:11:56 -07:00
parent 8732b27e4e
commit 484274d8ba
2 changed files with 13 additions and 2 deletions

View File

@@ -98,7 +98,7 @@ sub get_tables {
# These keywords may appear between UPDATE or SELECT and the table refs. # 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. # They need to be removed so that they are not mistaken for tables.
$query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN|DELAYED) / /ig; $query =~ s/(?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN|DELAYED)\s+/ /ig;
# Another special case: LOCK TABLES tbl [[AS] alias] READ|WRITE, etc. # Another special case: LOCK TABLES tbl [[AS] alias] READ|WRITE, etc.
# We strip the LOCK TABLES stuff and append "FROM" to fake a SELECT # We strip the LOCK TABLES stuff and append "FROM" to fake a SELECT
@@ -116,11 +116,16 @@ sub get_tables {
# INSERT and REPLACE without INTO # INSERT and REPLACE without INTO
# https://bugs.launchpad.net/percona-toolkit/+bug/984053 # https://bugs.launchpad.net/percona-toolkit/+bug/984053
if ( $query =~ m/\A\s*(?:INSERT|REPLACE)\s+(?!INTO)/i ) { if ( $query =~ m/\A\s*(?:INSERT|REPLACE)(?!\s+INTO)/i ) {
# Add INTO so the reset of the code work as usual. # Add INTO so the reset of the code work as usual.
$query =~ s/\A\s*((?:INSERT|REPLACE))\s+/$1 INTO /i; $query =~ s/\A\s*((?:INSERT|REPLACE))\s+/$1 INTO /i;
} }
if ( $query =~ m/\A\s*LOAD DATA/i ) {
my ($tbl) = $query =~ m/INTO TABLE\s+(\S+)/i;
return $tbl;
}
my @tables; my @tables;
foreach my $tbls ( $query =~ m/$tbl_regex/gio ) { foreach my $tbls ( $query =~ m/$tbl_regex/gio ) {
PTDEBUG && _d('Match tables:', $tbls); PTDEBUG && _d('Match tables:', $tbls);

View File

@@ -828,6 +828,12 @@ is_deeply(
[qw(t1 t2)], 'get_tables works for lowercased LOCK TABLES', [qw(t1 t2)], 'get_tables works for lowercased LOCK TABLES',
); );
is_deeply(
[ $qp->get_tables("LOAD DATA INFILE '/tmp/foo.txt' INTO TABLE db.tbl") ],
[qw(db.tbl)],
"LOAD DATA db.tbl"
);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################