Remove --chunk-index-columns and extend --chunk-index instead to take INDEX:N value. Add n_index_values to TableNibbler.

This commit is contained in:
Daniel Nichter
2012-06-10 10:01:25 -04:00
parent 3c553665a2
commit 272f963733
4 changed files with 76 additions and 28 deletions

View File

@@ -5991,6 +5991,25 @@ sub main {
}
}
# Parse --chunk-index INDEX:N where N is the number of
# left-most columns of INDEX to use.
# https://bugs.launchpad.net/percona-toolkit/+bug/1010232
my ($chunk_index, $n_chunk_index_cols)
= split(':', $o->get('chunk-index') || '');
if ( defined $chunk_index && !$chunk_index ) {
$o->save_error('--chunk-index cannot be an empty string');
}
else {
$chunk_index = lc $chunk_index;
}
if ( defined $n_chunk_index_cols
&& (!$n_chunk_index_cols
|| $n_chunk_index_cols =~ m/[^\d]/
|| $n_chunk_index_cols < 1) ) {
$o->save_error('Invalid number of --chunk-index columns: '
. $n_chunk_index_cols);
}
if ( !$o->get('help') ) {
if ( @ARGV > 1 ) {
$o->save_error("More than one host specified; only one allowed");
@@ -6910,22 +6929,23 @@ sub main {
my $nibble_iter;
eval {
$nibble_iter = new OobNibbleIterator(
Cxn => $master_cxn,
tbl => $tbl,
chunk_size => $tbl->{chunk_size},
chunk_index => $o->get('chunk-index'),
dml => $checksum_dml,
select => $checksum_cols,
past_dml => $checksum_dml,
past_select => $past_cols,
callbacks => $callbacks,
resume => $last_chunk,
OptionParser => $o,
Quoter => $q,
TableNibbler => $tn,
TableParser => $tp,
RowChecksum => $rc,
comments => {
Cxn => $master_cxn,
tbl => $tbl,
chunk_size => $tbl->{chunk_size},
chunk_index => $chunk_index,
n_chunk_index_cols => $n_chunk_index_cols,
dml => $checksum_dml,
select => $checksum_cols,
past_dml => $checksum_dml,
past_select => $past_cols,
callbacks => $callbacks,
resume => $last_chunk,
OptionParser => $o,
Quoter => $q,
TableNibbler => $tn,
TableParser => $tp,
RowChecksum => $rc,
comments => {
bite => "checksum table",
nibble => "checksum chunk",
},
@@ -8037,12 +8057,6 @@ when using this option; a poor choice of index could cause bad performance.
This is probably best to use when you are checksumming only a single table, not
an entire server.
=item --chunk-index-columns
type: int
Number of left-most L<"--chunk-index"> columns to use.
=item --chunk-size
type: size; default: 1000

View File

@@ -124,10 +124,11 @@ sub new {
# Figure out how to nibble the table with the index.
my $asc = $args{TableNibbler}->generate_asc_stmt(
%args,
tbl_struct => $tbl->{tbl_struct},
index => $index,
cols => \@cols,
asc_only => 1,
tbl_struct => $tbl->{tbl_struct},
index => $index,
n_index_cols => $args{n_chunk_index_cols},
cols => \@cols,
asc_only => 1,
);
PTDEBUG && _d('Ascend params:', Dumper($asc));

View File

@@ -41,6 +41,7 @@ sub new {
# * tbl_struct Hashref returned from TableParser::parse().
# * cols Arrayref of columns to SELECT from the table
# * index Which index to ascend; optional.
# * n_index_cols The number of left-most index columns to use.
# * asc_only Whether to ascend strictly, that is, the WHERE clause for
# the asc_stmt will fetch the next row > the given arguments.
# The option is to fetch the row >=, which could loop
@@ -77,8 +78,12 @@ sub generate_asc_stmt {
# These are the columns we'll ascend.
my @asc_cols = @{$tbl_struct->{keys}->{$index}->{cols}};
if ( $args{asc_first} ) {
@asc_cols = $asc_cols[0];
PTDEBUG && _d('Ascending only first column');
@asc_cols = $asc_cols[0];
}
elsif ( my $n = $args{n_index_cols} ) {
PTDEBUG && _d('Ascending only first', $n, 'columns');
@asc_cols = @asc_cols[0..($n-1)];
}
PTDEBUG && _d('Will ascend columns', join(', ', @asc_cols));

View File

@@ -9,7 +9,7 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 24;
use Test::More tests => 25;
use TableParser;
use TableNibbler;
@@ -297,6 +297,34 @@ is_deeply(
'Alternate index with asc_first on sakila.rental',
);
is_deeply(
$n->generate_asc_stmt(
tbl_struct => $t,
cols => $t->{cols},
index => 'rental_date',
n_index_cols => 2,
),
{
cols => [qw(rental_id rental_date inventory_id customer_id
return_date staff_id last_update)],
index => 'rental_date',
where => '((`rental_date` > ?) OR (`rental_date` = ? AND `inventory_id` >= ?))',
slice => [qw(1 1 2)],
scols => [qw(rental_date rental_date inventory_id)],
boundaries => {
'<' =>
'((`rental_date` < ?) OR (`rental_date` = ? AND `inventory_id` < ?))',
'<=' =>
'((`rental_date` < ?) OR (`rental_date` = ? AND `inventory_id` <= ?))',
'>' =>
'((`rental_date` > ?) OR (`rental_date` = ? AND `inventory_id` > ?))',
'>=' =>
'((`rental_date` > ?) OR (`rental_date` = ? AND `inventory_id` >= ?))'
},
},
'Use only N left-most columns of the index',
);
is_deeply(
$n->generate_asc_stmt(
tbl_struct => $t,