Re: BUG #18305: Unexpected error: "WindowFunc not found in subplan target lists" triggered by subqueries

Richard Guo <guofenglinux@gmail.com>

From: Richard Guo <guofenglinux@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, zuming.jiang@inf.ethz.ch, pgsql-bugs@lists.postgresql.org
Date: 2024-03-22T08:55:47Z
Lists: pgsql-bugs
On Fri, Jan 26, 2024 at 8:02 PM David Rowley <dgrowleyml@gmail.com> wrote:

> 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.

Thanks
Richard

Commits

  1. Fix query pullup issue with WindowClause runCondition

  2. Make documentation builds reproducible

  3. Teach planner about more monotonic window functions