Re: count(*) slow on large tables

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Christopher Browne <cbbrowne(at)libertyrms(dot)info>, pgsql-performance(at)postgresql(dot)org
Subject: Re: count(*) slow on large tables
Date: 2003-10-04 18:19:46
Message-ID: 200310041819.h94IJkV07596@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Tom Lane wrote:
> >> ... 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.
>
> > The cache is an ordinary table, with xid's on every row. I meant it
> > would require no index/heap scans of the large table --- it would still
> > require a scan of the "count" table.
>
> Oh, that idea. Yeah, I think we had concluded it might work. You'd
> better make the TODO item link to that discussion, because there's sure
> been plenty of discussion of ideas that wouldn't work.

OK, I beefed up the TODO:

* Use a fixed row count and a +/- count with MVCC visibility rules
to allow fast COUNT(*) queries with no WHERE clause(?)

I can always give the details if someone asks. It doesn't seem complex
enough for a separate TODO.detail item.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-10-04 18:24:40 Re: pg_dump bug in 7.4
Previous Message Bruce Momjian 2003-10-04 18:15:42 Re: pg_dump bug in 7.4

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2003-10-04 18:34:32 Re: count(*) slow on large tables
Previous Message Tom Lane 2003-10-04 17:51:38 Re: count(*) slow on large tables