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

From David Rowley
Subject Re: BUG #19533: Wrong results from WindowAgg run-condition pushdown on count() with EXCLUDE CURRENT ROW
Date
Msg-id CAApHDvpKHEZXVDsaAyJ9pAkX3KH34jC83spXPjJPyrtrsKk_HA@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 Mon, 6 Jul 2026 at 00:54, Chengpeng Yan <chengpeng_yan@outlook.com> wrote:
> count(*) FILTER (WHERE ...)

Yeah, looks like we'll need to disable if there's a FILTER clause.

> int exclusion = frameOptions & FRAMEOPTION_EXCLUSION;
> bool plain_count_star = req->window_func->winfnoid == F_COUNT_ &&
> req->window_func->aggfilter == NULL;
>
> if (exclusion &&
> (exclusion != FRAMEOPTION_EXCLUDE_CURRENT_ROW || !plain_count_star))
> {
> req->monotonic = MONOTONICFUNC_NONE;
> PG_RETURN_POINTER(req);
> }
> ```

Given how complex Claude's logic became to get all those cases
correct, I now think the above is the best option. I've attached a
patch for that.

David

Attachment

pgsql-bugs by date:

Previous
From: Richard Guo
Date:
Subject: Re: EXPLAIN (VERBOSE) fails with for JSON_ARRAYAGG/JSON_OBJECTAGG + window function
Next
From: Konstantin Knizhnik
Date:
Subject: Re: BUG #19519: REPACK can fail due to missing chunk for toast value