Re: BUG #19533: Wrong results from WindowAgg run-condition pushdown on count() with EXCLUDE CURRENT ROW - Mailing list pgsql-bugs

From Richard Guo
Subject Re: BUG #19533: Wrong results from WindowAgg run-condition pushdown on count() with EXCLUDE CURRENT ROW
Date
Msg-id CAMbWs4-6umOecRifmC88RW0SHWDAvb4c3-VD8XQ3NJufsUyUOQ@mail.gmail.com
Whole thread
In response to Re: BUG #19533: Wrong results from WindowAgg run-condition pushdown on count() with EXCLUDE CURRENT ROW  (Chengpeng Yan <chengpeng_yan@outlook.com>)
List pgsql-bugs
On Sun, Jun 28, 2026 at 1:53 AM Chengpeng Yan <chengpeng_yan@outlook.com> wrote:
> The attached patch takes the conservative route: int8inc_support() no
> longer reports count() as monotonic when the window frame has
> FRAMEOPTION_EXCLUSION. The added regression tests cover the reported
> case, related EXCLUDE variants, and a count(*) case. They also check
> that the excluded-frame query keeps a normal Filter instead of a
> WindowAgg Run Condition.

I think the fix is on the right track.  One nit is that it might be
better to use if/else if structure here.  The other nit is that the
test case is over-heavy; it should be kept as minimal as possible.

> Thoughts welcome on whether this is the right boundary, or whether some
> narrower excluded-frame cases should still prove monotonicity
> separately.

I wonder if we should still support count(*) with EXCLUDE CURRENT ROW,
as that always removes exactly one row, so it is still monotonic.

+   if ((frameOptions & FRAMEOPTION_EXCLUSION) &&
+       ((frameOptions & FRAMEOPTION_EXCLUSION) !=
FRAMEOPTION_EXCLUDE_CURRENT_ROW ||
+        req->window_func->winfnoid != F_COUNT_))
+       monotonic = MONOTONICFUNC_NONE;

- Richard



pgsql-bugs by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: BUG #19536: UPDATE RETURNING OLD value is stale after concurrent update when table has a BEFORE UPDATE trigger
Next
From: Tender Wang
Date:
Subject: Re: BUG #19534: Qual pushdown across a window subquery is unsafe with nondeterministic partition collations