Skip to content

Commit

Permalink
util: increase column's nullBitmap's capacity (#12470) (#16141)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Apr 9, 2020
1 parent 2ade419 commit 792ce6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions util/chunk/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func newFixedLenColumn(elemLen, cap int) *column {
return &column{
elemBuf: make([]byte, elemLen),
data: make([]byte, 0, cap*elemLen),
nullBitmap: make([]byte, 0, cap>>3),
nullBitmap: make([]byte, 0, (cap+7)>>3),
}
}

Expand All @@ -147,7 +147,7 @@ func newVarLenColumn(cap int, old *column) *column {
return &column{
offsets: make([]int64, 1, cap+1),
data: make([]byte, 0, cap*estimatedElemLen),
nullBitmap: make([]byte, 0, cap>>3),
nullBitmap: make([]byte, 0, (cap+7)>>3),
}
}

Expand Down
13 changes: 7 additions & 6 deletions util/chunk/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,14 @@ func (s *testChunkSuite) TestChunkMemoryUsage(c *check.C) {
initCap := 10
chk := NewChunkWithCapacity(fieldTypes, initCap)

sizeTime := 16
//cap(c.nullBitmap) + cap(c.offsets)*4 + cap(c.data) + cap(c.elemBuf)
colUsage := make([]int, len(fieldTypes))
colUsage[0] = initCap>>3 + 0 + initCap*4 + 4
colUsage[1] = initCap>>3 + (initCap+1)*4 + initCap*8 + 0
colUsage[2] = initCap>>3 + (initCap+1)*4 + initCap*8 + 0
colUsage[3] = initCap>>3 + 0 + initCap*16 + 16
colUsage[4] = initCap>>3 + 0 + initCap*8 + 8
colUsage[0] = (initCap+7)>>3 + 0 + initCap*4 + 4
colUsage[1] = (initCap+7)>>3 + (initCap+1)*4 + initCap*8 + 0
colUsage[2] = (initCap+7)>>3 + (initCap+1)*4 + initCap*8 + 0
colUsage[3] = (initCap+7)>>3 + 0 + initCap*sizeTime + sizeTime
colUsage[4] = (initCap+7)>>3 + 0 + initCap*8 + 8

expectedUsage := 0
for i := range colUsage {
Expand Down Expand Up @@ -572,7 +573,7 @@ func (s *testChunkSuite) TestChunkMemoryUsage(c *check.C) {
chk.AppendDuration(4, durationObj)

memUsage = chk.MemoryUsage()
colUsage[1] = initCap>>3 + (initCap+1)*4 + cap(chk.columns[1].data) + 0
colUsage[1] = (initCap+7)>>3 + (initCap+1)*4 + cap(chk.columns[1].data) + 0
expectedUsage = 0
for i := range colUsage {
expectedUsage += colUsage[i] + int(unsafe.Sizeof(*chk.columns[i]))
Expand Down

0 comments on commit 792ce6c

Please sign in to comment.