Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(col_low_cardinality): use small value. #425

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading