Skip to content

Commit

Permalink
colexec: fix usage of incorrect type schema for external hash agg
Browse files Browse the repository at this point in the history
We recently merged a change to the external hash aggregator to maintain
ordering. This was done by planning an explicit sort after aggregation.
However, a bug was introduced in which we were using the incorrect type
schema for sort planning: namely, we used the "result types" for the
aggregator stage (after a projection is applied), but we should have
used the "output types" (the schema of what the aggregator outputs). Now
this is fixed.

Release note: None
  • Loading branch information
yuzefovich committed Apr 11, 2021
1 parent 71a023f commit 971bf24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/sql/colexec/external_hash_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewExternalHashAggregator(
// sort isn't accounted for when considering the number file descriptors to
// acquire. Not urgent, but it should be fixed.
maxNumberActivePartitions := calculateMaxNumberActivePartitions(flowCtx, args, ehaNumRequiredActivePartitions)
return createDiskBackedSorter(eha, args.Spec.ResultTypes, outputOrdering.Columns, maxNumberActivePartitions)
return createDiskBackedSorter(eha, newAggArgs.OutputTypes, outputOrdering.Columns, maxNumberActivePartitions)
}

// HashAggregationDiskSpillingEnabled is a cluster setting that allows to
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/aggregate
Original file line number Diff line number Diff line change
Expand Up @@ -3840,3 +3840,9 @@ SELECT a, b, count(*) FROM t63159 GROUP BY a,b ORDER BY a
2 2 1
3 3 1
5 5 1

# Regression test for the vectorized hash aggregator using incorrect type schema
# when planning an external sort to maintain the required ordering.
statement ok
CREATE TABLE t63436 (a INT, b FLOAT, c DECIMAL, INDEX(a));
SELECT count(*) FROM t63436@t63436_a_idx GROUP BY b, c ORDER BY c;

0 comments on commit 971bf24

Please sign in to comment.