diff --git a/bin/pt-fingerprint b/bin/pt-fingerprint index f68e72e4..05ca6df7 100755 --- a/bin/pt-fingerprint +++ b/bin/pt-fingerprint @@ -1097,10 +1097,9 @@ sub get_tables { $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN)//ig; - if ( $query =~ /^\s*LOCK TABLES/i ) { + if ( $query =~ s/^\s*LOCK TABLES\s+//i ) { PTDEBUG && _d('Special table type: LOCK TABLES'); - $query =~ s/^(\s*LOCK TABLES\s+)//; - $query =~ s/\s+(?:READ|WRITE|LOCAL)+\s*//g; + $query =~ s/\s+(?:READ(?:\s+LOCAL)?|WRITE)\s*//gi; PTDEBUG && _d('Locked tables:', $query); $query = "FROM $query"; } diff --git a/bin/pt-index-usage b/bin/pt-index-usage index 38c28314..2930487c 100755 --- a/bin/pt-index-usage +++ b/bin/pt-index-usage @@ -1826,10 +1826,9 @@ sub get_tables { $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN)//ig; - if ( $query =~ /^\s*LOCK TABLES/i ) { + if ( $query =~ s/^\s*LOCK TABLES\s+//i ) { PTDEBUG && _d('Special table type: LOCK TABLES'); - $query =~ s/^(\s*LOCK TABLES\s+)//; - $query =~ s/\s+(?:READ|WRITE|LOCAL)+\s*//g; + $query =~ s/\s+(?:READ(?:\s+LOCAL)?|WRITE)\s*//gi; PTDEBUG && _d('Locked tables:', $query); $query = "FROM $query"; } diff --git a/bin/pt-query-advisor b/bin/pt-query-advisor index 2c5d63b2..c9fbabaa 100755 --- a/bin/pt-query-advisor +++ b/bin/pt-query-advisor @@ -1996,10 +1996,9 @@ sub get_tables { $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN)//ig; - if ( $query =~ /^\s*LOCK TABLES/i ) { + if ( $query =~ s/^\s*LOCK TABLES\s+//i ) { PTDEBUG && _d('Special table type: LOCK TABLES'); - $query =~ s/^(\s*LOCK TABLES\s+)//; - $query =~ s/\s+(?:READ|WRITE|LOCAL)+\s*//g; + $query =~ s/\s+(?:READ(?:\s+LOCAL)?|WRITE)\s*//gi; PTDEBUG && _d('Locked tables:', $query); $query = "FROM $query"; } diff --git a/bin/pt-query-digest b/bin/pt-query-digest index d9215190..f82509eb 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -7736,10 +7736,9 @@ sub get_tables { $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN)//ig; - if ( $query =~ /^\s*LOCK TABLES/i ) { + if ( $query =~ s/^\s*LOCK TABLES\s+//i ) { PTDEBUG && _d('Special table type: LOCK TABLES'); - $query =~ s/^(\s*LOCK TABLES\s+)//; - $query =~ s/\s+(?:READ|WRITE|LOCAL)+\s*//g; + $query =~ s/\s+(?:READ(?:\s+LOCAL)?|WRITE)\s*//gi; PTDEBUG && _d('Locked tables:', $query); $query = "FROM $query"; } diff --git a/bin/pt-table-usage b/bin/pt-table-usage index 97b88f4c..cabf587e 100755 --- a/bin/pt-table-usage +++ b/bin/pt-table-usage @@ -2410,10 +2410,9 @@ sub get_tables { $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN)//ig; - if ( $query =~ /^\s*LOCK TABLES/i ) { + if ( $query =~ s/^\s*LOCK TABLES\s+//i ) { PTDEBUG && _d('Special table type: LOCK TABLES'); - $query =~ s/^(\s*LOCK TABLES\s+)//; - $query =~ s/\s+(?:READ|WRITE|LOCAL)+\s*//g; + $query =~ s/\s+(?:READ(?:\s+LOCAL)?|WRITE)\s*//gi; PTDEBUG && _d('Locked tables:', $query); $query = "FROM $query"; } diff --git a/bin/pt-upgrade b/bin/pt-upgrade index bd225e19..e194e99e 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -3590,10 +3590,9 @@ sub get_tables { $query =~ s/ (?:LOW_PRIORITY|IGNORE|STRAIGHT_JOIN)//ig; - if ( $query =~ /^\s*LOCK TABLES/i ) { + if ( $query =~ s/^\s*LOCK TABLES\s+//i ) { PTDEBUG && _d('Special table type: LOCK TABLES'); - $query =~ s/^(\s*LOCK TABLES\s+)//; - $query =~ s/\s+(?:READ|WRITE|LOCAL)+\s*//g; + $query =~ s/\s+(?:READ(?:\s+LOCAL)?|WRITE)\s*//gi; PTDEBUG && _d('Locked tables:', $query); $query = "FROM $query"; } diff --git a/lib/QueryParser.pm b/lib/QueryParser.pm index f83a95bd..90c6e7d0 100644 --- a/lib/QueryParser.pm +++ b/lib/QueryParser.pm @@ -103,10 +103,9 @@ sub get_tables { # Another special case: LOCK TABLES tbl [[AS] alias] READ|WRITE, etc. # We strip the LOCK TABLES stuff and append "FROM" to fake a SELECT # statement and allow $tbl_regex to match below. - if ( $query =~ /^\s*LOCK TABLES/i ) { + if ( $query =~ s/^\s*LOCK TABLES\s+//i ) { PTDEBUG && _d('Special table type: LOCK TABLES'); - $query =~ s/^(\s*LOCK TABLES\s+)//; - $query =~ s/\s+(?:READ|WRITE|LOCAL)+\s*//g; + $query =~ s/\s+(?:READ(?:\s+LOCAL)?|WRITE)\s*//gi; PTDEBUG && _d('Locked tables:', $query); $query = "FROM $query"; } diff --git a/t/lib/QueryParser.t b/t/lib/QueryParser.t index c4b51f6a..3f453b4e 100644 --- a/t/lib/QueryParser.t +++ b/t/lib/QueryParser.t @@ -10,7 +10,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; -use Test::More tests => 135; +use Test::More; use English qw(-no_match_vars); use QueryRewriter; @@ -823,7 +823,12 @@ is_deeply( [qw(mytable)], 'Does not consider subquery SELECT as a table (issue 781)', ); +is_deeply( + [ $qp->get_tables('lock tables t1 as t5 read local, t2 low_priority write') ], + [qw(t1 t2)], 'get_tables works for lowercased LOCK TABLES', +); + # ############################################################################# # Done. # ############################################################################# -exit; +done_testing;