From 8c806df6582d64e70c8809e79aefae81d63f8ab8 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Thu, 9 Aug 2018 13:58:31 -0300 Subject: [PATCH] PT-1572 Fixed issue with --chunk-index-columns --- bin/pt-online-schema-change | 3 +++ bin/pt-table-checksum | 3 +++ lib/NibbleIterator.pm | 3 +++ t/lib/NibbleIterator.t | 46 +++++++++++++++++++++++++++---------- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 6750b61f..6e07c42c 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -5521,7 +5521,10 @@ sub new { PTDEBUG && _d('Ascend params:', Dumper($asc)); my $force_concat_enums = $o->has('force-concat-enums') && $o->get('force-concat-enums'); + my $i=0; for my $index (@{$index_cols}) { + last if $args{n_chunk_index_cols} && $i >= $args{n_chunk_index_cols}; + $i++; if ($tbl->{tbl_struct}->{type_for}->{$index} eq 'enum') { if ($tbl->{tbl_struct}->{defs}->{$index} =~ m/enum\s*\((.*?)\)/) { my @items = split(/,\s*/, $1); diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 7d88b492..d106e9f3 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -6372,7 +6372,10 @@ sub new { PTDEBUG && _d('Ascend params:', Dumper($asc)); my $force_concat_enums = $o->has('force-concat-enums') && $o->get('force-concat-enums'); + my $i=0; for my $index (@{$index_cols}) { + last if $args{n_chunk_index_cols} && $i >= $args{n_chunk_index_cols}; + $i++; if ($tbl->{tbl_struct}->{type_for}->{$index} eq 'enum') { if ($tbl->{tbl_struct}->{defs}->{$index} =~ m/enum\s*\((.*?)\)/) { my @items = split(/,\s*/, $1); diff --git a/lib/NibbleIterator.pm b/lib/NibbleIterator.pm index 1f70235e..285a990a 100644 --- a/lib/NibbleIterator.pm +++ b/lib/NibbleIterator.pm @@ -137,7 +137,10 @@ sub new { # Check if enum fields items are sorted or not. # If they are sorted we can skip adding CONCAT to improve the queries eficiency. my $force_concat_enums = $o->has('force-concat-enums') && $o->get('force-concat-enums'); + my $i=0; for my $index (@{$index_cols}) { + last if $args{n_chunk_index_cols} && $i >= $args{n_chunk_index_cols}; + $i++; if ($tbl->{tbl_struct}->{type_for}->{$index} eq 'enum') { if ($tbl->{tbl_struct}->{defs}->{$index} =~ m/enum\s*\((.*?)\)/) { my @items = split(/,\s*/, $1); diff --git a/t/lib/NibbleIterator.t b/t/lib/NibbleIterator.t index 8574b9fc..f968389e 100644 --- a/t/lib/NibbleIterator.t +++ b/t/lib/NibbleIterator.t @@ -67,6 +67,7 @@ my $in = "/t/lib/samples/NibbleIterator/"; sub make_nibble_iter { my (%args) = @_; + if (my $file = $args{sql_file}) { $sb->load_file('master', "$in/$file"); } @@ -85,18 +86,19 @@ sub make_nibble_iter { 1 while $si->next(); my $ni = new NibbleIterator( - Cxn => $cxn, - tbl => $schema->get_table(lc($args{db}), lc($args{tbl})), - chunk_size => $o->get('chunk-size'), - chunk_index => $o->get('chunk-index'), - callbacks => $args{callbacks}, - select => $args{select}, - one_nibble => $args{one_nibble}, - resume => $args{resume}, - order_by => $args{order_by}, - comments => $args{comments}, - pause_file => $o->get('pause-file'), - sleep => $args{sleep} || 60, + Cxn => $cxn, + tbl => $schema->get_table(lc($args{db}), lc($args{tbl})), + chunk_size => $o->get('chunk-size'), + chunk_index => $o->get('chunk-index'), + callbacks => $args{callbacks}, + select => $args{select}, + one_nibble => $args{one_nibble}, + resume => $args{resume}, + order_by => $args{order_by}, + comments => $args{comments}, + n_chunk_index_cols => $o->get('chunk-index-columns'), + pause_file => $o->get('pause-file'), + sleep => $args{sleep} || 60, %common_modules, ); @@ -944,6 +946,26 @@ like( "PT-1572 Don't use CONCAT for sorted ENUM field items without --force-concat-enums", ); +eval { + $ni = make_nibble_iter( + db => 'test', + tbl => 't1', + argv => [qw(--databases test --chunk-size 3 --chunk-index-columns 2)], + ); +}; + +is( + $EVAL_ERROR, + '', + "PT-1572 No errors on unsorted enum items in index and --chunk-index-columns", +); + +like( + $ni->{explain_first_lb_sql}, + qr/ORDER BY `f1`, `f2`, `f3`/, + "PT-1572 Don't use CONCAT for sorted ENUM field items without --force-concat-enums & --chunk-index-columns", +); + # ############################################################################# # Done. # #############################################################################