This commit is contained in:
Aliaksandr Valialkin 2024-05-06 19:02:47 +02:00
parent 39e0412bfc
commit 97786db05e
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -286,17 +286,12 @@ func (shard *pipeSortProcessorShard) createUint64Values(values []string) []uint6
u64, ok := tryParseUint64(v) u64, ok := tryParseUint64(v)
if ok { if ok {
u64ValuesBuf = append(u64ValuesBuf, u64) u64ValuesBuf = append(u64ValuesBuf, u64)
continue
} }
u32, ok := tryParseIPv4(v) u32, _ := tryParseIPv4(v)
if ok { u64ValuesBuf = append(u64ValuesBuf, uint64(u32))
u64ValuesBuf = append(u64ValuesBuf, uint64(u32)) // Do not try parsing timestamp and duration, since they may be negative.
} // This breaks sorting.
i64, ok := tryParseTimestampRFC3339Nano(v)
if ok {
u64ValuesBuf = append(u64ValuesBuf, uint64(i64))
}
i64, ok = tryParseDuration(v)
u64ValuesBuf = append(u64ValuesBuf, uint64(i64))
} }
shard.u64ValuesBuf = u64ValuesBuf shard.u64ValuesBuf = u64ValuesBuf
@ -433,7 +428,7 @@ func (psp *pipeSortProcessor) flush() error {
} }
} }
if sortBlockLess(shardNext, shardNext.rowRefNext, shard, shard.rowRefNext) {d if sortBlockLess(shardNext, shardNext.rowRefNext, shard, shard.rowRefNext) {
heap.Fix(&sh, 0) heap.Fix(&sh, 0)
shardNext = nil shardNext = nil
@ -464,8 +459,8 @@ type pipeSortWriteContext struct {
} }
func (wctx *pipeSortWriteContext) writeRow(shard *pipeSortProcessorShard, rowIdx uint) { func (wctx *pipeSortWriteContext) writeRow(shard *pipeSortProcessorShard, rowIdx uint) {
rowRef := shard.rowRefs[rowIdx] rr := shard.rowRefs[rowIdx]
block := &shard.blocks[rowRef.blockIdx] block := &shard.blocks[rr.blockIdx]
byFields := shard.ps.byFields byFields := shard.ps.byFields
rcs := wctx.rcs rcs := wctx.rcs
@ -498,12 +493,12 @@ func (wctx *pipeSortWriteContext) writeRow(shard *pipeSortProcessorShard, rowIdx
} }
for i, c := range block.byColumns { for i, c := range block.byColumns {
v := c.values[rowRef.rowIdx] v := c.values[rr.rowIdx]
rcs[i].addValue(v) rcs[i].addValue(v)
wctx.valuesLen += len(v) wctx.valuesLen += len(v)
} }
for i, c := range block.otherColumns { for i, c := range block.otherColumns {
v := c.values[rowRef.rowIdx] v := c.values[rr.rowIdx]
rcs[len(byFields)+i].addValue(v) rcs[len(byFields)+i].addValue(v)
wctx.valuesLen += len(v) wctx.valuesLen += len(v)
} }
@ -566,10 +561,10 @@ func (sh *pipeSortProcessorShardsHeap) Pop() any {
func sortBlockLess(shardA *pipeSortProcessorShard, rowIdxA uint, shardB *pipeSortProcessorShard, rowIdxB uint) bool { func sortBlockLess(shardA *pipeSortProcessorShard, rowIdxA uint, shardB *pipeSortProcessorShard, rowIdxB uint) bool {
byFields := shardA.ps.byFields byFields := shardA.ps.byFields
rowRefA := shardA.rowRefs[rowIdxA] rrA := shardA.rowRefs[rowIdxA]
rowRefB := shardB.rowRefs[rowIdxB] rrB := shardB.rowRefs[rowIdxB]
csA := shardA.blocks[rowRefA.blockIdx].byColumns csA := shardA.blocks[rrA.blockIdx].byColumns
csB := shardB.blocks[rowRefB.blockIdx].byColumns csB := shardB.blocks[rrB.blockIdx].byColumns
for idx := range csA { for idx := range csA {
cA := &csA[idx] cA := &csA[idx]
cB := &csB[idx] cB := &csB[idx]
@ -577,8 +572,8 @@ func sortBlockLess(shardA *pipeSortProcessorShard, rowIdxA uint, shardB *pipeSor
if len(cA.timestamps) > 0 && len(cB.timestamps) > 0 { if len(cA.timestamps) > 0 && len(cB.timestamps) > 0 {
// Fast path - sort by _time // Fast path - sort by _time
tA := cA.timestamps[rowIdxA] tA := cA.timestamps[rrA.rowIdx]
tB := cB.timestamps[rowIdxB] tB := cB.timestamps[rrB.rowIdx]
if tA == tB { if tA == tB {
continue continue
} }
@ -589,8 +584,8 @@ func sortBlockLess(shardA *pipeSortProcessorShard, rowIdxA uint, shardB *pipeSor
} }
// Try sorting by uint64 values at first // Try sorting by uint64 values at first
uA := cA.u64Values[rowIdxA] uA := cA.u64Values[rrA.rowIdx]
uB := cB.u64Values[rowIdxB] uB := cB.u64Values[rrB.rowIdx]
if uA != 0 && uB != 0 { if uA != 0 && uB != 0 {
if uA == uB { if uA == uB {
continue continue
@ -602,8 +597,8 @@ func sortBlockLess(shardA *pipeSortProcessorShard, rowIdxA uint, shardB *pipeSor
} }
// Try sorting by float64 then // Try sorting by float64 then
fA := cA.f64Values[rowIdxA] fA := cA.f64Values[rrA.rowIdx]
fB := cB.f64Values[rowIdxB] fB := cB.f64Values[rrB.rowIdx]
if !math.IsNaN(fA) && !math.IsNaN(fB) { if !math.IsNaN(fA) && !math.IsNaN(fB) {
if fA == fB { if fA == fB {
continue continue
@ -615,8 +610,8 @@ func sortBlockLess(shardA *pipeSortProcessorShard, rowIdxA uint, shardB *pipeSor
} }
// Fall back to string sorting // Fall back to string sorting
sA := cA.values[rowIdxA] sA := cA.values[rrA.rowIdx]
sB := cB.values[rowIdxB] sB := cB.values[rrB.rowIdx]
if sA == sB { if sA == sB {
continue continue
} }