Skip to content

Commit

Permalink
perf(col_low_cardinality): use small value
Browse files Browse the repository at this point in the history
  • Loading branch information
zdyj3170101136 committed Oct 17, 2024
1 parent a64f2cd commit 618b1c1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions proto/col_low_cardinality.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,6 @@ func (c ColLowCardinality[T]) Rows() int {

// Prepare column for ingestion.
func (c *ColLowCardinality[T]) Prepare() error {
// Select minimum possible size for key.
if n := len(c.Values); n < math.MaxUint8 {
c.key = KeyUInt8
} else if n < math.MaxUint16 {
c.key = KeyUInt16
} else if uint32(n) < math.MaxUint32 {
c.key = KeyUInt32
} else {
c.key = KeyUInt64
}

// Allocate keys slice.
c.keys = append(c.keys[:0], make([]int, len(c.Values))...)
if c.kv == nil {
Expand All @@ -317,6 +306,17 @@ func (c *ColLowCardinality[T]) Prepare() error {
c.keys[i] = idx
}

// Select minimum possible size for key.
if n := last; n < math.MaxUint8 {
c.key = KeyUInt8
} else if n < math.MaxUint16 {
c.key = KeyUInt16
} else if uint32(n) < math.MaxUint32 {
c.key = KeyUInt32
} else {
c.key = KeyUInt64
}

// Fill key column with key indexes.
switch c.key {
case KeyUInt8:
Expand Down

0 comments on commit 618b1c1

Please sign in to comment.