Re: count(*) vs count(id)

From: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: count(*) vs count(id)
Date: 2021-02-03 09:54:34
Message-ID: YBpy2meHVgF4yMIa@hermes.hilbert.loc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Am Wed, Feb 03, 2021 at 01:43:14AM -0500 schrieb Cherio:

> I just ran a few practical tests on large (~14mil rows) tables that have
> multiple indexes.
>
> SELECT COUNT(id) forces PostgreSQL to use the primary key index.
> SELECT COUNT(*) allows PostgreSQL to chose an index to use and it seems to
> be choosing one of smaller size which leads to less IO and hence returns
> the result faster.

Would you mind throwing in a test for

select count(1) ...

?

Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2021-02-03 10:30:45 Re: count(*) vs count(id)
Previous Message Sebastian Dressler 2021-02-03 09:12:41 Re: Foreign table performance issue / PostgreSQK vs. ORACLE