diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index fe920652..a3014931 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -4755,6 +4755,11 @@ sub next { return; } } + if ( !$self->{one_nibble} && !$self->{first_lower} ) { + PTDEBUG && _d('No first lower boundary, table must be empty'); + $self->{no_more_boundaries} = 1; + return; + } } NIBBLE: @@ -6502,13 +6507,21 @@ sub main { my $tbl = $args{tbl}; my $nibble_iter = $args{NibbleIterator}; my $statements = $nibble_iter->statements(); + my $boundary = $nibble_iter->boundaries(); if ( $o->get('dry-run') ) { print "Not copying rows because this is a dry run.\n"; } else { - print "Copying approximately ", $nibble_iter->row_estimate(), - " rows...\n"; + if ( !$nibble_iter->one_nibble() && !$boundary->{first_lower} ) { + # https://bugs.launchpad.net/percona-toolkit/+bug/1020997 + print "$tbl->{name} is empty, no rows to copy.\n"; + return; + } + else { + print "Copying approximately ", $nibble_iter->row_estimate(), + " rows...\n"; + } } if ( $o->get('print') ) { diff --git a/lib/NibbleIterator.pm b/lib/NibbleIterator.pm index a43bcf4e..e1a42703 100644 --- a/lib/NibbleIterator.pm +++ b/lib/NibbleIterator.pm @@ -286,6 +286,11 @@ sub next { return; } } + if ( !$self->{one_nibble} && !$self->{first_lower} ) { + PTDEBUG && _d('No first lower boundary, table must be empty'); + $self->{no_more_boundaries} = 1; + return; + } } # If there's another nibble, fetch the rows within it. diff --git a/t/lib/NibbleIterator.t b/t/lib/NibbleIterator.t index 8b8e8e5b..1fc4cb22 100644 --- a/t/lib/NibbleIterator.t +++ b/t/lib/NibbleIterator.t @@ -249,7 +249,7 @@ is_deeply( \@rows, $all_rows, '1 nibble' -) or print Dumper(\@rows); +) or diag(Dumper(\@rows)); # ############################################################################ # single row table @@ -274,7 +274,7 @@ is_deeply( \@rows, [['d']], 'single row table' -) or print Dumper(\@rows); +) or diag(Dumper(\@rows)); # ############################################################################ # empty table @@ -294,7 +294,7 @@ is_deeply( \@rows, [], 'empty table' -) or print Dumper(\@rows); +) or diag(Dumper(\@rows)); # ############################################################################ # Callbacks @@ -397,35 +397,35 @@ is_deeply( $row, [25, 'da79784d'], "SELECT chunk checksum 1 FROM sakila.country" -) or print STDERR Dumper($row); +) or diag(Dumper($row)); $row = $ni->next(); is_deeply( $row, [25, 'e860c4f9'], "SELECT chunk checksum 2 FROM sakila.country" -) or print STDERR Dumper($row); +) or diag(Dumper($row)); $row = $ni->next(); is_deeply( $row, [25, 'eb651f58'], "SELECT chunk checksum 3 FROM sakila.country" -) or print STDERR Dumper($row); +) or diag(Dumper($row)); $row = $ni->next(); is_deeply( $row, [25, '2d87d588'], "SELECT chunk checksum 4 FROM sakila.country" -) or print STDERR Dumper($row); +) or diag(Dumper($row)); $row = $ni->next(); is_deeply( $row, [9, 'beb4a180'], "SELECT chunk checksum 5 FROM sakila.country" -) or print STDERR Dumper($row); +) or diag(Dumper($row)); # ######################################################################### @@ -552,7 +552,7 @@ is_deeply( [ 'z' ], # last nibble ], "Change chunk size while nibbling" -) or print STDERR Dumper(\@rows); +) or diag(Dumper(\@rows)); # ############################################################################ # Nibble one row at a time.