mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/mergeset: do not store commonPrefix in blockHeader if the block contains only a single item
There is no sense in storing commonPrefix for blockHeader containing only a single item, since this only increases blockHeader size without any benefits.
This commit is contained in:
parent
84a3f4719d
commit
9a3a88b321
1 changed files with 7 additions and 6 deletions
|
@ -104,17 +104,18 @@ func (ib *inmemoryBlock) Reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ib *inmemoryBlock) updateCommonPrefixSorted() {
|
func (ib *inmemoryBlock) updateCommonPrefixSorted() {
|
||||||
ib.commonPrefix = ib.commonPrefix[:0]
|
|
||||||
items := ib.items
|
items := ib.items
|
||||||
if len(items) == 0 {
|
if len(items) <= 1 {
|
||||||
|
// There is no sense in duplicating a single item or zero items into commonPrefix,
|
||||||
|
// since this only can increase blockHeader size without any benefits.
|
||||||
|
ib.commonPrefix = ib.commonPrefix[:0]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := ib.data
|
data := ib.data
|
||||||
cp := items[0].Bytes(data)
|
cp := items[0].Bytes(data)
|
||||||
if len(items) > 1 {
|
cpLen := commonPrefixLen(cp, items[len(items)-1].Bytes(data))
|
||||||
cpLen := commonPrefixLen(cp, items[len(items)-1].Bytes(data))
|
cp = cp[:cpLen]
|
||||||
cp = cp[:cpLen]
|
|
||||||
}
|
|
||||||
ib.commonPrefix = append(ib.commonPrefix[:0], cp...)
|
ib.commonPrefix = append(ib.commonPrefix[:0], cp...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue