Re: Make COUNT(*) Faster? - Mailing list pgsql-sql

From Tom Lane
Subject Re: Make COUNT(*) Faster?
Date
Msg-id 22916.1120836900@sss.pgh.pa.us
Whole thread Raw
In response to Re: Make COUNT(*) Faster?  (Steve Wampler <swampler@noao.edu>)
Responses Re: Make COUNT(*) Faster?
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Dawid Kuroczko
Date:
Subject: Re: Make COUNT(*) Faster?
Next
From: Rod Taylor
Date:
Subject: Re: Make COUNT(*) Faster?