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: Wed, 26 Aug 2026 10:02:59 -0400
Message-ID: <696216.1787752979@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMbWs4-rxs-GJFNjbRkmArVaeXTXkexpO+vmrXOW9Jg3WxUXWw@mail.gmail.com>
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>
	<CAMbWs4-4JN51woVH86hMSMmdLfNVXzRav8KHShhP6QGmbtLNDg@mail.gmail.com>
	<CAMbWs4-rxs-GJFNjbRkmArVaeXTXkexpO+vmrXOW9Jg3WxUXWw@mail.gmail.com>

Richard Guo <guofenglinux@gmail.com> writes:
> I did some testing of planning time.  Independent removals are fine,
> even faster than before: 64 removable joins that each join directly to
> t0 plan in 0.57 ms here vs 1.11 ms on master.  They all go in the
> first pass, and one extra pass over a single-rel query is cheaper than
> the per-removal cleanup the old code did.

Thanks for looking into this!

> Chains of dependent joins are not fine though:

>   select t0.id from t0
>     left join t1 on t0.nxt = t1.id
>     left join t2 on t1.nxt = t2.id
>     ...
>     left join t64 on t63.nxt = t64.id;

> Only t64 can go in the first pass; t63 still looks needed because
> attr_needed for t63.nxt includes t64's join, and we only find out
> otherwise after the restart.  So each link costs a full pass, and this
> plans in 20.9 ms vs 1.98 ms on master.  The gap widens quickly with
> the chain length, and views built on views give the same shape.

I'm skeptical that this example is a deal-breaker, because it seems
quite artificial.  Queries with this many relations would typically
take a long time to plan.  If we're somewhat slower to deal with the
edge case where most of the joins vanish, is anyone really likely to
notice?  So I'm hesitant to add complexity in hopes of making the
edge case faster.  Especially since this is a bug fix that I'm hoping
to back-patch; every dollop of complexity adds risk.

			regards, tom lane






view thread (74+ messages)  latest in thread

Message-ID: <696216.1787752979@sss.pgh.pa.us>
Permalink:  ../696216.1787752979@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/696216.1787752979@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: <696216.1787752979@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> <CAMbWs4-4JN51woVH86hMSMmdLfNVXzRav8KHShhP6QGmbtLNDg@mail.gmail.com> <CAMbWs4-rxs-GJFNjbRkmArVaeXTXkexpO+vmrXOW9Jg3WxUXWw@mail.gmail.com> <696216.1787752979@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