pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: 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 13:22:40 +0200
Message-ID: <35f81ca4-f68e-8b71-d34c-7364751b4e36@gmx.net> (raw)
In-Reply-To: <ab88db80f032933ff603d9d59745e8a09196bc1e.camel@cybertec.at>
References: <df354b76-a645-73fc-9645-4508e5291d71@gmx.net>
	<ab88db80f032933ff603d9d59745e8a09196bc1e.camel@cybertec.at>

Laurenz Albe schrieb am 19.09.2019 um 12:22:
>> 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.

But 1 is a constant, why does it need to check it for each row? 







view thread (6+ messages)  latest in thread

Message-ID: <35f81ca4-f68e-8b71-d34c-7364751b4e36@gmx.net>
Permalink:  ../35f81ca4-f68e-8b71-d34c-7364751b4e36@gmx.net/
Also on:    postgresql.org/message-id/35f81ca4-f68e-8b71-d34c-7364751b4e36@gmx.net

 · 

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: spam_eater@gmx.net, pgsql-performance@lists.postgresql.org
  Subject: Re: Surprising benchmark count(1) vs. count(*)
  In-Reply-To: <35f81ca4-f68e-8b71-d34c-7364751b4e36@gmx.net>

* 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