pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix incorrect Assert in add_foreign_ordered_paths
Date: Wed, 04 Nov 2026 02:58:38 +0000
Message-ID: <E1xORCx-000000006PS-0l3o@gemulon.postgresql.org> (raw)

Fix incorrect Assert in add_foreign_ordered_paths

12933dc60 (originally 66c0185a3) added setop_pathkeys for providing
presorted inputs for set operation from child queries when that query
doesn't have any other pathkey requirements.

add_foreign_ordered_paths() assumed that if the query had an ORDER BY
that the query_pathkeys would be equal to sort_pathkeys.  That's not
true when query_pathkeys is set to setop_pathkeys, which can happen
for set-op child queries with an ORDER BY when all the sort_pathkeys are
redundant pathkeys. (See standard_qp_callback()).

Here we relax the Assert to allow for sort_pathkeys to be empty.  In
this case it is technically ok to mark pushdown_safe as true so that
postgresGetForeignUpperPaths() allows add_foreign_final_paths() to
generate paths with the LIMIT clause pushed down.  We don't adjust that
here as that could cause plan changes in the backbranches.  Let's just
fix things enough so the Assert doesn't fail and do a proper fix in
master.

Backpatch to 17 where the setop_pathkeys field was added.

Reported-by: Robins Tharakan <tharakan@gmail.com>
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Robins Tharakan <tharakan@gmail.com>
Discussion: https://postgr.es/m/CAEP4nAwnSefmi4w+89XbHQ0f-0OixCYUJo9kVcbXSYL8L4rEPg@mail.gmail.com
Backpatch-through: 17

Branch
------
REL_17_STABLE

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

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 26 ++++++++++++++++++++++++++
contrib/postgres_fdw/postgres_fdw.c            | 16 ++++++++--------
contrib/postgres_fdw/sql/postgres_fdw.sql      |  9 +++++++++
3 files changed, 43 insertions(+), 8 deletions(-)



view thread (4+ messages)

Message-ID: <E1xORCx-000000006PS-0l3o@gemulon.postgresql.org>
Permalink:  ../E1xORCx-000000006PS-0l3o@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xORCx-000000006PS-0l3o@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: drowley@postgresql.org
  Subject: Re: pgsql: Fix incorrect Assert in add_foreign_ordered_paths
  In-Reply-To: <E1xORCx-000000006PS-0l3o@gemulon.postgresql.org>
  References: <E1xORCx-000000006PS-0l3o@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