Skip to content

Commit

Permalink
Merge pull request #425 from zdyj3170101136/fix/col_low_cardinity
Browse files Browse the repository at this point in the history
perf(col_low_cardinality): use small value.
  • Loading branch information
serprex authored Oct 17, 2024
2 parents ea7df0e + 618b1c1 commit 73fa62f
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 @@ -321,17 +321,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 @@ -352,6 +341,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 73fa62f

Please sign in to comment.