Skip to content

Commit

Permalink
Merge pull request #78996 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.1-78704

release-22.1: sql: propagate limit for top K sort correctly in tests
  • Loading branch information
yuzefovich authored Mar 30, 2022
2 parents 9296eed + b30a916 commit 88c3b91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 1 addition & 3 deletions pkg/sql/colexec/external_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,13 @@ func createDiskBackedSorter(
sorterSpec := &execinfrapb.SorterSpec{
OutputOrdering: execinfrapb.Ordering{Columns: ordCols},
OrderingMatchLen: uint32(matchLen),
Limit: int64(k),
}
spec := &execinfrapb.ProcessorSpec{
Input: []execinfrapb.InputSyncSpec{{ColumnTypes: typs}},
Core: execinfrapb.ProcessorCoreUnion{
Sorter: sorterSpec,
},
Post: execinfrapb.PostProcessSpec{
Limit: k,
},
ResultTypes: typs,
}
args := &colexecargs.NewColOperatorArgs{
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/distsql/columnar_operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,15 @@ func TestSorterAgainstProcessor(t *testing.T) {
sorterSpec := &execinfrapb.SorterSpec{
OutputOrdering: execinfrapb.Ordering{Columns: orderingCols},
}
var limit, offset uint64
var offset uint64
if topK > 0 {
offset = uint64(rng.Intn(int(topK)))
limit = topK - offset
sorterSpec.Limit = int64(topK - offset)
}
pspec := &execinfrapb.ProcessorSpec{
Input: []execinfrapb.InputSyncSpec{{ColumnTypes: inputTypes}},
Core: execinfrapb.ProcessorCoreUnion{Sorter: sorterSpec},
Post: execinfrapb.PostProcessSpec{Limit: limit, Offset: offset},
Post: execinfrapb.PostProcessSpec{Offset: offset},
ResultTypes: inputTypes,
}
args := verifyColOperatorArgs{
Expand Down
7 changes: 4 additions & 3 deletions pkg/sql/rowexec/sorter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,15 @@ func BenchmarkSortLimit(b *testing.B) {
const numRows = 1 << 16
b.Run(fmt.Sprintf("rows=%d", numRows), func(b *testing.B) {
input := execinfra.NewRepeatableRowSource(types.TwoIntCols, randgen.MakeRandIntRows(rng, numRows, numCols))
for _, limit := range []uint64{1 << 4, 1 << 8, 1 << 12, 1 << 16} {
post := execinfrapb.PostProcessSpec{Limit: limit}
for _, limit := range []int64{1 << 4, 1 << 8, 1 << 12, 1 << 16} {
spec.Limit = limit
b.Run(fmt.Sprintf("Limit=%d", limit), func(b *testing.B) {
b.SetBytes(int64(numRows * numCols * 8))
b.ResetTimer()
for i := 0; i < b.N; i++ {
s, err := newSorter(
context.Background(), &flowCtx, 0 /* processorID */, &spec, input, &post, &rowDisposer{},
context.Background(), &flowCtx, 0, /* processorID */
&spec, input, &execinfrapb.PostProcessSpec{Limit: 0}, &rowDisposer{},
)
if err != nil {
b.Fatal(err)
Expand Down

0 comments on commit 88c3b91

Please sign in to comment.