pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Stone <mstone+postgres@mathom.us>
To: pgsql-performance@postgresql.org
Subject: Re: Performance of count(*)
Date: Thu, 22 Mar 2007 10:41:51 -0400
Message-ID: <20070322144149.GF11402@mathom.us> (raw)
In-Reply-To: <b42b73150703220639x40dbac7en29318778b43e1e4c@mail.gmail.com>
References: <Pine.LNX.4.62.0703221149210.13747@wr-linux02>
	<b42b73150703220639x40dbac7en29318778b43e1e4c@mail.gmail.com>

On Thu, Mar 22, 2007 at 09:39:18AM -0400, Merlin Moncure wrote:
>You can get the approximate count by selecting reltuples from
>pg_class.  It is valid as of last analyze.

Of course, that only works if you're not using any WHERE clause. 
Here's a (somewhat ugly) example of getting an approximate count based 
off the statistics info, which will work for more complicated queries:
http://archives.postgresql.org/pgsql-sql/2005-08/msg00046.php
The ugliness is that you have to provide the whole query as a 
parameter to the function, instead of using it as a drop-in replacement 
for count. I assume that the TODO item is to provide the latter, but for 
now this method can be useful for UI type stuff where you just want to 
know whether there's "a little" or "a lot".

Mike Stone



view thread (41+ messages)  latest in thread

Message-ID: <20070322144149.GF11402@mathom.us>
Permalink:  ../20070322144149.GF11402@mathom.us/
Also on:    postgresql.org/message-id/20070322144149.GF11402@mathom.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: mstone+postgres@mathom.us
  Subject: Re: Performance of count(*)
  In-Reply-To: <20070322144149.GF11402@mathom.us>

* 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