pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-performance@lists.postgresql.org
Subject: Re: Surprising benchmark count(1) vs. count(*)
Date: Thu, 19 Sep 2019 12:22:42 +0200
Message-ID: <ab88db80f032933ff603d9d59745e8a09196bc1e.camel@cybertec.at> (raw)
In-Reply-To: <df354b76-a645-73fc-9645-4508e5291d71@gmx.net>
References: <df354b76-a645-73fc-9645-4508e5291d71@gmx.net>

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






view thread (6+ messages)  latest in thread

Message-ID: <ab88db80f032933ff603d9d59745e8a09196bc1e.camel@cybertec.at>
Permalink:  ../ab88db80f032933ff603d9d59745e8a09196bc1e.camel@cybertec.at/
Also on:    postgresql.org/message-id/ab88db80f032933ff603d9d59745e8a09196bc1e.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: laurenz.albe@cybertec.at, spam_eater@gmx.net, pgsql-performance@lists.postgresql.org
  Subject: Re: Surprising benchmark count(1) vs. count(*)
  In-Reply-To: <ab88db80f032933ff603d9d59745e8a09196bc1e.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox