PT-1757 Implemented fallback in NibbleIterator

Since now NibbleIterator can fallback to nibble (from one chunk) pt-osc
can nibble tables even if due to unacurate stats, it choses one nible as
the initial nibbling method.
This commit is contained in:
Carlos Salguero
2019-10-13 21:58:56 -03:00
parent e58b9fbea8
commit 6a302e2b07
12 changed files with 549 additions and 398 deletions

View File

@@ -125,6 +125,7 @@ sub generate_asc_stmt {
cols => \@cols,
quoter => $q,
is_nullable => $tbl_struct->{is_nullable},
type_for => $tbl_struct->{type_for},
);
$asc_stmt->{boundaries}->{$cmp} = $cmp_where->{where};
}
@@ -152,6 +153,7 @@ sub generate_cmp_where {
my @slice = @{$args{slice}};
my @cols = @{$args{cols}};
my $is_nullable = $args{is_nullable};
my $type_for = $args{type_for};
my $type = $args{type};
my $q = $self->{Quoter};
@@ -169,13 +171,14 @@ sub generate_cmp_where {
my $ord = $slice[$j];
my $col = $cols[$ord];
my $quo = $q->quote($col);
my $val = ($col && ($type_for->{$col} || '')) eq 'enum' ? "CAST(? AS UNSIGNED)" : "?";
if ( $is_nullable->{$col} ) {
push @clause, "((? IS NULL AND $quo IS NULL) OR ($quo = ?))";
push @clause, "(($val IS NULL AND $quo IS NULL) OR ($quo = $val))";
push @r_slice, $ord, $ord;
push @r_scols, $col, $col;
}
else {
push @clause, "$quo = ?";
push @clause, "$quo = $val";
push @r_slice, $ord;
push @r_scols, $col;
}
@@ -188,15 +191,16 @@ sub generate_cmp_where {
my $col = $cols[$ord];
my $quo = $q->quote($col);
my $end = $i == $#slice; # Last clause of the whole group.
my $val = ($col && ($type_for->{$col} || '')) eq 'enum' ? "CAST(? AS UNSIGNED)" : "?";
if ( $is_nullable->{$col} ) {
if ( $type =~ m/=/ && $end ) {
push @clause, "(? IS NULL OR $quo $type ?)";
push @clause, "($val IS NULL OR $quo $type $val)";
}
elsif ( $type =~ m/>/ ) {
push @clause, "((? IS NULL AND $quo IS NOT NULL) OR ($quo $cmp ?))";
push @clause, "(($val IS NULL AND $quo IS NOT NULL) OR ($quo $cmp $val)";
}
else { # If $type =~ m/</ ) {
push @clause, "((? IS NOT NULL AND $quo IS NULL) OR ($quo $cmp ?))";
push @clauses, "(($val IS NOT NULL AND $quo IS NULL) OR ($quo $cmp $val))";
}
push @r_slice, $ord, $ord;
push @r_scols, $col, $col;
@@ -204,7 +208,7 @@ sub generate_cmp_where {
else {
push @r_slice, $ord;
push @r_scols, $col;
push @clause, ($type =~ m/=/ && $end ? "$quo $type ?" : "$quo $cmp ?");
push @clause, ($type =~ m/=/ && $end ? "$quo $type $val" : "$quo $cmp $val");
}
# Add the clause to the larger WHERE clause.