Skip to content

Commit

Permalink
crdb: fix untyped version seek
Browse files Browse the repository at this point in the history
The comparison when searching for an untyped version was in the wrong
direction (suffixes are in reverse order).
  • Loading branch information
RaduBerinde committed Oct 23, 2024
1 parent d6a032b commit 6c8d32b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/crdbtest/crdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ func (ks *cockroachKeySeeker) seekGEOnSuffix(index int, seekSuffix []byte) (row
for l < u {
h := int(uint(l+u) >> 1) // avoid overflow when computing h
// l ≤ h < u
if bytes.Compare(ks.untypedVersions.At(h), seekSuffix) >= 0 {
if bytes.Compare(ks.untypedVersions.At(h), seekSuffix) <= 0 {
u = h // preserves f(u) == true
} else {
l = h + 1 // preserves f(l-1) == false
Expand Down
24 changes: 12 additions & 12 deletions internal/crdbtest/testdata/seek
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fo @ 0102030405060708 #1,SET = v0
fo @ 0102030405060707 #1,SET = v0
----
fo: fo @ 0102030405060708 #1,SET = row0
fo @ 05: foo @ 0102030405060708 #1,SET = row1
fo @ 05: foo @ 0102030405060708 #1,SET = row1
fo @ 05: fo @ 0102030405060708 #1,SET = row0
fo @ 05: fo @ 0102030405060708 #1,SET = row0
fo @ 0102030405060709: fo @ 0102030405060708 #1,SET = row0
fo @ 0102030405060708: fo @ 0102030405060708 #1,SET = row0
fo @ 0102030405060707: foo @ 0102030405060708 #1,SET = row1
Expand Down Expand Up @@ -105,9 +105,9 @@ fo @ 0000000000000000000000000000000001
----
a: fo @ 0000000000000000000000000000000002 #1,SET = row0
fo: fo @ 0000000000000000000000000000000002 #1,SET = row0
fo @ 0000000000000000000000000000000003: foo @ 0000000000000000000000000000000010 #1,SET = row1
fo @ 0000000000000000000000000000000003: fo @ 0000000000000000000000000000000002 #1,SET = row0
fo @ 0000000000000000000000000000000002: fo @ 0000000000000000000000000000000002 #1,SET = row0
fo @ 0000000000000000000000000000000001: fo @ 0000000000000000000000000000000002 #1,SET = row0
fo @ 0000000000000000000000000000000001: foo @ 0000000000000000000000000000000010 #1,SET = row1

seek
foo
Expand All @@ -121,13 +121,13 @@ foo @ 0000000000000000000000000000000001
foo @ 0000000000000000000000000000000000
----
foo: foo @ 0000000000000000000000000000000010 #1,SET = row1
foo @ 0000000000000000000000000000000015: z @ 0000000000000000000000000000000001 #1,SET = row5
foo @ 0000000000000000000000000000000010: z @ 0000000000000000000000000000000001 #1,SET = row5
foo @ 0000000000000000000000000000000009: z @ 0000000000000000000000000000000001 #1,SET = row5
foo @ 0000000000000000000000000000000008: z @ 0000000000000000000000000000000001 #1,SET = row5
foo @ 0000000000000000000000000000000007: z @ 0000000000000000000000000000000001 #1,SET = row5
foo @ 0000000000000000000000000000000002: foo @ 0000000000000000000000000000000010 #1,SET = row1
foo @ 0000000000000000000000000000000001: foo @ 0000000000000000000000000000000010 #1,SET = row1
foo @ 0000000000000000000000000000000000: foo @ 0000000000000000000000000000000010 #1,SET = row1
foo @ 0000000000000000000000000000000015: foo @ 0000000000000000000000000000000010 #1,SET = row1
foo @ 0000000000000000000000000000000010: foo @ 0000000000000000000000000000000010 #1,SET = row1
foo @ 0000000000000000000000000000000009: foo @ 0000000000000000000000000000000008 #1,SET = row2
foo @ 0000000000000000000000000000000008: foo @ 0000000000000000000000000000000008 #1,SET = row2
foo @ 0000000000000000000000000000000007: foo @ 0000000000000000000000000000000002 #1,SET = row3
foo @ 0000000000000000000000000000000002: foo @ 0000000000000000000000000000000002 #1,SET = row3
foo @ 0000000000000000000000000000000001: foo @ 0000000000000000000000000000000001 #1,SET = row4
foo @ 0000000000000000000000000000000000: z @ 0000000000000000000000000000000001 #1,SET = row5

# TODO(radu): tests with mixed types of versions.

0 comments on commit 6c8d32b

Please sign in to comment.