From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: count(*) vs count(id) |
Date: | 2021-02-03 10:30:45 |
Message-ID: | d89a256ac1d07b7e833a979689f306f76f1ce2e9.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, 2021-02-03 at 10:54 +0100, Karsten Hilbert wrote:
> > 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) ...
No need to test. That will be slightly slower because it repeatedly checks
if 1 is NULL or not.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
From | Date | Subject | |
---|---|---|---|
Next Message | Ulrich Goebel | 2021-02-03 10:31:41 | UPDATE Syntax |
Previous Message | Karsten Hilbert | 2021-02-03 09:54:34 | Re: count(*) vs count(id) |