Re: Surprising benchmark count(1) vs. count(*)

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Surprising benchmark count(1) vs. count(*)
Date: 2019-09-19 10:22:42
Message-ID: ab88db80f032933ff603d9d59745e8a09196bc1e.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, 2019-09-19 at 12:09 +0200, Thomas Kellerer wrote:
> https://blog.jooq.org/2019/09/19/whats-faster-count-or-count1/
>
> Is there a reason why count(*) seems to be faster?

"count(*)" is just the SQL standard's way of saying what you'd
normally call "count()", that is, an aggregate without arguments.

"count(1)" has to check if 1 IS NULL for each row, because NULL
values are not counted. "count(*)" doesn't have to do that.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Thomas Kellerer 2019-09-19 11:22:40 Re: Surprising benchmark count(1) vs. count(*)
Previous Message Thomas Kellerer 2019-09-19 10:09:32 Surprising benchmark count(1) vs. count(*)