add invisible option to pt-duplicate-key-checker

This commit is contained in:
utdrmac
2025-08-20 16:06:16 -05:00
parent b3bf266412
commit be598413ef

View File

@@ -5301,12 +5301,19 @@ sub print_duplicate_key {
if ( $o->get('sql') ) {
if ( $dupe->{dupe_type} ne 'clustered' ) {
print "# To remove this duplicate "
. ($args{is_fk} ? 'foreign key' : 'index')
. ", execute:\n"
. 'ALTER TABLE ' . $q->quote($db, $tbl)
. ($args{is_fk} ? ' DROP FOREIGN KEY ' : ' DROP INDEX ')
. "`$dupe->{key}`;\n";
if ( $o->get('invisible') && !$args{is_fk} ) {
print "# To make this index invisible, execute:\n"
. 'ALTER TABLE ' . $q->quote($db, $tbl)
. " ALTER INDEX `$dupe->{key}` INVISIBLE;\n";
}
else {
print "# To remove this duplicate "
. ($args{is_fk} ? 'foreign key' : 'index')
. ", execute:\n"
. 'ALTER TABLE ' . $q->quote($db, $tbl)
. ($args{is_fk} ? ' DROP FOREIGN KEY ' : ' DROP INDEX ')
. "`$dupe->{key}`;\n";
}
}
else {
# Suggest shortening clustered dupes instead of
@@ -5566,6 +5573,19 @@ type: Hash
Ignore this comma-separated list of tables. Table names may be qualified with
the database name.
=item --invisible
The output SQL will make the index INVISIBLE, instead of dropping it.
An invisible index cannot be considered by the query optimizer, but is still
maintained when writes happen to the table. To make the index usable by the
optimizer, execute ALTER INDEX .. VISIBLE
While dropping an index is a fast, background operation, adding indexes is
a slow, CPU, and disk IO intensive operation. If you discover that an index
was incorrectly dropped, it becomes a NOOP to make the index visable again,
compared to completely re-adding the index.
=item --key-types
type: string; default: fk