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: Tender Wang <tndrwang@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: Thu, 03 Sep 2026 10:55:05 -0400
Message-ID: <1468659.1788447305@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMbWs4_FkUdq1D4rwbty972=JVFgS-ip1K9x6x_izAtqv=k3Eg@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>
	<670538.1786924698@sss.pgh.pa.us>
	<CAMbWs4-C4fwZTtY911MfAkW51G2d9TpqoRqmxCiJbjeO0GG1ug@mail.gmail.com>
	<839346.1787765112@sss.pgh.pa.us>
	<CAMbWs4-bgUE1SuNOgMmROhLJbRZz=f4bK7RJAEBQU9uCTSMBnQ@mail.gmail.com>
	<954541.1787846010@sss.pgh.pa.us>
	<CAMbWs4_mfPF5pQVT2FAdvjEMqN7pDT2MGJqkVoJLVyGLYAsU+w@mail.gmail.com>
	<1147476.1787924590@sss.pgh.pa.us>
	<250168.! 1788034245@sss.pgh.pa.us>
	<CAMbWs4-5aHFeGy9ArFbozdpxy4xFEtWgXzGTW7KoYOjzX9nXGA@mail.gmail.com>
	<495449.1788106841@sss.pgh.pa.us>
	<CAMbWs4_FkUdq1D4rwbty972=JVFgS-ip1K9x6x_izAtqv=k3Eg@mail.gmail.com>

[ after a good deal of navel-gazing... ]

Richard Guo <guofenglinux@gmail.com> writes:
> I'm also not sure about skipping outer-level PHVs in
> eval_const_expressions.  I'm worried that that can cause us to carry
> the raw expressions in the outer query somewhere.

It still feels to me that that's the right thing to do.  With your
v2 patch, subquery_planner will have taken care of preprocessing
any outer-level PHVs before the subquery's own preprocessing starts.
If we do that over again, the best-case result is that we waste
cycles.  The worst-case result is that we end up with an expression
that looks different from what it looks like in the outer level
and then that causes problems.  (I don't have any specific ideas
in mind about how the doubly-processed expression could come to be
different.  But if we accept your point that "it's unsafe to do
preprocessing twice", it seems like this is fertile ground for
trouble.)

I think that your v2 patch is fundamentally the right way forward,
but I'm worried that it's not complete yet.  In particular it
seems very strange that only flatten_join_alias_vars_mutator needs
to worry about skipping outer-level PHVs.  I already explained why
I think eval_const_expressions should too, and I wonder if there
are not other places that should as well.  Fundamentally it seems
like the policy across the board ought to be that subqueries keep
their hands off upper-level PHVs.  Now, once we've applied
SS_replace_correlation_vars, the question is moot because all such
PHVs will have been replaced by Params, but anything that runs
before that needs a close look.

			regards, tom lane






view thread (74+ messages)  latest in thread

Message-ID: <1468659.1788447305@sss.pgh.pa.us>
Permalink:  ../1468659.1788447305@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1468659.1788447305@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, tndrwang@gmail.com, thom@linux.com, jacob.brazeal@gmail.com
  Subject: Re: remove_useless_joins vs. bug #19560
  In-Reply-To: <1468659.1788447305@sss.pgh.pa.us>
  References: <1186816.1784573544@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> <670538.1786924698@sss.pgh.pa.us> <CAMbWs4-C4fwZTtY911MfAkW51G2d9TpqoRqmxCiJbjeO0GG1ug@mail.gmail.com> <839346.1787765112@sss.pgh.pa.us> <CAMbWs4-bgUE1SuNOgMmROhLJbRZz=f4bK7RJAEBQU9uCTSMBnQ@mail.gmail.com> <954541.1787846010@sss.pgh.pa.us> <CAMbWs4_mfPF5pQVT2FAdvjEMqN7pDT2MGJqkVoJLVyGLYAsU+w@mail.gmail.com> <1147476.1787924590@sss.pgh.pa.us> <CAMbWs4-5aHFeGy9ArFbozdpxy4xFEtWgXzGTW7KoYOjzX9nXGA@mail.gmail.com> <495449.1788106841@sss.pgh.pa.us> <CAMbWs4_FkUdq1D4rwbty972=JVFgS-ip1K9x6x_izAtqv=k3Eg@mail.gmail.com> <1468659.1788447305@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