Re: BUG #17709: Regression in PG15 with window functions - "WindowFunc not found in subplan target lists"

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: makhmutov(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17709: Regression in PG15 with window functions - "WindowFunc not found in subplan target lists"
Date: 2022-12-09 11:00:19
Message-ID: CAMbWs48=JwUZdGRBdfSPVgovyqq=QTH8qQXoaDsfQymT3xwBNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Dec 9, 2022 at 5:42 PM PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> Following query works fine on PG14, but produce error "WindowFunc not found
> in subplan target lists" on PG15:
>
> select 1
> from
> (
> select count(case t1.a when 1 then 1 else null end) over (partition by
> t2.b) c
> from (select 1 a) t1, (select 1 b) t2
> ) t
> where t.c = 1

Thanks for the report! I can reproduce this issue.

The WindowFunc within runCondition comes from the query's targetList,
before we pull up subquery 't1'. Then when it comes to pulling up
subquery 't1', we perform pullup variable replacement for the query's
targetList but not for runCondition in the query's windowClause. I
believe that's how this error is triggered.

Below is how we can fix this issue.

--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2134,6 +2134,16 @@ perform_pullup_replace_vars(PlannerInfo *root,
* can't contain any references to a subquery.
*/
}
+ if (parse->windowClause)
+ {
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wclause = (WindowClause *) lfirst(lc);
+
+ wclause->runCondition = (List *)
+ pullup_replace_vars((Node *) wclause->runCondition,
rvcontext);
+ }
+ }
if (parse->mergeActionList)
{
foreach(lc, parse->mergeActionList)

Thanks
Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2022-12-09 11:52:40 Re: BUG #17709: Regression in PG15 with window functions - "WindowFunc not found in subplan target lists"
Previous Message PG Bug reporting form 2022-12-09 08:46:02 BUG #17709: Regression in PG15 with window functions - "WindowFunc not found in subplan target lists"