Re: Fix a reference error for window functions: In the function 'find_window_functions', the deduplication logic should be removed

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Meng Zhang <mza117jc(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Fix a reference error for window functions: In the function 'find_window_functions', the deduplication logic should be removed
Date: 2026-01-25 07:20:48
Message-ID: CAHewXNkvTpofYp747vQaxvJdWiH+00vkvkd7MhP1fvdvDEvkfQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,all

David Rowley <dgrowleyml(at)gmail(dot)com> 于2026年1月25日周日 15:05写道:
>
> On Sun, 25 Jan 2026 at 17:09, Meng Zhang <mza117jc(at)gmail(dot)com> wrote:
> > The deduplication logic won't cause an error when the result of this function is only used in `select_active_windows`.
> > But when the result is used in `optimize_window_clauses`, it will cause the `winref` field of a certain window function to not be modified in the new window.
>
> Thanks for the report. I'll have a look.
>
> David
>
>
I did some analysis, and I found this issue was introduced by this
commit ed1a88d:
Allow window functions to adjust their frameOptions

In optimize_window_clauses(), the list wc->winref = 2 was set to NIL,
so "window 2" would not be in the activewindow lists.
We only have one windowagg node, in ExecEndWindowAgg(), when we
process the second "ROW_NUMBER() OVER window2"
which its winref was still 2 because in
find_window_functions_walker(), it was skipped due to duplicates.

The attached patch seems workable. But I have one question. If we
implement the attached patch, would it introduce redundant
computation?
Maybe optimize_window_clauses() would optimize the repeated
computation. I don't understand this much.

--
Thanks,
Tender Wang

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2026-01-25 07:41:22 Re: pg_stat_statements: add missing tests for nesting_level
Previous Message David Rowley 2026-01-25 07:05:03 Re: Fix a reference error for window functions: In the function 'find_window_functions', the deduplication logic should be removed