Skip site navigation (1) Skip section navigation (2)

Re: Performance of count(*)

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Andreas Tille" <tillea(at)rki(dot)de>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Performance of count(*)
Date: 2007-03-22 13:39:18
Message-ID: b42b73150703220639x40dbac7en29318778b43e1e4c@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-performance
On 3/22/07, Andreas Tille <tillea(at)rki(dot)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

In response to

Responses

pgsql-performance by date

Next:From: Alvaro HerreraDate: 2007-03-22 13:52:05
Subject: Re: Parallel Vacuum
Previous:From: DimitriDate: 2007-03-22 13:35:53
Subject: Parallel Vacuum

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group