Re: BUG #17502: View based on window functions returns wrong results when queried - Mailing list pgsql-bugs

From David Rowley
Subject Re: BUG #17502: View based on window functions returns wrong results when queried
Date
Msg-id CAApHDvqZkGVd=7DzTsnsNwq-Q+HmEyMi5zrKh50s1tgpchQ_aw@mail.gmail.com
Whole thread Raw
In response to Re: BUG #17502: View based on window functions returns wrong results when queried  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Tue, 31 Jan 2023 at 11:53, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> This bug seems to have slipped off the radar screen, but it's still
> a bug.  I continue to believe that the best fix is to disallow SRFs
> in window definitions, and present the trivial patch to do so.

I don't really object to doing this, but I'm not convinced that
someone else won't eventually come along complaining about us changing
this. As far as I'm aware, the behaviour is not wrong today provided
you always use the column so that remove_unused_subquery_outputs()
does not get rid of it.

If we disallow this, then maybe it's worth also giving ourselves a bit
more flexibility to make it work correctly in the future should
someone come along and convince us we shouldn't have disallowed this.
Adjusting  expression_returns_set() to pass it the relevant
PlannerInfo for the Node might be a good idea. If we change our minds
in the future then we could easily then modify
expression_returns_set_walker() to have it check if the given
WindowFunc's WindowClause has SRFs so that we don't remove the unused
WindowFunc subquery columns in remove_unused_subquery_outputs(). I'd
have probably gone with this as a master-only fix, but is quite likely
you're thinking of something that I'm not.  Certainly, the consistency
of when SRFs are evaluated is pretty terrible so I understand the
desire to disallow the WindowClause SRFs so we have one less thing to
get wrong.

David



pgsql-bugs by date:

Previous
From: Richard Guo
Date:
Subject: Re: BUG #17502: View based on window functions returns wrong results when queried
Next
From: "Gunnar \"Nick\" Bluth"
Date:
Subject: Re: BUG #17760: SCRAM authentication fails with "modern" (rsassaPss signature) server certificate