Merge branch 'master' into groupby-cluster-rows

This commit is contained in:
Nia 2021-01-25 15:26:13 -05:00 committed by GitHub
commit 60ab9e84dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 13 deletions

View file

@ -4144,26 +4144,26 @@ func intersectionAnyRunBitmap(a, b *Container) bool {
bb := b.bitmap()[:1024]
runs := a.runs()
for _, r := range runs {
loWord, loBit := r.Start/64, r.Start%64
hiWord, hiBit := r.Last/64, r.Last%64
if loBit != 0 {
w := bb[loWord]
mask := (uint64(1) << loBit) - 1
if w&^mask != 0 {
if r.Start/64 == r.Last/64 {
mask := (^uint64(0) << (r.Start % 64)) &^
(^uint64(0) << ((r.Last % 64) + 1))
if mask&bb[r.Start/64] != 0 {
return true
}
continue
}
for i := loWord; i < hiWord; i++ {
firstWord, lastWord := r.Start/64, r.Last/64
for i := firstWord + 1; i < lastWord; i++ {
if bb[i] != 0 {
return true
}
}
if hiBit != 0 {
w := bb[hiWord]
mask := (uint64(1) << hiBit) - 1
if w&mask != 0 {
return true
}
firstMask := ^uint64(0) << (r.Start % 64)
lastMask := ^(^uint64(0) << ((r.Last % 64) + 1))
if (firstMask&bb[firstWord])|(lastMask&bb[lastWord]) != 0 {
return true
}
}
return false

View file

@ -97,3 +97,15 @@ func TestIntersectVariants(t *testing.T) {
}
}
}
func TestIntersectionAnyRunBitmapSingleWordRegression(t *testing.T) {
// In a previous version, single-word runs would match any bit within the word.
// Verify that this no longer happens.
any := intersectionAnyRunBitmap(
NewContainerRun([]Interval16{{1, 2}}),
NewContainerBitmapN([]uint64{0b1001}, 2),
)
if any {
t.Errorf("matched an exclusive single-word run")
}
}