Skip to content

Commit e4773fa

Browse files
committed
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
1 parent 667de78 commit e4773fa

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

pkg/sql/exec/aggregator.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ func NewOrderedAggregator(
127127
)
128128
}
129129

130-
groupTypes := extractGroupTypes(groupCols, colTypes)
131130
aggTypes := extractAggTypes(aggCols, colTypes)
132131

133-
op, groupCol, err := OrderedDistinctColsToOperators(input, groupCols, groupTypes)
132+
op, groupCol, err := OrderedDistinctColsToOperators(input, groupCols, colTypes)
134133
if err != nil {
135134
return nil, err
136135
}
@@ -296,19 +295,6 @@ func (a *orderedAggregator) reset() {
296295
}
297296
}
298297

299-
// extractGroupTypes returns an array representing the type corresponding to
300-
// each group column. This information is extracted from the group column
301-
// indices and their corresponding column types.
302-
func extractGroupTypes(groupCols []uint32, colTypes []types.T) []types.T {
303-
groupTyps := make([]types.T, len(groupCols))
304-
305-
for i, colIdx := range groupCols {
306-
groupTyps[i] = colTypes[colIdx]
307-
}
308-
309-
return groupTyps
310-
}
311-
312298
// extractAggTypes returns a nested array representing the input types
313299
// corresponding to each aggregation function.
314300
func extractAggTypes(aggCols [][]uint32, colTypes []types.T) [][]types.T {

pkg/sql/exec/aggregator_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ func TestAggregatorOneFunc(t *testing.T) {
235235
name: "NoGroupingCols",
236236
groupCols: []uint32{},
237237
},
238+
{
239+
input: tuples{
240+
{1, 0, 0},
241+
{2, 0, 0},
242+
{3, 0, 0},
243+
{4, 0, 0},
244+
},
245+
expected: tuples{
246+
{10},
247+
},
248+
batchSize: 1,
249+
outputBatchSize: 1,
250+
name: "UnusedInputColumns",
251+
colTypes: []types.T{types.Int64, types.Int64, types.Int64},
252+
groupCols: []uint32{1, 2},
253+
aggCols: [][]uint32{{0}},
254+
},
238255
}
239256

240257
// Run tests with deliberate batch sizes and no selection vectors.

0 commit comments

Comments
 (0)