Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec: fix possible infinite loops in the benchmark #37106

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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