Created
December 3, 2012 21:29
-
-
Save rcoup/4198249 to your computer and use it in GitHub Desktop.
pg_comparator: #1011286 Hash collisions cause more errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ../2.1/pg_comparator-2.1.1/pg_comparator 2012-08-20 21:15:10.000000000 +1200 | |
+++ pg_comparator 2012-12-04 10:28:33.120672197 +1300 | |
@@ -2148,6 +2148,24 @@ | |
dbh_serialize($dbh, $db); # async_wait if needed | |
} | |
+sub elementwise_compare | |
+{ | |
+ my ($xref, $yref) = @_; | |
+ | |
+ my $i = 0; | |
+ foreach my $x (@{$xref}) { | |
+ my $y = $yref->[$i++]; | |
+ return 1 unless defined($y); | |
+ my $c = $x cmp $y; | |
+ return $c unless ($c == 0); | |
+ } | |
+ if ($i < scalar(@{$yref})) { | |
+ return -1; | |
+ } else { | |
+ return 0; | |
+ } | |
+} | |
+ | |
############################################################### MERGE ALGORITHM | |
# this is the core of the comparison algorithm | |
@@ -2224,7 +2242,7 @@ | |
# their key checksums are equal | |
$kcs1==$kcs2 and | |
# for level 0, the keys are also equal | |
- ($level or @key1 eq @key2)) | |
+ ($level or elementwise_compare(\@key1, \@key2) == 0)) | |
{ | |
die "unexpected undefined tuple checksum" # if not null is wrong... | |
unless defined $tcs1 and defined $tcs2; | |
@@ -2249,7 +2267,7 @@ | |
# or the left side id checksum is less than right side | |
(defined $kcs1 and ($kcs1<$kcs2 or | |
# or special case for level 0 on kcs collision | |
- (not $level and $kcs1==$kcs2 and @key1 lt @key2)))) | |
+ (not $level and $kcs1==$kcs2 and elementwise_compare(\@key1, \@key2) < 0)))) | |
{ | |
# more kcs (/key) in table 1 | |
if ($level) { | |
@@ -2269,7 +2287,7 @@ | |
# or the right side id checksum is less than left side | |
(defined $kcs2 and ($kcs1>$kcs2 or | |
# special case for level 0 on kcs collision | |
- (not $level and $kcs1==$kcs2 and @key1 gt @key2)))) | |
+ (not $level and $kcs1==$kcs2 and elementwise_compare(\@key1, \@key2) > 0)))) | |
{ | |
# more kcs in table 2 | |
if ($level) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment