mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-24 02:01:42 +08:00
Rename preserve_embedded_numbers to match_embedded_numbers, and fingerprint_md5 to match_md5_checksums. Add corresponding options to pt-fingerprint.
This commit is contained in:
@@ -1559,8 +1559,25 @@ sub fingerprint {
|
||||
$query =~ s/\\["']//g; # quoted strings
|
||||
$query =~ s/".*?"/?/sg; # quoted strings
|
||||
$query =~ s/'.*?'/?/sg; # quoted strings
|
||||
$query =~ s/[0-9+-][0-9a-f.xb+-]*/?/g;# Anything vaguely resembling numbers
|
||||
$query =~ s/[xb.+-]\?/?/g; # Clean up leftovers
|
||||
|
||||
if ( $self->{match_md5_checksums} ) {
|
||||
$query =~ s/([._-])[a-f0-9]{32}/$1?/g;
|
||||
}
|
||||
|
||||
if ( !$self->{match_embedded_numbers} ) {
|
||||
$query =~ s/[0-9+-][0-9a-f.xb+-]*/?/g;
|
||||
}
|
||||
else {
|
||||
$query =~ s/\b[0-9+-][0-9a-f.xb+-]*/?/g;
|
||||
}
|
||||
|
||||
if ( $self->{match_md5_checksums} ) {
|
||||
$query =~ s/[xb+-]\?/?/g;
|
||||
}
|
||||
else {
|
||||
$query =~ s/[xb.+-]\?/?/g;
|
||||
}
|
||||
|
||||
$query =~ s/\A\s+//; # Chop off leading whitespace
|
||||
chomp $query; # Kill trailing whitespace
|
||||
$query =~ tr[ \n\t\r\f][ ]s; # Collapse whitespace
|
||||
@@ -1840,7 +1857,11 @@ sub main {
|
||||
$o->usage_or_errors();
|
||||
|
||||
my $qp = new QueryParser();
|
||||
my $qr = new QueryRewriter(QueryParser=>$qp);
|
||||
my $qr = new QueryRewriter(
|
||||
QueryParser => $qp,
|
||||
match_md5_checksums => $o->get('match-md5-checksums'),
|
||||
match_embedded_numbers => $o->get('match-embedded-numbers'),
|
||||
);
|
||||
|
||||
if ( $o->got('query') ) {
|
||||
print $qr->fingerprint($o->get('query')), "\n";
|
||||
@@ -1993,6 +2014,24 @@ first option on the command line.
|
||||
|
||||
Show help and exit.
|
||||
|
||||
=item --match-embedded-numbers
|
||||
|
||||
Match numbers embedded in words and replace as single values. This option
|
||||
causes the tool to be more careful about matching numbers so that words
|
||||
with numbers, like C<catch22> are matched and replaced as a single C<?>
|
||||
placeholder. Otherwise the default number matching pattern will replace
|
||||
C<catch22> as C<catch?>.
|
||||
|
||||
This is helpful if database or table names contain numbers.
|
||||
|
||||
=item --match-md5-checksums
|
||||
|
||||
Match MD5 checksums and replace as single values. This option causes
|
||||
the tool to be more careful about matching numbers so that MD5 checksums
|
||||
like C<fbc5e685a5d3d45aa1d0347fdb7c4d35> are matched and replaced as a
|
||||
single C<?> placeholder. Otherwise, the default number matching pattern will
|
||||
replace C<fbc5e685a5d3d45aa1d0347fdb7c4d35> as C<fbc?>.
|
||||
|
||||
=item --query
|
||||
|
||||
type: string
|
||||
|
||||
@@ -177,12 +177,12 @@ sub fingerprint {
|
||||
$query =~ s/'.*?'/?/sg; # quoted strings
|
||||
|
||||
# MD5 checksums which are always 32 hex chars
|
||||
if ( $self->{fingerprint_md5} ) {
|
||||
if ( $self->{match_md5_checksums} ) {
|
||||
$query =~ s/([._-])[a-f0-9]{32}/$1?/g;
|
||||
}
|
||||
|
||||
# Things resembling numbers/hex.
|
||||
if ( !$self->{preserve_embedded_numbers} ) {
|
||||
if ( !$self->{match_embedded_numbers} ) {
|
||||
# For speed, this regex is extremely broad in its definition
|
||||
# of what looks like a number.
|
||||
$query =~ s/[0-9+-][0-9a-f.xb+-]*/?/g;
|
||||
@@ -192,7 +192,7 @@ sub fingerprint {
|
||||
}
|
||||
|
||||
# Clean up leftovers
|
||||
if ( $self->{fingerprint_md5} ) {
|
||||
if ( $self->{match_md5_checksums} ) {
|
||||
$query =~ s/[xb+-]\?/?/g;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -353,7 +353,7 @@ is(
|
||||
# special feature used by pt-fingerprint.
|
||||
$qr = new QueryRewriter(
|
||||
QueryParser => $qp,
|
||||
fingerprint_md5 => 1,
|
||||
match_md5_checksums => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
@@ -374,8 +374,8 @@ is(
|
||||
|
||||
$qr = new QueryRewriter(
|
||||
QueryParser => $qp,
|
||||
fingerprint_md5 => 1,
|
||||
preserve_embedded_numbers => 1,
|
||||
match_md5_checksums => 1,
|
||||
match_embedded_numbers => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
@@ -383,7 +383,7 @@ is(
|
||||
"SELECT * FROM db.fbc5e685a5d3d45aa1d0347fdb7c4d35_temp where id=1"
|
||||
),
|
||||
"select * from db.?_temp where id=?",
|
||||
"Fingerprint db.MD5_tbl (with preserve_embedded_numbers)"
|
||||
"Fingerprint db.MD5_tbl (with match_embedded_numbers)"
|
||||
);
|
||||
|
||||
is(
|
||||
@@ -391,12 +391,12 @@ is(
|
||||
"SELECT * FROM db.temp_fbc5e685a5d3d45aa1d0347fdb7c4d35 where id=1"
|
||||
),
|
||||
"select * from db.temp_? where id=?",
|
||||
"Fingerprint db.tbl_MD5 (with preserve_embedded_numbers)"
|
||||
"Fingerprint db.tbl_MD5 (with match_embedded_numbers)"
|
||||
);
|
||||
|
||||
$qr = new QueryRewriter(
|
||||
QueryParser => $qp,
|
||||
preserve_embedded_numbers => 1,
|
||||
match_embedded_numbers => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
|
||||
Reference in New Issue
Block a user