Re: [PATCH] Replace COUNT(NULL) with '0'::bigint - Mailing list pgsql-hackers

From Junwang Zhao
Subject Re: [PATCH] Replace COUNT(NULL) with '0'::bigint
Date
Msg-id CAEG8a3+Ba4eScRz+EjWn7q631PehyD8fyXMeD7TaHhdWLTWNpA@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Replace COUNT(NULL) with '0'::bigint  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Mon, Jan 26, 2026 at 12:44 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> David Rowley <dgrowleyml@gmail.com> writes:
> > On Sun, 25 Jan 2026 at 19:48, Junwang Zhao <zhjwpku@gmail.com> wrote:
> >> In [1], David Rowley noted that COUNT(NULL) can be replaced
> >> with '0'::bigint. The change should be straightforward, and I came
> >> up with the attached patch to implement it.
>
> > Coming up with the code to do this wasn't the problem. I already
> > posted it in the patch in [2]. The reason I didn't commit that part is
> > simply that I don't think anyone would ever write COUNT(NULL) in a
> > query.
>
> Yeah, I agree that this should be so rare as to not be worth expending
> planner cycles to check for, not to mention future code maintenance
> costs.  The other special cases we optimize COUNT() for are common
> real-world usages, but not this.

Agreed, good to know, thanks for the explanation.

>
>                         regards, tom lane



--
Regards
Junwang Zhao



pgsql-hackers by date:

Previous
From: Gyan Sreejith
Date:
Subject: Re: [Proposal] Adding Log File Capability to pg_createsubscriber
Next
From: Chao Li
Date:
Subject: Re: Proposal: Cascade REPLICA IDENTITY changes to leaf partitions