| From: | Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | postgres_fdw: direct arguments of ordered-set aggregates are not checked for shippability |
| Date: | 2026-12-04 09:02:57 |
| Message-ID: | CAF1DzPV9zc50jEZXy4EP2ugp4850VeaQen7EBKMQtrEn2xgK8A@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
foreign_expr_walker() in contrib/postgres_fdw/deparse.c never looks at the
direct arguments of an ordered-set aggregate, so an aggregate can be pushed
down to the remote server even when a direct argument uses a function that
the remote server cannot run.
The T_Aggref case only walks agg->args. The comment there says:
...
/*
* Recurse to input args. aggdirectargs, aggorder and
* aggdistinct are all present in args, so no need to check
* their shippability explicitly.
*/
...
That is true for aggorder and aggdistinct, since they only point at entries
in args. It is not true for aggdirectargs. primnodes.h says:
...
The direct arguments appear in aggdirectargs (as a list of plain
expressions, not TargetEntry nodes).
...
and Aggref has them as a separate field from "args". The parser does the
split in transformAggregateCall(). deparseAggref() does send aggdirectargs
to the remote side, so they are deparsed but never checked.
Example (the remote database has no myf()):
...
create function myf(float8) returns float8 language plpgsql immutable
as $$ begin return $1; end $$;
select c2, percentile_cont(myf(length(c2)/10.0)) within group (order by
c1)
from ft group by c2;
ERROR: function public.myf(numeric) does not exist
CONTEXT: remote SQL command: SELECT c2,
percentile_cont(public.myf((length(c2) / 10.0))) WITHIN GROUP
(ORDER BY c1 ASC NULLS LAST) FROM public.t GROUP BY 1 ...
...
The same function used as a normal aggregate argument, e.g. sum(myf(c1)),
is correctly kept local, and the query above works fine on a local table.
The other checks the walker does (operator and type shippability, collation)
are skipped for direct arguments too. I only tested the function case.
This comes from the original aggregate pushdown commit (7012b132d07), and
we can backport this.
The attached patch makes the walker recurse into aggdirectargs as well and
fixes the comment.
Thoughts?
--
Thanks & Regards,
Suraj kharage,
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-postgres_fdw-Check-shippability-of-ordered-set-ag.patch | application/octet-stream | 8.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ajit Awekar | 2026-12-04 09:03:07 | [PATCH] Don't write ldapbindpasswd to the server log on authentication failure |
| Previous Message | Alexander Pyhalov | 2026-12-04 08:42:32 | Re: Semi-join related bug in postgres_fdw |