On Sat, 11 Feb 2023 at 13:49, Andres Freund <andres@anarazel.de> wrote:
> I think we could just add a !contain_subplans() to the code deciding whether
> it's safe to use the movable window optimization?
I think this is a fair way to fix the bug. I think we're pretty
unlikely to disappoint too many people by just disabling the inverse
transitions when the filter has a subplan. I think it'll be rare that
a WindowFunc would even have a filter, let alone one with a subplan.
I think there are other reasons that a subplan might not return the
same thing when it's executed again. Maybe a synchronous seq scan
looking for some tuple with a subquery containing a LIMIT 1. If the
sync scan started in a different place each time then some other tuple
could be returned. So I think checking if the filter contains
subplans is a good fix.
Here's a patch for that.
David