Skip to content

Commit dc80eb5

Browse files
craig[bot]jordanlewis
craig[bot]
andcommitted
Merge #38512
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 <[email protected]>
2 parents 6ad3692 + e4773fa commit dc80eb5

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
}
@@ -302,19 +301,6 @@ func (a *orderedAggregator) reset() {
302301
}
303302
}
304303

305-
// extractGroupTypes returns an array representing the type corresponding to
306-
// each group column. This information is extracted from the group column
307-
// indices and their corresponding column types.
308-
func extractGroupTypes(groupCols []uint32, colTypes []types.T) []types.T {
309-
groupTyps := make([]types.T, len(groupCols))
310-
311-
for i, colIdx := range groupCols {
312-
groupTyps[i] = colTypes[colIdx]
313-
}
314-
315-
return groupTyps
316-
}
317-
318304
// extractAggTypes returns a nested array representing the input types
319305
// corresponding to each aggregation function.
320306
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)