mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-19 02:05:23 +00:00
Merge fix-pt-dupe-key-bug-1036804
This commit is contained in:
@@ -2188,8 +2188,9 @@ sub get_duplicate_keys {
|
||||
|
||||
my $clustered_key = $args{clustered_key} ? $keys{$args{clustered_key}}
|
||||
: undef;
|
||||
PTDEBUG && _d('clustered key:', $clustered_key->{name},
|
||||
$clustered_key->{colnames});
|
||||
PTDEBUG && _d('clustered key:',
|
||||
$clustered_key ? ($clustered_key->{name}, $clustered_key->{colnames})
|
||||
: 'none');
|
||||
if ( $clustered_key
|
||||
&& $args{clustered}
|
||||
&& $args{tbl_info}->{engine}
|
||||
@@ -3404,6 +3405,7 @@ sub main {
|
||||
);
|
||||
TABLE:
|
||||
while ( my $tbl = $schema_itr->next() ) {
|
||||
eval {
|
||||
$tbl->{engine} = $tbl->{tbl_struct}->{engine};
|
||||
|
||||
my ($keys, $clustered_key, $fks);
|
||||
@@ -3415,15 +3417,14 @@ sub main {
|
||||
$fks = $tp->get_fks($tbl->{ddl}, {database => $tbl->{db}});
|
||||
}
|
||||
|
||||
next TABLE unless ($keys && %$keys) || ($fks && %$fks);
|
||||
|
||||
if ( ($keys && %$keys) || ($fks && %$fks) ) {
|
||||
if ( $o->got('verbose') ) {
|
||||
print_all_keys($keys, $tbl, \%seen_tbl) if $keys;
|
||||
print_all_keys($fks, $tbl, \%seen_tbl) if $fks;
|
||||
}
|
||||
else {
|
||||
PTDEBUG && _d('Getting duplicate keys on', $tbl->{db}, $tbl->{tbl});
|
||||
eval {
|
||||
PTDEBUG && _d('Getting duplicate keys on',
|
||||
$tbl->{db}, $tbl->{tbl});
|
||||
if ( $keys ) {
|
||||
$dk->get_duplicate_keys(
|
||||
$keys,
|
||||
@@ -3461,17 +3462,17 @@ sub main {
|
||||
summary => \%summary,
|
||||
);
|
||||
}
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
warn "Error checking `$tbl->{db}`.`$tbl->{tbl}` for duplicate keys: "
|
||||
. $EVAL_ERROR;
|
||||
next TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
# Always count Total Keys so print_key_summary won't die
|
||||
# because %summary is empty.
|
||||
$summary{'Total Indexes'} += (scalar keys %$keys) + (scalar keys %$fks)
|
||||
$summary{'Total Indexes'} += (scalar keys %$keys)
|
||||
+ (scalar keys %$fks)
|
||||
}
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
warn "Error checking $tbl->{db}.$tbl->{tbl}: $EVAL_ERROR";
|
||||
}
|
||||
} # TABLE
|
||||
|
||||
print_key_summary(%summary) if $o->get('summary');
|
||||
|
@@ -148,8 +148,9 @@ sub get_duplicate_keys {
|
||||
# Remove clustered duplicates.
|
||||
my $clustered_key = $args{clustered_key} ? $keys{$args{clustered_key}}
|
||||
: undef;
|
||||
PTDEBUG && _d('clustered key:', $clustered_key->{name},
|
||||
$clustered_key->{colnames});
|
||||
PTDEBUG && _d('clustered key:',
|
||||
$clustered_key ? ($clustered_key->{name}, $clustered_key->{colnames})
|
||||
: 'none');
|
||||
if ( $clustered_key
|
||||
&& $args{clustered}
|
||||
&& $args{tbl_info}->{engine}
|
||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 38;
|
||||
use Test::More;
|
||||
|
||||
use VersionParser;
|
||||
use DuplicateKeyFinder;
|
||||
@@ -786,4 +786,5 @@ like(
|
||||
qr/Complete test coverage/,
|
||||
'_d() works'
|
||||
);
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -22,9 +22,6 @@ my $dbh = $sb->get_dbh_for('master');
|
||||
if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 2;
|
||||
}
|
||||
|
||||
my $cnf = "/tmp/12345/my.sandbox.cnf";
|
||||
my $sample = "t/pt-duplicate-key-checker/samples/";
|
||||
@@ -46,9 +43,47 @@ ok(
|
||||
"Shorten, not remove, clustered dupes"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Error if InnoDB table has no PK or unique indexes
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1036804
|
||||
# #############################################################################
|
||||
$sb->load_file('master', "t/pt-duplicate-key-checker/samples/idb-no-uniques-bug-894140.sql");
|
||||
|
||||
# PTDEBUG was auto-vivifying $clustered_key:
|
||||
#
|
||||
# PTDEBUG && _d('clustered key:', $clustered_key->{name},
|
||||
# $clustered_key->{colnames});
|
||||
#
|
||||
# if ( $clustered_key
|
||||
# && $args{clustered}
|
||||
# && $args{tbl_info}->{engine}
|
||||
# && $args{tbl_info}->{engine} =~ m/InnoDB/i )
|
||||
# {
|
||||
# push @dupes, $self->remove_clustered_duplicates($clustered_key...
|
||||
#
|
||||
# sub remove_clustered_duplicates {
|
||||
# my ( $self, $ck, $keys, %args ) = @_;
|
||||
# die "I need a ck argument" unless $ck;
|
||||
# die "I need a keys argument" unless $keys;
|
||||
# my $ck_cols = $ck->{colnames};
|
||||
# my @dupes;
|
||||
# KEY:
|
||||
# for my $i ( 0 .. @$keys - 1 ) {
|
||||
# my $key = $keys->[$i]->{colnames};
|
||||
# if ( $key =~ m/$ck_cols$/ ) {
|
||||
|
||||
my $output = `PTDEBUG=1 $trunk/bin/pt-duplicate-key-checker F=$cnf -d bug_1036804 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Use of uninitialized value/,
|
||||
'PTDEBUG doesn\'t auto-vivify cluster key hashref (bug 1036804)'
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -0,0 +1,9 @@
|
||||
DROP DATABASE IF EXISTS bug_1036804;
|
||||
CREATE DATABASE bug_1036804;
|
||||
USE bug_1036804;
|
||||
CREATE TABLE `t` (
|
||||
`col1` int(11) DEFAULT NULL,
|
||||
`col2` int(11) DEFAULT NULL,
|
||||
KEY `col1` (`col1`),
|
||||
KEY `col2` (`col2`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
Reference in New Issue
Block a user