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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Surprising benchmark count(1) vs. count(*)
Date: 2019-09-19 14:11:52
Message-ID: 22758.1568902312@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Thomas Kellerer <spam_eater(at)gmx(dot)net> writes:
> Laurenz Albe schrieb am 19.09.2019 um 12:22:
>> "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?

[ shrug... ] There's no special optimization for that case.
And I can't say that it seems attractive to add one.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Mariel Cherkassky 2019-09-19 15:50:44 comparing output of internal pg tables of referenced tables
Previous Message Thomas Kellerer 2019-09-19 11:22:40 Re: Surprising benchmark count(1) vs. count(*)