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

From Tom Lane
Subject Re: [PATCH] Replace COUNT(NULL) with '0'::bigint
Date
Msg-id 3600427.1769359466@sss.pgh.pa.us
Whole thread Raw
In response to Re: [PATCH] Replace COUNT(NULL) with '0'::bigint  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: [PATCH] Replace COUNT(NULL) with '0'::bigint
List pgsql-hackers
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.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Mihail Nikalayeu
Date:
Subject: Re: Adding REPACK [concurrently]
Next
From: Andres Freund
Date:
Subject: Re: Make copyObject work in C++