Re: Wrong results from join removal with DISTINCT ON + SRF subquery

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Wrong results from join removal with DISTINCT ON + SRF subquery
Date: 2026-08-24 01:53:57
Message-ID: CAMbWs48xSVesyCb0drA5NPGm-kqST4T9n22Q0=Wq11DLp-kVYw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Aug 22, 2026 at 10:15 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Richard Guo <guofenglinux(at)gmail(dot)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.

Thanks for looking at this! I'll push the patch and back-patch to all
supported branches if there are no objections.

- Richard

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Rocker 2026-08-24 02:08:50 Re: [PATCH] Fix vacuum_delay_point happening inside lock
Previous Message Michael Paquier 2026-08-24 01:25:07 Re: Changing the state of data checksums in a running cluster