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: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Wrong results from join removal with DISTINCT ON + SRF subquery
Date: Fri, 21 Aug 2026 21:15:52 -0400
Message-ID: <4122160.1787361352@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMbWs4-hfd1Pyy_zBejsVUSy-3dx16rz2hgUakkKnAg3qg2q=Q@mail.gmail.com>
References: <CAMbWs4-hfd1Pyy_zBejsVUSy-3dx16rz2hgUakkKnAg3qg2q=Q@mail.gmail.com>

Richard Guo <guofenglinux@gmail.com> writes:
> Attached is a patch to not rely on DISTINCT ON for distinctness if
> there are any tlist SRFs.  This is more conservative than necessary,
> since the SRFs are only postponed when there is an ORDER BY and none
> of them is in a sort/group column, but I don't think it's worth
> duplicating that logic in analyzejoins.c.

I didn't study the patch in any detail, but I concur with your
thinking here.  SRFs in the tlist are kind of a legacy usage in the
first place, so I don't feel a need to expend lots of effort on
optimizing cases like this.

			regards, tom lane






view thread (5+ messages)  latest in thread

Message-ID: <4122160.1787361352@sss.pgh.pa.us>
Permalink:  ../4122160.1787361352@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/4122160.1787361352@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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, guofenglinux@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Wrong results from join removal with DISTINCT ON + SRF subquery
  In-Reply-To: <4122160.1787361352@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