diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index bcd54383..6be21987 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -6560,7 +6560,7 @@ sub _find_best_index { } } - if (!$best_index && !$want_index) { + if (!$best_index) { PTDEBUG && _d('Auto-selecting best index'); foreach my $index ( $tp->sort_indexes($tbl_struct) ) { if ( $index eq 'PRIMARY' || $indexes->{$index}->{is_unique} ) { diff --git a/lib/NibbleIterator.pm b/lib/NibbleIterator.pm index 3491d600..ea5f08c5 100644 --- a/lib/NibbleIterator.pm +++ b/lib/NibbleIterator.pm @@ -540,7 +540,8 @@ sub _find_best_index { } } - # still no best index? select amongst all candidates. + # still no best index? + # prefer unique index. otherwise put in candidates array. if (!$best_index) { PTDEBUG && _d('Auto-selecting best index'); foreach my $index ( $tp->sort_indexes($tbl_struct) ) { @@ -554,6 +555,7 @@ sub _find_best_index { } } + # choose the one with best cardinality if ( !$best_index && @possible_indexes ) { PTDEBUG && _d('No PRIMARY or unique indexes;', 'will use index with highest cardinality');