pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Steve Wampler <swampler@noao.edu>
Cc: Bruno Wolff III <bruno@wolff.to>
Cc: pgsql-sql@postgresql.org
Subject: Re: Make COUNT(*) Faster?
Date: Fri, 08 Jul 2005 11:35:00 -0400
Message-ID: <22916.1120836900@sss.pgh.pa.us> (raw)
In-Reply-To: <42CE96AF.3020903@noao.edu>
References: <9EF2931D-1097-470D-8ECB-59D00166C96F@apple.com>
	<60vf3mklue.fsf@dba2.int.libertyrms.com>
	<42CE89CA.2070607@noao.edu>
	<20050708143508.GD22725@wolff.to>
	<42CE96AF.3020903@noao.edu>

Steve Wampler <swampler@noao.edu> writes:
> So, leave COUNT(*) alone.  But it would be very handy to have a
> way to get an approximate table size that is more accurate than is
> provided by a pg_class.reltuples that is only updated on vacuums.

If you want something cheap, you could use the same technique the
planner uses nowadays: take RelationGetNumberOfBlocks() (which is
guaranteed accurate) and multiply by reltuples/relpages.  I don't
see anyplace where RelationGetNumberOfBlocks is directly exposed to
users now, but it'd be trivial to code up a couple of C functions to
provide this functionality.

			regards, tom lane



view thread (21+ messages)  latest in thread

Message-ID: <22916.1120836900@sss.pgh.pa.us>
Permalink:  ../22916.1120836900@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22916.1120836900@sss.pgh.pa.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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, swampler@noao.edu, bruno@wolff.to
  Subject: Re: Make COUNT(*) Faster?
  In-Reply-To: <22916.1120836900@sss.pgh.pa.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