Get CRC function once, not per-table.

This commit is contained in:
Daniel Nichter
2011-09-12 10:35:20 -06:00
parent 75f554ea7d
commit 5e7cb7597d

View File

@@ -3246,37 +3246,34 @@ sub make_chunk_checksum {
if ( !$args{dbh} && !($args{func} && $args{crc_width} && $args{crc_type}) ) { if ( !$args{dbh} && !($args{func} && $args{crc_width} && $args{crc_type}) ) {
die "I need a dbh argument" die "I need a dbh argument"
} }
my ($tbl) = @args{@required_args}; my ($tbl) = @args{@required_args};
my $o = $self->{OptionParser}; my $o = $self->{OptionParser};
my $q = $self->{Quoter}; my $q = $self->{Quoter};
my $func = $args{func} || $self->_get_hash_func(%args); my %crc_args = $self->get_crc_args(%args);
my $crc_width = $args{crc_width}|| $self->_get_crc_width(%args, func=>$func);
my $crc_type = $args{crc_type} || $self->_get_crc_type(%args, func=>$func);
my $opt_slice; my $opt_slice;
if ( $o->get('optimize-xor') ) { if ( $o->get('optimize-xor') ) {
if ( $crc_type !~ m/int$/ ) { if ( $crc_args{crc_type} !~ m/int$/ ) {
$opt_slice = $self->_optimize_xor(%args, func => $func); $opt_slice = $self->_optimize_xor(%args, %crc_args);
warn "Cannot use --optimize-xor" unless defined $opt_slice; warn "Cannot use --optimize-xor" unless defined $opt_slice;
} }
} }
MKDEBUG && _d("Checksum strat:", $func, $crc_width, $crc_type, $opt_slice); MKDEBUG && _d("Checksum strat:", Dumper(\%crc_args));
my $row_checksum = $self->make_row_checksum( my $row_checksum = $self->make_row_checksum(
%args, %args,
func => $func, %crc_args,
no_cols => 1 no_cols => 1
); );
my $crc; my $crc;
if ( $crc_type =~ m/int$/ ) { if ( $crc_args{crc_type} =~ m/int$/ ) {
$crc = "COALESCE(LOWER(CONV(BIT_XOR(CAST($row_checksum AS UNSIGNED)), " $crc = "COALESCE(LOWER(CONV(BIT_XOR(CAST($row_checksum AS UNSIGNED)), "
. "10, 16)), 0)"; . "10, 16)), 0)";
} }
else { else {
my $slices = $self->_make_xor_slices( my $slices = $self->_make_xor_slices(
row_checksum => $row_checksum, row_checksum => $row_checksum,
crc_width => $crc_width %crc_args,
); );
$crc = "COALESCE(LOWER(CONCAT($slices)), 0)"; $crc = "COALESCE(LOWER(CONCAT($slices)), 0)";
} }
@@ -3286,6 +3283,18 @@ sub make_chunk_checksum {
return $select; return $select;
} }
sub get_crc_args {
my ($self, %args) = @_;
my $func = $args{func} || $self->_get_hash_func(%args);
my $crc_width = $args{crc_width}|| $self->_get_crc_width(%args, func=>$func);
my $crc_type = $args{crc_type} || $self->_get_crc_type(%args, func=>$func);
return (
func => $func,
crc_width => $crc_width,
crc_type => $crc_type,
);
}
sub _get_hash_func { sub _get_hash_func {
my ( $self, %args ) = @_; my ( $self, %args ) = @_;
my @required_args = qw(dbh); my @required_args = qw(dbh);
@@ -4944,6 +4953,7 @@ sub main {
# ######################################################################## # ########################################################################
# Checksum query statementn and sths to update the checksum table. # Checksum query statementn and sths to update the checksum table.
# ######################################################################## # ########################################################################
my %crc_args = $rc->get_crc_args(dbh => $dbh);
my $checksum_dms = "REPLACE INTO $repl_table " my $checksum_dms = "REPLACE INTO $repl_table "
. "(db, tbl, chunk, boundaries, this_cnt, this_crc) " . "(db, tbl, chunk, boundaries, this_cnt, this_crc) "
. "SELECT ?, ?, ?, ?,"; . "SELECT ?, ?, ?, ?,";
@@ -5008,7 +5018,11 @@ sub main {
# be saved here. print_checksum_results() uses this info. # be saved here. print_checksum_results() uses this info.
$tbl->{checksum_results}->{exit_status} = 0; $tbl->{checksum_results}->{exit_status} = 0;
my $checksum_cols = $rc->make_chunk_checksum(dbh => $dbh, tbl => $tbl); my $checksum_cols = $rc->make_chunk_checksum(
dbh => $dbh,
tbl => $tbl,
%crc_args
);
my $nibble_iter = new NibbleIterator( my $nibble_iter = new NibbleIterator(
dbh => $dbh, dbh => $dbh,
tbl => $tbl, tbl => $tbl,