Re: Surprising benchmark count(1) vs. count(*) - Mailing list pgsql-performance

From Tom Lane
Subject Re: Surprising benchmark count(1) vs. count(*)
Date
Msg-id 22758.1568902312@sss.pgh.pa.us
Whole thread Raw
In response to Re: Surprising benchmark count(1) vs. count(*)  (Thomas Kellerer <spam_eater@gmx.net>)
Responses Re: Surprising benchmark count(1) vs. count(*)  (Adam Brusselback <adambrusselback@gmail.com>)
List pgsql-performance
Thomas Kellerer <spam_eater@gmx.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



pgsql-performance by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Surprising benchmark count(1) vs. count(*)
Next
From: Mariel Cherkassky
Date:
Subject: comparing output of internal pg tables of referenced tables