From 618b1c113c1c21b21d0a2a09dcc1b057ace06c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=9D=B0?= Date: Thu, 19 Sep 2024 16:46:13 +0800 Subject: [PATCH] perf(col_low_cardinality): use small value --- proto/col_low_cardinality.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/proto/col_low_cardinality.go b/proto/col_low_cardinality.go index ffed5809..38f3bff1 100644 --- a/proto/col_low_cardinality.go +++ b/proto/col_low_cardinality.go @@ -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 { @@ -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: