Skip to content

Commit

Permalink
Merge #38512
Browse files Browse the repository at this point in the history
38512: exec: fix bug in ordered aggregate planning r=jordanlewis a=jordanlewis

Previously, there was a bug that caused ordered aggregations to not be
planned correctly when some columns weren't present in the grouping
columns.

Fixes #37332.

Release note: None

Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
  • Loading branch information
craig[bot] and jordanlewis committed Jun 27, 2019
2 parents 6ad3692 + e4773fa commit dc80eb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
16 changes: 1 addition & 15 deletions pkg/sql/exec/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -302,19 +301,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 {
Expand Down
17 changes: 17 additions & 0 deletions pkg/sql/exec/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit dc80eb5

Please sign in to comment.