Re: BUG #17502: View based on window functions returns wrong results when queried
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Richard Guo <guofenglinux@gmail.com>, Daniel Farkaš <daniel.farkas@datoris.com>, Magnus Hagander <magnus@hagander.net>, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2023-01-31T11:03:47Z
Lists: 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
Commits
-
Disallow set-returning functions within window OVER clauses.
- 1de468099d27 master landed
- 0c15b715c651 19 (unreleased) landed