pgsql: Fix postgres_fdw to check shippability of sort clauses properly.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix postgres_fdw to check shippability of sort clauses properly.
Date: 2022-03-31 18:30:07
Message-ID: E1nZzYc-000BwY-Q2@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f3dd9fe1dd9254680591aa8d9891b90b8d735b2a

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 ++
src/backend/optimizer/path/equivclass.c | 29 -----
src/include/optimizer/paths.h | 1 -
7 files changed, 234 insertions(+), 109 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2022-03-31 18:31:55 Re: pgsql: Add 'basebackup_to_shell' contrib module.
Previous Message Andrew Dunstan 2022-03-31 18:27:04 Re: pgsql: Add 'basebackup_to_shell' contrib module.