pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bruce Momjian <pgman@candle.pha.pa.us>
Cc: Christopher Browne <cbbrowne@libertyrms.info>
Cc: pgsql-performance@postgresql.org
Subject: Re: count(*) slow on large tables
Date: Sat, 04 Oct 2003 12:49:33 -0400
Message-ID: <6743.1065286173@sss.pgh.pa.us> (raw)
In-Reply-To: <200310041556.h94Fuek24423@candle.pha.pa.us>
References: <200310041556.h94Fuek24423@candle.pha.pa.us>

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> We do have a TODO item:
> 	* Consider using MVCC to cache count(*) queries with no WHERE clause

> The idea is to cache a recent count of the table, then have
> insert/delete add +/- records to the count.  A COUNT(*) would get the
> main cached record plus any visible +/- records.  This would allow the
> count to return the proper value depending on the visibility of the
> requesting transaction, and it would require _no_ heap or index scan.

... and it would give the wrong answers.  Unless the cache is somehow
snapshot-aware, so that it can know which other transactions should be
included in your count.

			regards, tom lane



view thread (30+ messages)  latest in thread

Message-ID: <6743.1065286173@sss.pgh.pa.us>
Permalink:  ../6743.1065286173@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6743.1065286173@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-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgman@candle.pha.pa.us, cbbrowne@libertyrms.info
  Subject: Re: count(*) slow on large tables
  In-Reply-To: <6743.1065286173@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