From 272f963733e9d55e506dfcad78b723194670b9f3 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Sun, 10 Jun 2012 10:01:25 -0400 Subject: [PATCH] Remove --chunk-index-columns and extend --chunk-index instead to take INDEX:N value. Add n_index_values to TableNibbler. --- bin/pt-table-checksum | 58 +++++++++++++++++++++++++++---------------- lib/NibbleIterator.pm | 9 ++++--- lib/TableNibbler.pm | 7 +++++- t/lib/TableNibbler.t | 30 +++++++++++++++++++++- 4 files changed, 76 insertions(+), 28 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index c7d2c1f8..4ce0d9f6 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -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 diff --git a/lib/NibbleIterator.pm b/lib/NibbleIterator.pm index ada807c9..a43bcf4e 100644 --- a/lib/NibbleIterator.pm +++ b/lib/NibbleIterator.pm @@ -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)); diff --git a/lib/TableNibbler.pm b/lib/TableNibbler.pm index 1cf7ad03..f1a0f860 100644 --- a/lib/TableNibbler.pm +++ b/lib/TableNibbler.pm @@ -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)); diff --git a/t/lib/TableNibbler.t b/t/lib/TableNibbler.t index 670c1da1..480704eb 100644 --- a/t/lib/TableNibbler.t +++ b/t/lib/TableNibbler.t @@ -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,