LP #1199591: pt-table-checksum doesn't use non-unique index with highest cardinality

Description

**Reported in Launchpad by Daniel Nichter last update 02-08-2013 19:14:12

If there are only non-unique index, pt-table-checksum should choose the one with the highest cardinality, but it doesn't. In NIbbleIterator.pm:

if ( !$best_index && @possible_indexes ) {
PTDEBUG && _d('No PRIMARY or unique indexes;',
'will use index with highest cardinality');
foreach my $index ( @possible_indexes ) {
$indexes->{$index}->{cardinality} = _get_index_cardinality(
%args,
index => $index,
);
}
@possible_indexes = sort {

  1. Prefer the index with the highest cardinality.
    my $cmp
    = $indexes->{$b}>{cardinality} <=> $indexes>{$b}->{cardinality};
    if ( $cmp == 0 ) {

  2. Indexes have the same cardinality; prefer the one with

  3. more columns.
    $cmp = scalar @{$indexes->{$b}->{cols}}
    <=> scalar @{$indexes->{$a}->{cols}};
    }
    $cmp;
    } @possible_indexes;
    $best_index = $possible_indexes[0];
    }

We need to test that block.

Environment

None

Smart Checklist

Activity

Show:

lpjirasync January 24, 2018 at 2:26 PM

**Comment from Launchpad by: Daniel Nichter on: 10-07-2013 17:27:16

Simple fix, can you spot it? :

my $cmp
= $indexes->{$b}>{cardinality} <=> $indexes>{$b}->{cardinality};

If not, see the branches.

Done

Details

Assignee

Reporter

Priority

Smart Checklist

Created January 24, 2018 at 2:26 PM
Updated January 24, 2018 at 2:26 PM
Resolved January 24, 2018 at 2:26 PM