pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Richard Guo <guofenglinux@gmail.com>
Cc: Thom Brown <thom@linux.com>
Cc: Jacob Brazeal <jacob.brazeal@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: remove_useless_joins vs. bug #19560
Date: Mon, 27 Jul 2026 14:21:12 -0400
Message-ID: <3975112.1785176472@sss.pgh.pa.us> (raw)
In-Reply-To: <3968565.1785170019@sss.pgh.pa.us>
References: <1186816.1784573544@sss.pgh.pa.us>
	<CAMbWs49s+AdZgvrxm3bxqEWGKeFcK=r41TpfT+x+wzucVV+ORA@mail.gmail.com>
	<2727652.1784997994@sss.pgh.pa.us>
	<CAA-aLv7GGm3OwWOAGou0k-j5jyjSyOMqVc3-GxxO0NjjX+vDmg@mail.gmail.com>
	<2746010.1785014587@sss.pgh.pa.us>
	<2933135.1785032128@sss.pgh.pa.us>
	<CAA-aLv4UbdjHarp8zaK4PQjFHZVrt27hxmZqqBUn3yR_5CpgjQ@mail.gmail.com>
	<3304318.1785087206@sss.pgh.pa.us>
	<3304418.1785087314@sss.pgh.pa.us>
	<CAMbWs4_oMOZkKJF77TGwBsiN1vaKS568rxhE0Adzuwhrs6GLnQ@mail.gmail.com>
	<3968565.1785170019@sss.pgh.pa.us>

I spent some time looking into what would be involved in back-patching
this.  Quite aside from risks of new bugs, there's an API/ABI break
involved for released branches (I don't think we are worried about
that yet for v19, though).  One thing we can do to reduce the API risk
is to not delete the no-longer-used extern functions that the master
patch removes, such as add_vars_to_attr_needed.  I kind of doubt that
anyone is using those in extensions, but leaving them as dead code
seems like cheap insurance.  However, there's an irreducible minimum
API change in remove_useless_joins, reduce_unique_semijoins, and
remove_useless_self_joins: those don't return what they did before,
and even more importantly their side effects are much different from
before.  I don't see any evidence in Debian Code Search that anyone is
calling those, so I'm not inclined to go to lengths like (say) keeping
the whole of the existing analyzejoins.c code around as dead code.
Even if we wanted to consider that, the bugs that we're trying to get
rid of would still bite any hypothetical extension that was messing
with these functions.  So I think it's reasonable to trust that nobody
is calling anything lower-level than query_planner().

Having said that, I think that it'd be a good idea to rename
remove_useless_joins to remove_useless_outer_joins.  The existing
name is already confusing now that we have remove_useless_self_joins
too.  The ABI angle is that if we do that, then any extension that's
trying to call remove_useless_joins will fail with an
easily-understood error at library load time, rather than crashing
or misbehaving in some arcane way because the function didn't do what
it expected.  We could extend this to renaming all three functions,
but I think renaming remove_useless_joins is sufficient --- I really
don't see any use case for calling the other two and not that one.

So attached are a set of patches along that line.  v5-0001 is the
master patchset squashed to one patch; it differs from the v4 series
in having the remove_useless_joins rename and some minor additional
comment-smithing.  The others are draft patches for v16-v19.  The
v19 patch is only trivially different from master.  v18 and earlier
don't remove any of the dead code outside analyzejoins.c.  v16/v17
are a good deal smaller because there's no SJE code to fix.

I think it's still open to debate how far back we want to go.
In principle we could make these changes in v14/v15, but with no known
bugs manifesting in those branches, the risk/reward ratio seems poor,
so I didn't make patches for those.  I think we definitely want to do
this in v18, since aside from #19560 that branch has the SJE bug that
Jacob B. reported at [1] (which is a distinct problem, per Alexander's
analysis).  v16 and v17 seem like a gray area, but we do know that
they have #19560.  Even if we limit our ambition in those branches
to fixing that problem, I don't see a simple localized fix for it.

Thoughts?

			regards, tom lane

[1] https://www.postgresql.org/message-id/flat/CA%2BCOZaBVFHS-eXL7a53iZfNJyv5LqD5t1eSbYDavYxLSyfkL6A%40m...

Attachments:

  v5-join-removal-per-branch-patches.tar.gz (application/gzip, 119.0K) download

view thread (74+ messages)  latest in thread

Message-ID: <3975112.1785176472@sss.pgh.pa.us>
Permalink:  ../3975112.1785176472@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3975112.1785176472@sss.pgh.pa.us

 · 

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-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, guofenglinux@gmail.com, thom@linux.com, jacob.brazeal@gmail.com
  Subject: Re: remove_useless_joins vs. bug #19560
  In-Reply-To: <3975112.1785176472@sss.pgh.pa.us>
  References: <1186816.1784573544@sss.pgh.pa.us> <CAMbWs49s+AdZgvrxm3bxqEWGKeFcK=r41TpfT+x+wzucVV+ORA@mail.gmail.com> <2727652.1784997994@sss.pgh.pa.us> <CAA-aLv7GGm3OwWOAGou0k-j5jyjSyOMqVc3-GxxO0NjjX+vDmg@mail.gmail.com> <2746010.1785014587@sss.pgh.pa.us> <2933135.1785032128@sss.pgh.pa.us> <CAA-aLv4UbdjHarp8zaK4PQjFHZVrt27hxmZqqBUn3yR_5CpgjQ@mail.gmail.com> <3304318.1785087206@sss.pgh.pa.us> <3304418.1785087314@sss.pgh.pa.us> <CAMbWs4_oMOZkKJF77TGwBsiN1vaKS568rxhE0Adzuwhrs6GLnQ@mail.gmail.com> <3968565.1785170019@sss.pgh.pa.us> <3975112.1785176472@sss.pgh.pa.us>

* 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