Skip to content

Commit

Permalink
exec: fix bug in ordered aggregate planning
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jordanlewis committed Jun 27, 2019
1 parent 667de78 commit e4773fa
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 @@ -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 {
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 e4773fa

Please sign in to comment.