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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Junwang Zhao <zhjwpku(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-25 16:44:26
Message-ID: 3600427.1769359466@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-01-25 16:50:28 Re: Make copyObject work in C++
Previous Message Mihail Nikalayeu 2026-01-25 16:31:00 Re: Adding REPACK [concurrently]