Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 43847dd

Browse files
committed
Don't try to parallelize array_agg() on an anonymous record type.
This doesn't work because record_recv requires the typmod that identifies the specific record type (in our session) and array_agg_deserialize has no convenient way to get that information. The result is an "input of anonymous composite types is not implemented" error. We could probably make this work if we had to, but it does not seem worth the trouble, given that it took this long to get a field report. Just shut off parallelization, as though record_recv didn't exist. Oversight in commit 16fd03e. Back-patch to v16 where that came in. Reported-by: Kirill Zdornyy <kirill@dineserve.com> Diagnosed-by: Richard Guo <guofenglinux@gmail.com> Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Discussion: https://postgr.es/m/atLI5Kce2ie1zcYjU0w_kjtVaxiYbYGTihrkLDmGZQnRDD4pnXukIATaABbnIj9pUnelC4ESvCXMm4HAyHg-v61XABaKpERj0A2IXzJZM7g=@dineserve.com Backpatch-through: 16
1 parent 99c01aa commit 43847dd

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/backend/parser/parse_agg.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ resolve_aggregate_transtype(Oid aggfuncid,
19611961

19621962
/*
19631963
* agg_args_support_sendreceive
1964-
* Returns true if all non-byval of aggref's arg types have send and
1964+
* Returns true if all non-byval types of aggref's args have send and
19651965
* receive functions.
19661966
*/
19671967
bool
@@ -1976,6 +1976,15 @@ agg_args_support_sendreceive(Aggref *aggref)
19761976
TargetEntry *tle = (TargetEntry *) lfirst(lc);
19771977
Oid type = exprType((Node *) tle->expr);
19781978

1979+
/*
1980+
* RECORD is a special case: it has typsend/typreceive functions, but
1981+
* record_recv only works if passed the correct typmod to identify the
1982+
* specific anonymous record type. array_agg_deserialize cannot do
1983+
* that, so we have to disclaim support for the case.
1984+
*/
1985+
if (type == RECORDOID)
1986+
return false;
1987+
19791988
typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type));
19801989
if (!HeapTupleIsValid(typeTuple))
19811990
elog(ERROR, "cache lookup failed for type %u", type);

src/test/regress/expected/aggregates.out

+19-1
Original file line numberDiff line numberDiff line change
@@ -2033,8 +2033,8 @@ explain (costs off) select * from v_pagg_test order by y;
20332033
-> Parallel Seq Scan on pagg_test
20342034
(13 rows)
20352035

2036-
set max_parallel_workers_per_gather = 0;
20372036
-- Ensure results are the same without parallel aggregation.
2037+
set max_parallel_workers_per_gather = 0;
20382038
select * from v_pagg_test order by y;
20392039
y | tmin | tmax | tndistinct | bmin | bmax | bndistinct | amin | amax | andistinct | aamin | aamax | aandistinct
20402040
---+------+------+------------+------+------+------------+------+------+------------+-------+-------+-------------
@@ -2050,6 +2050,24 @@ select * from v_pagg_test order by y;
20502050
9 | 19 | 4999 | 250 | 1019 | 999 | 250 | 19 | 4999 | 250 | 19 | 4999 | 250
20512051
(10 rows)
20522052

2053+
-- Check that we don't fail on anonymous record types.
2054+
set max_parallel_workers_per_gather = 2;
2055+
explain (costs off)
2056+
select array_dims(array_agg(s)) from (select * from pagg_test) s;
2057+
QUERY PLAN
2058+
--------------------------------------------
2059+
Aggregate
2060+
-> Gather
2061+
Workers Planned: 2
2062+
-> Parallel Seq Scan on pagg_test
2063+
(4 rows)
2064+
2065+
select array_dims(array_agg(s)) from (select * from pagg_test) s;
2066+
array_dims
2067+
------------
2068+
[1:5000]
2069+
(1 row)
2070+
20532071
-- Clean up
20542072
reset max_parallel_workers_per_gather;
20552073
reset bytea_output;

src/test/regress/sql/aggregates.sql

+7-2
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,16 @@ select * from v_pagg_test order by y;
805805
-- Ensure parallel aggregation is actually being used.
806806
explain (costs off) select * from v_pagg_test order by y;
807807

808-
set max_parallel_workers_per_gather = 0;
809-
810808
-- Ensure results are the same without parallel aggregation.
809+
set max_parallel_workers_per_gather = 0;
811810
select * from v_pagg_test order by y;
812811

812+
-- Check that we don't fail on anonymous record types.
813+
set max_parallel_workers_per_gather = 2;
814+
explain (costs off)
815+
select array_dims(array_agg(s)) from (select * from pagg_test) s;
816+
select array_dims(array_agg(s)) from (select * from pagg_test) s;
817+
813818
-- Clean up
814819
reset max_parallel_workers_per_gather;
815820
reset bytea_output;

0 commit comments

Comments
 (0)