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

Commit fedfcf6

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 3c472a1 commit fedfcf6

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/backend/parser/parse_agg.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ resolve_aggregate_transtype(Oid aggfuncid,
20522052

20532053
/*
20542054
* agg_args_support_sendreceive
2055-
* Returns true if all non-byval of aggref's arg types have send and
2055+
* Returns true if all non-byval types of aggref's args have send and
20562056
* receive functions.
20572057
*/
20582058
bool
@@ -2067,6 +2067,15 @@ agg_args_support_sendreceive(Aggref *aggref)
20672067
TargetEntry *tle = (TargetEntry *) lfirst(lc);
20682068
Oid type = exprType((Node *) tle->expr);
20692069

2070+
/*
2071+
* RECORD is a special case: it has typsend/typreceive functions, but
2072+
* record_recv only works if passed the correct typmod to identify the
2073+
* specific anonymous record type. array_agg_deserialize cannot do
2074+
* that, so we have to disclaim support for the case.
2075+
*/
2076+
if (type == RECORDOID)
2077+
return false;
2078+
20702079
typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type));
20712080
if (!HeapTupleIsValid(typeTuple))
20722081
elog(ERROR, "cache lookup failed for type %u", type);

src/test/regress/expected/aggregates.out

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,8 +2151,8 @@ explain (costs off) select * from v_pagg_test order by y;
21512151
-> Parallel Seq Scan on pagg_test
21522152
(13 rows)
21532153

2154-
set max_parallel_workers_per_gather = 0;
21552154
-- Ensure results are the same without parallel aggregation.
2155+
set max_parallel_workers_per_gather = 0;
21562156
select * from v_pagg_test order by y;
21572157
y | tmin | tmax | tndistinct | bmin | bmax | bndistinct | amin | amax | andistinct | aamin | aamax | aandistinct
21582158
---+------+------+------------+------+------+------------+------+------+------------+-------+-------+-------------
@@ -2168,6 +2168,24 @@ select * from v_pagg_test order by y;
21682168
9 | 19 | 4999 | 250 | 1019 | 999 | 250 | 19 | 4999 | 250 | 19 | 4999 | 250
21692169
(10 rows)
21702170

2171+
-- Check that we don't fail on anonymous record types.
2172+
set max_parallel_workers_per_gather = 2;
2173+
explain (costs off)
2174+
select array_dims(array_agg(s)) from (select * from pagg_test) s;
2175+
QUERY PLAN
2176+
--------------------------------------------
2177+
Aggregate
2178+
-> Gather
2179+
Workers Planned: 2
2180+
-> Parallel Seq Scan on pagg_test
2181+
(4 rows)
2182+
2183+
select array_dims(array_agg(s)) from (select * from pagg_test) s;
2184+
array_dims
2185+
------------
2186+
[1:5000]
2187+
(1 row)
2188+
21712189
-- Clean up
21722190
reset max_parallel_workers_per_gather;
21732191
reset bytea_output;

src/test/regress/sql/aggregates.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,16 @@ select * from v_pagg_test order by y;
852852
-- Ensure parallel aggregation is actually being used.
853853
explain (costs off) select * from v_pagg_test order by y;
854854

855-
set max_parallel_workers_per_gather = 0;
856-
857855
-- Ensure results are the same without parallel aggregation.
856+
set max_parallel_workers_per_gather = 0;
858857
select * from v_pagg_test order by y;
859858

859+
-- Check that we don't fail on anonymous record types.
860+
set max_parallel_workers_per_gather = 2;
861+
explain (costs off)
862+
select array_dims(array_agg(s)) from (select * from pagg_test) s;
863+
select array_dims(array_agg(s)) from (select * from pagg_test) s;
864+
860865
-- Clean up
861866
reset max_parallel_workers_per_gather;
862867
reset bytea_output;

0 commit comments

Comments
 (0)