pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Karsten Hilbert <Karsten.Hilbert@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: count(*) vs count(id)
Date: Wed, 3 Feb 2021 10:54:34 +0100
Message-ID: <YBpy2meHVgF4yMIa@hermes.hilbert.loc> (raw)
In-Reply-To: <CAKHqFkKWVam7LyVM7bxDMXxsr4fZVbNuTG=rfHx07jpF5f6MMA@mail.gmail.com>
References: <CAOLfK3VWa_Mv3OSumvpHZdppd+qDj8EUWCdxY5+vUe=gAo+h0A@mail.gmail.com>
	<cb465259-e29a-8fc2-1890-2666b8d79f36@gmail.com>
	<CAOLfK3W99Cdf9Sq+XyJv5MAjp9wsYBKpAC2UAVp7+dB881KmjQ@mail.gmail.com>
	<3502043.1612226098@sss.pgh.pa.us>
	<CAOLfK3XBUxP3jbAnKVn9cei4hh4snozhVj5yjxCipVnYvwfTsA@mail.gmail.com>
	<fe5b3e56cf75094864ac0d05eadefacc42d572c0.camel@cybertec.at>
	<CAN3Qy4q1VXQHbUsVH7+yKumdfyfcxQAaHTGS5XKgjZ-5PMOpRA@mail.gmail.com>
	<CAKHqFkKWVam7LyVM7bxDMXxsr4fZVbNuTG=rfHx07jpF5f6MMA@mail.gmail.com>

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





view thread (14+ messages)  latest in thread

Message-ID: <YBpy2meHVgF4yMIa@hermes.hilbert.loc>
Permalink:  ../YBpy2meHVgF4yMIa@hermes.hilbert.loc/
Also on:    postgresql.org/message-id/YBpy2meHVgF4yMIa@hermes.hilbert.loc

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: Karsten.Hilbert@gmx.net
  Subject: Re: count(*) vs count(id)
  In-Reply-To: <YBpy2meHVgF4yMIa@hermes.hilbert.loc>
  References: <CAOLfK3VWa_Mv3OSumvpHZdppd+qDj8EUWCdxY5+vUe=gAo+h0A@mail.gmail.com> <cb465259-e29a-8fc2-1890-2666b8d79f36@gmail.com> <CAOLfK3W99Cdf9Sq+XyJv5MAjp9wsYBKpAC2UAVp7+dB881KmjQ@mail.gmail.com> <3502043.1612226098@sss.pgh.pa.us> <CAOLfK3XBUxP3jbAnKVn9cei4hh4snozhVj5yjxCipVnYvwfTsA@mail.gmail.com> <fe5b3e56cf75094864ac0d05eadefacc42d572c0.camel@cybertec.at> <CAN3Qy4q1VXQHbUsVH7+yKumdfyfcxQAaHTGS5XKgjZ-5PMOpRA@mail.gmail.com> <CAKHqFkKWVam7LyVM7bxDMXxsr4fZVbNuTG=rfHx07jpF5f6MMA@mail.gmail.com> <YBpy2meHVgF4yMIa@hermes.hilbert.loc>

* 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