pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix postgres_fdw to check shippability of sort clauses properly.
Date: Thu, 31 Mar 2022 18:30:07 +0000
Message-ID: <E1nZzYc-000BwZ-QT@gemulon.postgresql.org> (raw)

Fix postgres_fdw to check shippability of sort clauses properly.

postgres_fdw would push ORDER BY clauses to the remote side without
verifying that the sort operator is safe to ship.  Moreover, it failed
to print a suitable USING clause if the sort operator isn't default
for the sort expression's type.  The net result of this is that the
remote sort might not have anywhere near the semantics we expect,
which'd be disastrous for locally-performed merge joins in particular.

We addressed similar issues in the context of ORDER BY within an
aggregate function call in commit 7012b132d, but failed to notice
that query-level ORDER BY was broken.  Thus, much of the necessary
logic already existed, but it requires refactoring to be usable
in both cases.

Back-patch to all supported branches.  In HEAD only, remove the
core code's copy of find_em_expr_for_rel, which is no longer used
and really should never have been pushed into equivclass.c in the
first place.

Ronan Dunklau, per report from David Rowley;
reviews by David Rowley, Ranier Vilela, and myself

Discussion: https://postgr.es/m/CAApHDvr4OeC2DBVY--zVP83-K=bYrTD7F8SZDhN4g+pj2f2S-A@mail.gmail.com

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9f9489aa2eefeaf4a6517b0b14f8f22938c2e3f3

Modified Files
--------------
contrib/postgres_fdw/deparse.c                 | 166 ++++++++++++++++++-------
contrib/postgres_fdw/expected/postgres_fdw.out |  23 ++++
contrib/postgres_fdw/postgres_fdw.c            | 103 ++++++++++-----
contrib/postgres_fdw/postgres_fdw.h            |  13 +-
contrib/postgres_fdw/sql/postgres_fdw.sql      |   8 ++
5 files changed, 234 insertions(+), 79 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1nZzYc-000BwZ-QT@gemulon.postgresql.org>
Permalink:  ../E1nZzYc-000BwZ-QT@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nZzYc-000BwZ-QT@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix postgres_fdw to check shippability of sort clauses properly.
  In-Reply-To: <E1nZzYc-000BwZ-QT@gemulon.postgresql.org>
  References: <E1nZzYc-000BwZ-QT@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox