Re: [PATCH] Replace COUNT(NULL) with '0'::bigint

From: Junwang Zhao <zhjwpku(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Replace COUNT(NULL) with '0'::bigint
Date: 2026-01-26 02:41:22
Message-ID: CAEG8a3+Ba4eScRz+EjWn7q631PehyD8fyXMeD7TaHhdWLTWNpA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jan 26, 2026 at 12:44 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> > On Sun, 25 Jan 2026 at 19:48, Junwang Zhao <zhjwpku(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-01-26 02:51:10 Re: Proposal: Cascade REPLICA IDENTITY changes to leaf partitions
Previous Message Gyan Sreejith 2026-01-26 01:38:00 Re: [Proposal] Adding Log File Capability to pg_createsubscriber