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 self-join elimination to avoid inheritance scans.
Date: Wed, 14 Oct 2026 20:38:24 +0000
Message-ID: <E1xH5k0-00000001dnx-1Wzh@gemulon.postgresql.org> (raw)

Fix self-join elimination to avoid inheritance scans.

Self-join elimination failed to check for inheritance cases,
which has two big problems.  First, a unique index on the parent
table isn't sufficient to prove uniqueness across its children too.
Second, since we matched RTEs by OID without considering rte->inh,
we could try to merge "mytable" with "mytable ONLY", which doesn't
even represent the same set of rows.

We can fix both issues by just skipping RTEs that have inh set.
preprocess_relation_rtes already cleared that flag for tables known
not to have inheritance children, so this doesn't break SJE for the
cases where it's valid.

Author: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAHewXNn4EjCQEvanN_FPKQ3OJWaBXq8Pxcj-DZYbeQ6_4xSFgw@mail.gmail.com
Backpatch-through: 18

Branch
------
REL_19_STABLE

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

Modified Files
--------------
src/backend/optimizer/plan/analyzejoins.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1xH5k0-00000001dnx-1Wzh@gemulon.postgresql.org>
Permalink:  ../E1xH5k0-00000001dnx-1Wzh@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xH5k0-00000001dnx-1Wzh@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 self-join elimination to avoid inheritance scans.
  In-Reply-To: <E1xH5k0-00000001dnx-1Wzh@gemulon.postgresql.org>
  References: <E1xH5k0-00000001dnx-1Wzh@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