pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Suppress unnecessary explicit sorting for EPQ mergejoin path
Date: Thu, 08 May 2025 09:22:39 +0000
Message-ID: <E1uCxSg-000kln-2T@gemulon.postgresql.org> (raw)

Suppress unnecessary explicit sorting for EPQ mergejoin path

When building a ForeignPath for a joinrel, if there's a possibility
that EvalPlanQual will be executed, we must identify a suitable path
for EPQ checks.  If the outer or inner path of the chosen path is a
ForeignPath representing a pushed-down join, we replace it with its
fdw_outerpath to ensure that the EPQ check path consists entirely of
local joins.

If the chosen path is a MergePath, and its outer or inner path is a
ForeignPath that is not already well enough ordered, the MergePath
will have non-NIL outersortkeys or innersortkeys indicating the
desired ordering to be created by an explicit Sort node.  If we then
replace the outer or inner path with its corresponding fdw_outerpath,
and that path is already sufficiently ordered, we end up in an
inconsistent state: the MergePath has non-NIL outersortkeys or
innersortkeys, and its input path is already properly ordered.  This
inconsistency can result in an Assert failure or the addition of a
redundant Sort node.

To fix, check if the new outer or inner path of a MergePath is already
properly sorted, and set its outersortkeys or innersortkeys to NIL if
so.

Bug: #18902
Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/18902-71c1bed2b9f7c46f@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/773db22269d474fab46d25e9e15b1e55252cf92c

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 64 ++++++++++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql      |  5 ++
src/backend/foreign/foreign.c                  | 33 +++++++++++++
3 files changed, 102 insertions(+)



Message-ID: <E1uCxSg-000kln-2T@gemulon.postgresql.org>
Permalink:  ../E1uCxSg-000kln-2T@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uCxSg-000kln-2T@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: rguo@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Suppress unnecessary explicit sorting for EPQ mergejoin path
  In-Reply-To: <E1uCxSg-000kln-2T@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