mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-02 02:34:19 +00:00
Merge pull request #996 from utdrmac/pt-dup-index-invis
Add invisible option to pt-duplicate-key-checker
This commit is contained in:
@@ -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 made invisible incorrectly, it becomes a NOOP (no-operation) to make the index visible again,
|
||||
compared to completely re-adding the index.
|
||||
|
||||
=item --key-types
|
||||
|
||||
type: string; default: fk
|
||||
|
@@ -8879,7 +8879,7 @@ sub main {
|
||||
# it's a hack, like ignoring a problem instead of fixing it somehow. We
|
||||
# should take a look at the things that get printed in a "normal"
|
||||
# non-quiet run, and "if !quiet" them, and then do some kind of Logger.pm
|
||||
# or Messager.pm module for a future release.
|
||||
# or Message.pm module for a future release.
|
||||
close STDOUT;
|
||||
open STDOUT, '>', '/dev/null'
|
||||
or warn "Cannot reopen STDOUT to /dev/null: $OS_ERROR";
|
||||
|
@@ -80,6 +80,15 @@ ok(
|
||||
'--nosql'
|
||||
);
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_duplicate_key_checker::main(@args, qw(-d test --invisible)) },
|
||||
"$sample/basic_invisible.txt",
|
||||
transform_sample => $transform_int
|
||||
),
|
||||
'--invisible'
|
||||
);
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_duplicate_key_checker::main(@args, qw(-d test --nosummary)) },
|
||||
|
21
t/pt-duplicate-key-checker/samples/basic_invisible.txt
Normal file
21
t/pt-duplicate-key-checker/samples/basic_invisible.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
# ########################################################################
|
||||
# test.dupe_key
|
||||
# ########################################################################
|
||||
|
||||
# a is a left-prefix of a_2
|
||||
# Key definitions:
|
||||
# KEY `a` (`a`),
|
||||
# KEY `a_2` (`a`,`b`)
|
||||
# Column types:
|
||||
# `a` int(11) default null
|
||||
# `b` int(11) default null
|
||||
# To make this index invisible, execute:
|
||||
ALTER TABLE `test`.`dupe_key` ALTER INDEX `a` INVISIBLE;
|
||||
|
||||
# ########################################################################
|
||||
# Summary of indexes
|
||||
# ########################################################################
|
||||
|
||||
# Size Duplicate Indexes 0
|
||||
# Total Duplicate Indexes 1
|
||||
# Total Indexes 2
|
Reference in New Issue
Block a user