diff --git a/pkg/sql/colexec/external_hash_aggregator.go b/pkg/sql/colexec/external_hash_aggregator.go index 60d5a0e360ba..553ac061d363 100644 --- a/pkg/sql/colexec/external_hash_aggregator.go +++ b/pkg/sql/colexec/external_hash_aggregator.go @@ -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 diff --git a/pkg/sql/logictest/testdata/logic_test/aggregate b/pkg/sql/logictest/testdata/logic_test/aggregate index be1bc7ad454d..5e7ae7730b8c 100644 --- a/pkg/sql/logictest/testdata/logic_test/aggregate +++ b/pkg/sql/logictest/testdata/logic_test/aggregate @@ -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;