Re: BUG #18277: Unexpected error: "WindowFunc not found in subplan target lists" triggered by JOIN and Window Func

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: zuming(dot)jiang(at)inf(dot)ethz(dot)ch, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18277: Unexpected error: "WindowFunc not found in subplan target lists" triggered by JOIN and Window Func
Date: 2024-01-09 07:35:08
Message-ID: CAMbWs4_g0-toa_BH3M-ocFoJLcLKuxL=wdaBho60+r7vVy+c=w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Jan 9, 2024 at 7:00 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> > My fuzzer finds a bug in Postgres 17devel, which triggers an unexpected
> > error "ERROR: WindowFunc not found in subplan target lists".
>
> Thanks for the report! Bisecting says this broke at
>
> 2489d76c4906f4461a364ca8ad7e0751ead8aa0d is the first bad commit
> commit 2489d76c4906f4461a364ca8ad7e0751ead8aa0d
> Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
> Date: Mon Jan 30 13:16:20 2023 -0500
>
> Make Vars be outer-join-aware.

I think this is caused by that query_tree_mutator fails to mutate
runCondition for WindowClause. So when we've reduced the ref_0/ref_1
left join to inner join, we fail to remove references to this join as
nulling rels in the run condition '1 >= ntile(ref_1.vkey) OVER (?)'.

So maybe we can fix this issue by:

@@ -3641,6 +3646,7 @@ query_tree_mutator_impl(Query *query,
FLATCOPY(newnode, wc, WindowClause);
MUTATE(newnode->startOffset, wc->startOffset, Node *);
MUTATE(newnode->endOffset, wc->endOffset, Node *);
+ MUTATE(newnode->runCondition, wc->runCondition, List *);

I think we should also consider WindowClause->runCondition in
query_tree_walker, expression_tree_mutator and expression_tree_walker.
Hence, proposed the attached patch.

Thanks
Richard

Attachment Content-Type Size
v1-0001-Fix-bug-18277.patch application/octet-stream 3.7 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Nathan Bossart 2024-01-09 17:38:27 Re: Wrong datatype in docs for wal_summary_keep_time
Previous Message Andres Freund 2024-01-09 04:21:12 Re: BUG #18259: Assertion in ExtendBufferedRelLocal() fails after no-space-left condition