On Thu, 25 Jan 2024 at 18:14, David Rowley <dgrowleyml@gmail.com> wrote: > If WindowFunc allowed a list of a new struct called WindowRunCondition > with fields "otherarg", "opno", "collation", "wfunc_left" then we > could construct the OpExpr later either in createplan.c or setrefs.c. > The EXPLAIN version of that OpExpr could have the WindowFunc and the > non-EXPLAIN version would have the Var.
Just to assist the discussion here I've drafted a patch along the lines of the above. See attached
If you think this idea has merit I can try and turn it into something committable for master.
This idea seems reasonable to me. Now the runCondition is constructed in create_one_window_path(), where the subquery has been through preprocessing and therefore the WindowFunc's arg has been replaced with a Param due to the pullup of the lower subquery and the expansion of SubLinks to SubPlans. This fixes the problem reported here.