Skip to content

Commit

Permalink
exec: fix possible infinite loops in the benchmark
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
yuzefovich committed Apr 29, 2019
1 parent df024f7 commit 56906de
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 56906de

Please sign in to comment.