Test and fix bug 1217013.

This commit is contained in:
Daniel Nichter
2013-12-11 19:39:09 -08:00
parent e83e1c09c4
commit e89ce13e97
4 changed files with 55 additions and 10 deletions

View File

@@ -2387,7 +2387,6 @@ sub get_duplicate_keys {
push @dupes, push @dupes,
$self->remove_prefix_duplicates(\@fulltext_keys, \@fulltext_keys, %args, exact_duplicates => 1); $self->remove_prefix_duplicates(\@fulltext_keys, \@fulltext_keys, %args, exact_duplicates => 1);
my $clustered_key = $args{clustered_key} ? $keys{$args{clustered_key}} my $clustered_key = $args{clustered_key} ? $keys{$args{clustered_key}}
: undef; : undef;
PTDEBUG && _d('clustered key:', PTDEBUG && _d('clustered key:',
@@ -2522,10 +2521,10 @@ sub remove_prefix_duplicates {
PTDEBUG && _d('Remove', $right_name); PTDEBUG && _d('Remove', $right_name);
my $reason; my $reason;
if ( $right_keys->[$right_index]->{unconstrained} ) { if ( my $type = $right_keys->[$right_index]->{unconstrained} ) {
$reason .= "Uniqueness of $right_name ignored because " $reason .= "Uniqueness of $right_name ignored because "
. $right_keys->[$right_index]->{constraining_key}->{name} . $right_keys->[$right_index]->{constraining_key}->{name}
. " is a stronger constraint\n"; . " is a $type constraint\n";
} }
my $exact_dupe = $right_len_cols < $left_len_cols ? 0 : 1; my $exact_dupe = $right_len_cols < $left_len_cols ? 0 : 1;
$reason .= $right_name $reason .= $right_name
@@ -2625,11 +2624,18 @@ sub unconstrain_keys {
next unless $unique_key; # primary key may be undefined next unless $unique_key; # primary key may be undefined
my $cols = $unique_key->{cols}; my $cols = $unique_key->{cols};
if ( @$cols == 1 ) { if ( @$cols == 1 ) {
PTDEBUG && _d($unique_key->{name},'defines unique column:',$cols->[0]);
if ( !exists $unique_cols{$cols->[0]} ) { if ( !exists $unique_cols{$cols->[0]} ) {
PTDEBUG && _d($unique_key->{name}, 'defines unique column:',
$cols->[0]);
$unique_cols{$cols->[0]} = $unique_key; $unique_cols{$cols->[0]} = $unique_key;
$unique_key->{unique_col} = 1; $unique_key->{unique_col} = 1;
} }
else {
PTDEBUG && _d($unique_key->{name},
'redundantly constrains unique column:', $cols->[0]);
$unique_key->{exact_dupe} = 1;
$unique_key->{constraining_key} = $unique_cols{$cols->[0]};
}
} }
else { else {
local $LIST_SEPARATOR = '-'; local $LIST_SEPARATOR = '-';
@@ -2663,13 +2669,19 @@ sub unconstrain_keys {
for my $i ( 0..(scalar @$unique_keys-1) ) { for my $i ( 0..(scalar @$unique_keys-1) ) {
if ( exists $unconstrain{$unique_keys->[$i]->{name}} ) { if ( exists $unconstrain{$unique_keys->[$i]->{name}} ) {
PTDEBUG && _d('Unconstraining', $unique_keys->[$i]->{name}); PTDEBUG && _d('Unconstraining weak', $unique_keys->[$i]->{name});
$unique_keys->[$i]->{unconstrained} = 1; $unique_keys->[$i]->{unconstrained} = 'stronger';
$unique_keys->[$i]->{constraining_key} $unique_keys->[$i]->{constraining_key}
= $unconstrain{$unique_keys->[$i]->{name}}; = $unconstrain{$unique_keys->[$i]->{name}};
push @unconstrained_keys, $unique_keys->[$i]; push @unconstrained_keys, $unique_keys->[$i];
delete $unique_keys->[$i]; delete $unique_keys->[$i];
} }
elsif ( $unique_keys->[$i]->{exact_dupe} ) {
PTDEBUG && _d('Unconstraining dupe', $unique_keys->[$i]->{name});
$unique_keys->[$i]->{unconstrained} = 'duplicate';
push @unconstrained_keys, $unique_keys->[$i];
delete $unique_keys->[$i];
}
} }
PTDEBUG && _d('No more keys'); PTDEBUG && _d('No more keys');

View File

@@ -22,9 +22,6 @@ my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) { if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master'; plan skip_all => 'Cannot connect to sandbox master';
} }
else {
plan tests => 13;
}
my $output; my $output;
my $sample = "t/pt-duplicate-key-checker/samples/"; my $sample = "t/pt-duplicate-key-checker/samples/";
@@ -136,9 +133,23 @@ ok(
'--key-types fk (explicit)' '--key-types fk (explicit)'
); );
# #############################################################################
# Exact unique dupes
# https://bugs.launchpad.net/percona-toolkit/+bug/1217013
# #############################################################################
$sb->load_file('master', 't/lib/samples/dupekeys/simple_dupe_bug_1217013.sql', 'test');
ok(
no_diff(
sub { pt_duplicate_key_checker::main(@args, qw(-t test.domains)) },
"$sample/simple_dupe_bug_1217013.txt"),
'Exact unique dupes (bug 1217013)'
) or diag($test_diff);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################
$sb->wipe_clean($dbh); $sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit; done_testing;

View File

@@ -2,6 +2,7 @@
# test.bug_894140 # test.bug_894140
# ######################################################################## # ########################################################################
# Uniqueness of row_id ignored because PRIMARY is a duplicate constraint
# row_id is a duplicate of PRIMARY # row_id is a duplicate of PRIMARY
# Key definitions: # Key definitions:
# UNIQUE KEY `row_id` (`row_id`), # UNIQUE KEY `row_id` (`row_id`),

View File

@@ -0,0 +1,21 @@
# ########################################################################
# test.domains
# ########################################################################
# Uniqueness of domain ignored because unique_key_domain is a duplicate constraint
# domain is a duplicate of unique_key_domain
# Key definitions:
# UNIQUE KEY `domain` (`domain`),
# UNIQUE KEY `unique_key_domain` (`domain`)
# Column types:
# `domain` varchar(175) collate utf8_bin not null
# To remove this duplicate index, execute:
ALTER TABLE `test`.`domains` DROP INDEX `domain`;
# ########################################################################
# Summary of indexes
# ########################################################################
# Size Duplicate Indexes 527
# Total Duplicate Indexes 1
# Total Indexes 3