This commit is contained in:
Aliaksandr Valialkin 2024-04-29 00:05:31 +02:00
parent 24f07dfdc3
commit 20fd87f86f
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
4 changed files with 64 additions and 0 deletions

View file

@ -405,6 +405,11 @@ func (br *blockResult) mustInit(bs *blockSearch, bm *filterBitmap) {
}
// Initialize timestamps, since they are used for determining the number of rows in br.RowsCount()
srcTimestamps := bs.getTimestamps()
if bm.areAllBitsSet() {
br.timestamps = append(br.timestamps[:0], srcTimestamps...)
return
}
dstTimestamps := br.timestamps[:0]
bm.forEachSetBit(func(idx int) bool {
ts := srcTimestamps[idx]

View file

@ -91,6 +91,22 @@ func (bm *filterBitmap) isZero() bool {
return true
}
func (bm *filterBitmap) areAllBitsSet() bool {
a := bm.a
for i, word := range a {
if word != (1<<64)-1 {
if i+1 < len(a) {
return false
}
tailBits := bm.bitsLen % 64
if tailBits == 0 || word != (uint64(1)<<tailBits)-1 {
return false
}
}
}
return true
}
func (bm *filterBitmap) andNot(x *filterBitmap) {
if bm.bitsLen != x.bitsLen {
logger.Panicf("BUG: cannot merge bitmaps with distinct lengths; %d vs %d", bm.bitsLen, x.bitsLen)

View file

@ -252,6 +252,18 @@ func TestFilterBitmap(t *testing.T) {
t.Fatalf("unexpected bits length: %d; want %d", bm.bitsLen, i)
}
if !bm.isZero() {
t.Fatalf("all the bits must be zero for bitmap with %d bits", i)
}
if i == 0 && !bm.areAllBitsSet() {
t.Fatalf("areAllBitsSet() must return true for bitmap with 0 bits")
}
if i > 0 && bm.areAllBitsSet() {
t.Fatalf("areAllBitsSet() must return false on new bitmap with %d bits; %#v", i, bm)
}
bm.setBits()
// Make sure that all the bits are set.
nextIdx := 0
bm.forEachSetBit(func(idx int) bool {
@ -265,10 +277,28 @@ func TestFilterBitmap(t *testing.T) {
return true
})
if !bm.areAllBitsSet() {
t.Fatalf("all bits must be set for bitmap with %d bits", i)
}
// Clear a part of bits
bm.forEachSetBit(func(idx int) bool {
return idx%2 != 0
})
if i <= 1 && !bm.isZero() {
t.Fatalf("bm.isZero() must return true for bitmap with %d bits", i)
}
if i > 1 && bm.isZero() {
t.Fatalf("bm.isZero() must return false, since some bits are set for bitmap with %d bits", i)
}
if i == 0 && !bm.areAllBitsSet() {
t.Fatalf("areAllBitsSet() must return true for bitmap with 0 bits")
}
if i > 0 && bm.areAllBitsSet() {
t.Fatalf("some bits mustn't be set for bitmap with %d bits", i)
}
nextIdx = 1
bm.forEachSetBit(func(idx int) bool {
if idx != nextIdx {
@ -282,6 +312,17 @@ func TestFilterBitmap(t *testing.T) {
bm.forEachSetBit(func(_ int) bool {
return false
})
if !bm.isZero() {
t.Fatalf("all the bits must be reset for bitmap with %d bits", i)
}
if i == 0 && !bm.areAllBitsSet() {
t.Fatalf("allAllBitsSet() must return true for bitmap with 0 bits")
}
if i > 0 && bm.areAllBitsSet() {
t.Fatalf("areAllBitsSet() must return false for bitmap with %d bits", i)
}
bitsCount := 0
bm.forEachSetBit(func(_ int) bool {
bitsCount++

View file

@ -616,6 +616,8 @@ func (sfcp *statsFuncCountProcessor) updateStatsForAllRows(timestamps []int64, c
// Slow path - count rows containing at least a single non-empty value for the fields enumerated inside count().
bm := getFilterBitmap(len(timestamps))
defer putFilterBitmap(bm)
bm.setBits()
for _, f := range fields {
if idx := getBlockColumnIndex(columns, f); idx >= 0 {