public inbox for [email protected]  
help / color / mirror / Atom feed
From: David Fetter <[email protected]>
To: PostgreSQL Docs <[email protected]>
To: PostgreSQL Patches <[email protected]>
Subject: Approximate count(*)
Date: Thu, 24 Mar 2005 09:01:37 -0800
Message-ID: <[email protected]> (raw)

Folks,

Please find enclosed a patch that shows how to get a quick
approximation of count(*) on a table.

Cheers,
D
-- 
David Fetter [email protected] http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.241
diff -c -r1.241 func.sgml
*** doc/src/sgml/func.sgml	14 Mar 2005 18:31:19 -0000	1.241
--- doc/src/sgml/func.sgml	24 Mar 2005 16:25:55 -0000
***************
*** 7330,7339 ****
     </para>
  
     <para>
!     Unfortunately, there is no similarly trivial query that can be
!     used to improve the performance of <function>count()</function>
!     when applied to the entire table.
     </para>
    </note>
  
   </sect1>
--- 7330,7348 ----
     </para>
  
     <para>
!     When the table has been <command>VACUUM</command>ed recently, but
!     only then, a good approximation of count(*) for an entire table
!     can be obtained as follows:
! <programlisting>
! SELECT reltuples FROM pg_class WHERE relname = 'sometable';
! </programlisting>
!    </para>
! 
!    <para>
!     Unfortunately, there is not yet a general trivial query that can
!     be used to improve the performance of <function>count()</function>.
     </para>
+ 
    </note>
  
   </sect1>


Attachments:

  [text/plain] approx_count.diff (1.1K, 2-approx_count.diff)
  download | inline diff:
Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.241
diff -c -r1.241 func.sgml
*** doc/src/sgml/func.sgml	14 Mar 2005 18:31:19 -0000	1.241
--- doc/src/sgml/func.sgml	24 Mar 2005 16:25:55 -0000
***************
*** 7330,7339 ****
     </para>
  
     <para>
!     Unfortunately, there is no similarly trivial query that can be
!     used to improve the performance of <function>count()</function>
!     when applied to the entire table.
     </para>
    </note>
  
   </sect1>
--- 7330,7348 ----
     </para>
  
     <para>
!     When the table has been <command>VACUUM</command>ed recently, but
!     only then, a good approximation of count(*) for an entire table
!     can be obtained as follows:
! <programlisting>
! SELECT reltuples FROM pg_class WHERE relname = 'sometable';
! </programlisting>
!    </para>
! 
!    <para>
!     Unfortunately, there is not yet a general trivial query that can
!     be used to improve the performance of <function>count()</function>.
     </para>
+ 
    </note>
  
   </sect1>


view thread (6+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Approximate count(*)
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox