From 454f781cd1b20794df54a65352c9d4ed0e44a22c Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 15 May 2024 16:04:10 +0200 Subject: [PATCH] wip --- lib/logstorage/block_result.go | 8 ++++ lib/logstorage/stats_max.go | 75 +++------------------------------- lib/logstorage/stats_min.go | 75 +++------------------------------- 3 files changed, 20 insertions(+), 138 deletions(-) diff --git a/lib/logstorage/block_result.go b/lib/logstorage/block_result.go index ed0899ef4..626d8365a 100644 --- a/lib/logstorage/block_result.go +++ b/lib/logstorage/block_result.go @@ -396,6 +396,8 @@ func (br *blockResult) addColumn(bs *blockSearch, ch *columnHeader, bm *bitmap) br.csBuf = append(br.csBuf, blockResultColumn{ name: getCanonicalColumnName(name), + minValue: ch.minValue, + maxValue: ch.maxValue, valueType: ch.valueType, dictValues: dictValues, encodedValues: encodedValues, @@ -1333,6 +1335,12 @@ type blockResultColumn struct { // name is column name. name string + // minValue is the minimum value in the block for uint*, float64, ipv4 and timestamp valueType + minValue uint64 + + // maxValue is the maximum value in the block for uint*, float64, ipv4 and timestamp valueType + maxValue uint64 + // isConst is set to true if the column is const. // // The column value is stored in encodedValues[0] diff --git a/lib/logstorage/stats_max.go b/lib/logstorage/stats_max.go index e477a010f..df917abaf 100644 --- a/lib/logstorage/stats_max.go +++ b/lib/logstorage/stats_max.go @@ -122,88 +122,25 @@ func (smp *statsMaxProcessor) updateStateForColumn(br *blockResult, c *blockResu for _, v := range c.dictValues { smp.updateStateString(v) } - case valueTypeUint8: - maxN := unmarshalUint8(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - n := unmarshalUint8(v) - if n > maxN { - maxN = n - } - } + case valueTypeUint8, valueTypeUint16, valueTypeUint32, valueTypeUint64: bb := bbPool.Get() - bb.B = marshalUint8String(bb.B[:0], maxN) - smp.updateStateBytes(bb.B) - bbPool.Put(bb) - case valueTypeUint16: - maxN := unmarshalUint16(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - n := unmarshalUint16(v) - if n > maxN { - maxN = n - } - } - bb := bbPool.Get() - bb.B = marshalUint16String(bb.B[:0], maxN) - smp.updateStateBytes(bb.B) - bbPool.Put(bb) - case valueTypeUint32: - maxN := unmarshalUint32(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - n := unmarshalUint32(v) - if n > maxN { - maxN = n - } - } - bb := bbPool.Get() - bb.B = marshalUint32String(bb.B[:0], maxN) - smp.updateStateBytes(bb.B) - bbPool.Put(bb) - case valueTypeUint64: - maxN := unmarshalUint64(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - n := unmarshalUint64(v) - if n > maxN { - maxN = n - } - } - bb := bbPool.Get() - bb.B = marshalUint64String(bb.B[:0], maxN) + bb.B = marshalUint64String(bb.B[:0], c.maxValue) smp.updateStateBytes(bb.B) bbPool.Put(bb) case valueTypeFloat64: - maxF := unmarshalFloat64(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - f := unmarshalFloat64(v) - if math.IsNaN(maxF) || f > maxF { - maxF = f - } - } + f := math.Float64frombits(c.maxValue) bb := bbPool.Get() - bb.B = marshalFloat64String(bb.B[:0], maxF) + bb.B = marshalFloat64String(bb.B[:0], f) smp.updateStateBytes(bb.B) bbPool.Put(bb) case valueTypeIPv4: - maxIP := unmarshalIPv4(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - ip := unmarshalIPv4(v) - if ip > maxIP { - maxIP = ip - } - } bb := bbPool.Get() - bb.B = marshalIPv4String(bb.B[:0], maxIP) + bb.B = marshalIPv4String(bb.B[:0], uint32(c.maxValue)) smp.updateStateBytes(bb.B) bbPool.Put(bb) case valueTypeTimestampISO8601: - maxTimestamp := unmarshalTimestampISO8601(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - timestamp := unmarshalTimestampISO8601(v) - if timestamp > maxTimestamp { - maxTimestamp = timestamp - } - } bb := bbPool.Get() - bb.B = marshalTimestampISO8601String(bb.B[:0], maxTimestamp) + bb.B = marshalTimestampISO8601String(bb.B[:0], int64(c.maxValue)) smp.updateStateBytes(bb.B) bbPool.Put(bb) default: diff --git a/lib/logstorage/stats_min.go b/lib/logstorage/stats_min.go index 9b614b386..298b1c92a 100644 --- a/lib/logstorage/stats_min.go +++ b/lib/logstorage/stats_min.go @@ -122,88 +122,25 @@ func (smp *statsMinProcessor) updateStateForColumn(br *blockResult, c *blockResu for _, v := range c.dictValues { smp.updateStateString(v) } - case valueTypeUint8: - minN := unmarshalUint8(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - n := unmarshalUint8(v) - if n < minN { - minN = n - } - } + case valueTypeUint8, valueTypeUint16, valueTypeUint32, valueTypeUint64: bb := bbPool.Get() - bb.B = marshalUint8String(bb.B[:0], minN) - smp.updateStateBytes(bb.B) - bbPool.Put(bb) - case valueTypeUint16: - minN := unmarshalUint16(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - n := unmarshalUint16(v) - if n < minN { - minN = n - } - } - bb := bbPool.Get() - bb.B = marshalUint16String(bb.B[:0], minN) - smp.updateStateBytes(bb.B) - bbPool.Put(bb) - case valueTypeUint32: - minN := unmarshalUint32(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - n := unmarshalUint32(v) - if n < minN { - minN = n - } - } - bb := bbPool.Get() - bb.B = marshalUint32String(bb.B[:0], minN) - smp.updateStateBytes(bb.B) - bbPool.Put(bb) - case valueTypeUint64: - minN := unmarshalUint64(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - n := unmarshalUint64(v) - if n < minN { - minN = n - } - } - bb := bbPool.Get() - bb.B = marshalUint64String(bb.B[:0], minN) + bb.B = marshalUint64String(bb.B[:0], c.minValue) smp.updateStateBytes(bb.B) bbPool.Put(bb) case valueTypeFloat64: - minF := unmarshalFloat64(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - f := unmarshalFloat64(v) - if math.IsNaN(minF) || f < minF { - minF = f - } - } + f := math.Float64frombits(c.minValue) bb := bbPool.Get() - bb.B = marshalFloat64String(bb.B[:0], minF) + bb.B = marshalFloat64String(bb.B[:0], f) smp.updateStateBytes(bb.B) bbPool.Put(bb) case valueTypeIPv4: - minIP := unmarshalIPv4(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - ip := unmarshalIPv4(v) - if ip < minIP { - minIP = ip - } - } bb := bbPool.Get() - bb.B = marshalIPv4String(bb.B[:0], minIP) + bb.B = marshalIPv4String(bb.B[:0], uint32(c.minValue)) smp.updateStateBytes(bb.B) bbPool.Put(bb) case valueTypeTimestampISO8601: - minTimestamp := unmarshalTimestampISO8601(c.encodedValues[0]) - for _, v := range c.encodedValues[1:] { - timestamp := unmarshalTimestampISO8601(v) - if timestamp < minTimestamp { - minTimestamp = timestamp - } - } bb := bbPool.Get() - bb.B = marshalTimestampISO8601String(bb.B[:0], minTimestamp) + bb.B = marshalTimestampISO8601String(bb.B[:0], int64(c.minValue)) smp.updateStateBytes(bb.B) bbPool.Put(bb) default: