Re: Have the planner convert COUNT(1) / COUNT(not_null_col) to COUNT(*)

David Rowley <dgrowleyml@gmail.com>

From: David Rowley <dgrowleyml@gmail.com>
To: Matheus Alcantara <matheusssilv97@gmail.com>
Cc: Corey Huinker <corey.huinker@gmail.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2025-11-25T23:37:50Z
Lists: pgsql-hackers

Attachments

On Wed, 5 Nov 2025 at 13:16, David Rowley <dgrowleyml@gmail.com> wrote:
> I've attached a version with the NOT_USED part removed (and a bunch of
> #includes I forgot to remove). The only other change was a minor
> revision to some comments.

This patch needed to be rebased due to the changes made in b140c8d7a.
I also adjusted a few comments and adjusted some code in
simplify_aggref() which mistakenly assumed the support function would
always return an Aggref. That conflicted with what I'd written in the
header comment for the SupportRequestSimplifyAggref struct; "(probably
another Aggref)". Which is leaving the door open for more aggressive
optimisations that someone might want to do, e.g. the mentioned
COUNT(NULL) replaced with '0'::bigint.

I'm not seeing any reason now not to go ahead with this now. Does
anyone else want to take a look at it before I start wielding the
sword of commitment on it?

David