Skip to content

Commit

Permalink
Merge #37106
Browse files Browse the repository at this point in the history
37106: exec: fix possible infinite loops in the benchmark r=yuzefovich a=yuzefovich

Release note: None

Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
  • Loading branch information
craig[bot] and yuzefovich committed Apr 29, 2019
2 parents f7018cf + 56906de commit 675b1b1
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pkg/sql/exec/selection_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package exec
import (
"context"
"fmt"
"math"
"reflect"
"testing"

Expand Down Expand Up @@ -100,9 +101,14 @@ func benchmarkSelLTInt64Int64ConstOp(b *testing.B, useSelectionVector bool) {
rng, _ := randutil.NewPseudoRand()
ctx := context.Background()

// We need to generate such a batch that selection operator will output at
// least one tuple - otherwise, the benchmark will be stuck in an infinite
// loop, so we put MinInt64 as the first element and make sure that constArg
// is not MinInt64.
batch := coldata.NewMemBatch([]types.T{types.Int64})
col := batch.ColVec(0).Int64()
for i := int64(0); i < coldata.BatchSize; i++ {
col[0] = math.MinInt64
for i := int64(1); i < coldata.BatchSize; i++ {
col[i] = rng.Int63()
}
batch.SetLength(coldata.BatchSize)
Expand All @@ -113,13 +119,18 @@ func benchmarkSelLTInt64Int64ConstOp(b *testing.B, useSelectionVector bool) {
sel[i] = uint16(i)
}
}
constArg := rng.Int63()
for constArg == math.MinInt64 {
constArg = rng.Int63()
}

source := newRepeatableBatchSource(batch)
source.Init()

plusOp := &selLTInt64Int64ConstOp{
input: source,
colIdx: 0,
constArg: rng.Int63(),
constArg: constArg,
}
plusOp.Init()

Expand All @@ -145,7 +156,11 @@ func benchmarkSelLTInt64Int64Op(b *testing.B, useSelectionVector bool) {
batch := coldata.NewMemBatch([]types.T{types.Int64, types.Int64})
col1 := batch.ColVec(0).Int64()
col2 := batch.ColVec(1).Int64()
for i := int64(0); i < coldata.BatchSize; i++ {
// We need to generate such a batch that selection operator will output at
// least one tuple - otherwise, the benchmark will be stuck in an infinite
// loop, so we put 0 and 1 as the first tuple of the batch.
col1[0], col2[0] = 0, 1
for i := int64(1); i < coldata.BatchSize; i++ {
col1[i] = rng.Int63()
col2[i] = rng.Int63()
}
Expand Down

0 comments on commit 675b1b1

Please sign in to comment.