From 2b9bc66c86773d4e20e748a7b710d65dd27c993e Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Fri, 23 Sep 2022 17:56:27 +0000 Subject: [PATCH] sql/row: make reseed cheaper Fixes #88589 Release note: None --- pkg/sql/row/expr_walker.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/sql/row/expr_walker.go b/pkg/sql/row/expr_walker.go index d861bedc31cd..6056d90a6815 100644 --- a/pkg/sql/row/expr_walker.go +++ b/pkg/sql/row/expr_walker.go @@ -86,13 +86,15 @@ type importRand struct { } func (r *importRand) reseed(pos importRandPosition) { - adjPos := (pos / reseedRandEveryN) * reseedRandEveryN - rnd := rand.New(rand.NewSource(int64(adjPos))) + adjPos := int64((pos / reseedRandEveryN) * reseedRandEveryN) + if r.Rand == nil { + r.Rand = rand.New(rand.NewSource(adjPos)) + } else { + r.Rand.Seed(adjPos) + } for i := int(pos % reseedRandEveryN); i > 0; i-- { - _ = rnd.Float64() + _ = r.Rand.Float64() } - - r.Rand = rnd r.pos = pos }