From: Tom Lane <tgl@sss.pgh.pa.us>
To: Richard Guo <guofenglinux@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: Kirill Zdornyy <kirill@dineserve.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: Error from array_agg when table has many rows
Date: Sat, 08 Mar 2025 10:50:01 -0500
Message-ID: <1297401.1741449001@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMbWs49WUftz6gXGPSVrZJ0czZ1RCtQz4RxDZKEKZtYADvA6Sw@mail.gmail.com>
References: <atLI5Kce2ie1zcYjU0w_kjtVaxiYbYGTihrkLDmGZQnRDD4pnXukIATaABbnIj9pUnelC4ESvCXMm4HAyHg-v61XABaKpERj0A2IXzJZM7g=@dineserve.com>
<CAMbWs49WUftz6gXGPSVrZJ0czZ1RCtQz4RxDZKEKZtYADvA6Sw@mail.gmail.com>
Richard Guo <guofenglinux@gmail.com> writes:
> We are performing deserialization during the final phase of the
> aggregation on data of type RECORD but we fail to provide a valid
> typmod (array_agg_deserialize() uses -1 as the typmod when calling the
> receiveproc).
> I haven't verified it, but I suspect it's related to 16fd03e95.
Yeah. I don't think there is any way for array_agg_deserialize to
know the correct typmod, so what we have to do is disable using
partial aggregation in this case. Fortunately there's a
policy-setting function that can be taught that, as attached.
regards, tom lane
Attachments:disable_partial_aggregation_on_RECORD.patch (text/x-diff, 1.1K) downloaddiff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.cindex 9e567f3cc45..0ac8966e30f 100644--- a/src/backend/parser/parse_agg.c+++ b/src/backend/parser/parse_agg.c@@ -2052,7 +2052,7 @@ resolve_aggregate_transtype(Oid aggfuncid,
/*
* agg_args_support_sendreceive
- * Returns true if all non-byval of aggref's arg types have send and+ * Returns true if all non-byval types of aggref's args have send and
* receive functions.
*/
bool
@@ -2067,6 +2067,15 @@ agg_args_support_sendreceive(Aggref *aggref)
TargetEntry *tle = (TargetEntry *) lfirst(lc);
Oid type = exprType((Node *) tle->expr);
+ /*+ * RECORD is a special case: it has typsend/typreceive functions, but+ * record_recv only works if passed the correct typmod to identify the+ * specific anonymous record type. array_agg_deserialize cannot do+ * that, so we have to disclaim support for the case.+ */+ if (type == RECORDOID)+ return false;+
typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type));
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "cache lookup failed for type %u", type);
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, guofenglinux@gmail.com, dgrowleyml@gmail.com, kirill@dineserve.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Error from array_agg when table has many rows
In-Reply-To: <1297401.1741449001@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox