Re: BUG #18978: Index does not work in aggregate function filter

David G. Johnston <david.g.johnston@gmail.com>

From: "David G. Johnston" <david.g.johnston@gmail.com>
To: jinhui-lai@foxmail.com, pgsql-bugs@lists.postgresql.org
Date: 2025-07-03T16:36:29Z
Lists: pgsql-bugs
On Thu, Jul 3, 2025 at 9:23 AM PG Bug reporting form <noreply@postgresql.org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference:      18978
> Logged by:          Jinhui
> Email address:      jinhui-lai@foxmail.com
> PostgreSQL version: 17.5
> Operating system:   ubuntu 22.04
> Description:
>
>
> explain SELECT COUNT(c1) FILTER (WHERE c1<2) FROM t1;
>

No.  You just need to use a where clause when it is appropriate and a
filter when it is appropriate.  A filter clause has no right imposing a
restriction on what rows are selected for its level of query - other
columns may very well need those rows.

David J.