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

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Chengpeng Yan <chengpeng_yan(at)outlook(dot)com>
Cc: John Naylor <johncnaylorls(at)gmail(dot)com>, Richard Guo <guofenglinux(at)gmail(dot)com>, "imchifan(at)163(dot)com" <imchifan(at)163(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #19533: Wrong results from WindowAgg run-condition pushdown on count() with EXCLUDE CURRENT ROW
Date: 2026-07-06 07:24:54
Message-ID: CAApHDvpKHEZXVDsaAyJ9pAkX3KH34jC83spXPjJPyrtrsKk_HA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, 6 Jul 2026 at 00:54, Chengpeng Yan <chengpeng_yan(at)outlook(dot)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 Content-Type Size
v4_fix_count_monotonic_detection.patch application/octet-stream 15.9 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Chengpeng Yan 2026-07-06 08:31:42 Re: BUG #19533: Wrong results from WindowAgg run-condition pushdown on count() with EXCLUDE CURRENT ROW
Previous Message Michael Paquier 2026-07-06 06:36:39 Re: BUG #19519: REPACK can fail due to missing chunk for toast value