agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: postgres_fdw: don't push down non-relabeling ArrayCoerceExpr
Date: Tue, 14 Jul 2026 22:59:42 +0000
Message-ID: <E1wjm6H-000CpH-2d@gemulon.postgresql.org> (raw)
postgres_fdw: don't push down non-relabeling ArrayCoerceExpr
Commit 62c3b4cd9ddc taught postgres_fdw to push down ArrayCoerceExpr, but
foreign_expr_walker() only recursed into the input array expression and
never examined elemexpr, the per-element conversion that gives the
coercion its semantics. deparseArrayCoerceExpr() then shipped a bare
"arg::resulttype" cast, or nothing at all for an implicit-format
coercion, leaving the remote server to re-resolve the element conversion
against its own catalogs and session state.
This produced wrong results or remote errors whenever the element
conversion was not a plain relabeling, and it was inconsistent with how
postgres_fdw treats the equivalent scalar coercions. An ArrayCoerceExpr
was shipped even when its elemexpr was a cast function (whose
shippability was never checked), a CoerceViaIO (e.g. float8out or
byteaout, which depend on extra_float_digits / bytea_output that
postgres_fdw sets differently on the remote session), or a
CoerceToDomain (which pushes domain enforcement to the remote catalog).
By contrast, a scalar CoerceViaIO is never shipped, and a scalar cast
function is shipped only when it is shippable.
Restrict pushdown to element coercions that are a plain relabeling, that
is, elemexpr is a RelabelType or a bare CaseTestExpr. Any other element
coercion is now evaluated locally. This keeps the common
binary-coercible case pushed down, including "col = ANY($1)" with a
varchar[]-to-text[] relabeling, which is the case 62c3b4cd9ddc set out to
optimize.
Pushing down shippable element cast functions, to reach parity with the
scalar case, is left out here for simplicity.
Reported-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/20260711024234.43.noahmisch%40microsoft.com
Backpatch-through: 19
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/2349b106b6661c084dc1171654146c730ecb048f
Modified Files
--------------
contrib/postgres_fdw/deparse.c | 20 +++++++
contrib/postgres_fdw/expected/postgres_fdw.out | 75 ++++++++++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 35 ++++++++++++
3 files changed, 130 insertions(+)
view thread (2+ messages)
Message-ID: <E1wjm6H-000CpH-2d@gemulon.postgresql.org>
Permalink: ../E1wjm6H-000CpH-2d@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wjm6H-000CpH-2d@gemulon.postgresql.org
reply
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-committers@postgresql.org
Cc: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: postgres_fdw: don't push down non-relabeling ArrayCoerceExpr
In-Reply-To: <E1wjm6H-000CpH-2d@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox