From e4773fae8f0cc378b418461a99160ea2f7710095 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Thu, 27 Jun 2019 12:41:27 -0400 Subject: [PATCH] exec: fix bug in ordered aggregate planning Previously, there was a bug that caused ordered aggregations to not be planned correctly when some columns weren't present in the grouping columns. Release note: None --- pkg/sql/exec/aggregator.go | 16 +--------------- pkg/sql/exec/aggregator_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pkg/sql/exec/aggregator.go b/pkg/sql/exec/aggregator.go index 5956d9972446..29ba47e14d88 100644 --- a/pkg/sql/exec/aggregator.go +++ b/pkg/sql/exec/aggregator.go @@ -127,10 +127,9 @@ func NewOrderedAggregator( ) } - groupTypes := extractGroupTypes(groupCols, colTypes) aggTypes := extractAggTypes(aggCols, colTypes) - op, groupCol, err := OrderedDistinctColsToOperators(input, groupCols, groupTypes) + op, groupCol, err := OrderedDistinctColsToOperators(input, groupCols, colTypes) if err != nil { return nil, err } @@ -296,19 +295,6 @@ func (a *orderedAggregator) reset() { } } -// extractGroupTypes returns an array representing the type corresponding to -// each group column. This information is extracted from the group column -// indices and their corresponding column types. -func extractGroupTypes(groupCols []uint32, colTypes []types.T) []types.T { - groupTyps := make([]types.T, len(groupCols)) - - for i, colIdx := range groupCols { - groupTyps[i] = colTypes[colIdx] - } - - return groupTyps -} - // extractAggTypes returns a nested array representing the input types // corresponding to each aggregation function. func extractAggTypes(aggCols [][]uint32, colTypes []types.T) [][]types.T { diff --git a/pkg/sql/exec/aggregator_test.go b/pkg/sql/exec/aggregator_test.go index a51d5bc0831d..7b44afe901ba 100644 --- a/pkg/sql/exec/aggregator_test.go +++ b/pkg/sql/exec/aggregator_test.go @@ -235,6 +235,23 @@ func TestAggregatorOneFunc(t *testing.T) { name: "NoGroupingCols", groupCols: []uint32{}, }, + { + input: tuples{ + {1, 0, 0}, + {2, 0, 0}, + {3, 0, 0}, + {4, 0, 0}, + }, + expected: tuples{ + {10}, + }, + batchSize: 1, + outputBatchSize: 1, + name: "UnusedInputColumns", + colTypes: []types.T{types.Int64, types.Int64, types.Int64}, + groupCols: []uint32{1, 2}, + aggCols: [][]uint32{{0}}, + }, } // Run tests with deliberate batch sizes and no selection vectors.