From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow LIMIT pushdown in postgres_fdw with empty ORDER BY pathkey
Date: Wed, 04 Nov 2026 03:24:04 +0000
Message-ID: <E1xORbY-000000006Zf-3NqC@gemulon.postgresql.org> (raw)
Allow LIMIT pushdown in postgres_fdw with empty ORDER BY pathkeys
When all of the ORDER BY clause's PathKeys are redundant due to consts in
all of the pathkeys' EquivalenceClasses, sort_pathkeys is NIL, but
query_pathkeys may then get set to setop_pathkeys, which may not be
shippable. add_foreign_ordered_paths() previously used the shippability
of query_pathkeys to decide whether the UPPERREL_ORDERED step was safe to
push down, which needlessly prevented the subsequent UPPERREL_FINAL step
from pushing down the LIMIT. No sort is needed in this case, so just mark
the ordered step as pushdown-safe.
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Robins Tharakan <tharakan@gmail.com>
Discussion: https://postgr.es/m/CAEP4nAwnSefmi4w+89XbHQ0f-0OixCYUJo9kVcbXSYL8L4rEPg@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/b6178c942ea7a85f72beb6a775d2793062a7ff8e
Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 10 ++++++++++
contrib/postgres_fdw/postgres_fdw.c | 14 ++++++++++----
contrib/postgres_fdw/sql/postgres_fdw.sql | 4 ++++
3 files changed, 24 insertions(+), 4 deletions(-)
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: drowley@postgresql.org
Subject: Re: pgsql: Allow LIMIT pushdown in postgres_fdw with empty ORDER BY pathkey
In-Reply-To: <E1xORbY-000000006Zf-3NqC@gemulon.postgresql.org>
References: <E1xORbY-000000006Zf-3NqC@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