From: Merlin Moncure <mmoncure@gmail.com>
To: Andreas Tille <tillea@rki.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Performance of count(*)
Date: Thu, 22 Mar 2007 09:39:18 -0400
Message-ID: <b42b73150703220639x40dbac7en29318778b43e1e4c@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.62.0703221149210.13747@wr-linux02>
References: <Pine.LNX.4.62.0703221149210.13747@wr-linux02>
On 3/22/07, Andreas Tille <tillea@rki.de> wrote:
> I just try to find out why a simple count(*) might last that long.
> At first I tried explain, which rather quickly knows how many rows
> to check, but the final count is two orders of magnitude slower.
You can get the approximate count by selecting reltuples from
pg_class. It is valid as of last analyze.
As others suggest select count(*) from table is very special case
which non-mvcc databases can optimize for. There are many reasons why
this is the case and why it explains nothing about the relative
performance of the two databases. This is probably #1 most
frequenctly asked question to -performance...there is a wealth of
information in the archives.
merlin
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-performance@postgresql.org
Cc: mmoncure@gmail.com, tillea@rki.de
Subject: Re: Performance of count(*)
In-Reply-To: <b42b73150703220639x40dbac7en29318778b43e1e4c@mail.gmail.com>
References: <Pine.LNX.4.62.0703221149210.13747@wr-linux02> <b42b73150703220639x40dbac7en29318778b43e1e4c@mail.gmail.com>
* 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