Re: Slow count(*) again... - Mailing list pgsql-performance

From Scott Carey
Subject Re: Slow count(*) again...
Date
Msg-id AFDEB033-DC31-46BF-ABF9-561A9D1AE4E0@richrelevance.com
Whole thread Raw
In response to Re: Slow count(*) again...  (Craig Ringer <craig@postnewspapers.com.au>)
List pgsql-performance
>>
>
> A count with any joins or filter criteria would still have to scan all
> pages with visible tuples in them. So the visibility map helps speed up
> scanning of bloated tables, but doesn't provide a magical "fast count"
> except in the utterly trivial "select count(*) from tablename;" case,
> and can probably only be used for accurate results when there are no
> read/write transactions currently open.

select count(*) from tablename where [condition or filter that can use an index] [group by on columns in the index]

will also work, I think.

Additionally, I think it can work if other open transactions exist, provided they haven't written to the table being
scanned. If they have, then only those pages that have been altered and marked in the visibility map need to be cracked
openthe normal way. 

> Even if you kept a count of
> tuples in each page along with the mvcc transaction ID information
> required to determine for which transactions that count is valid, it'd
> only be useful if you didn't have to do any condition checks, and it'd
> be yet another thing to update with every insert/delete/update.
>

Yes, lots of drawbacks and added complexity.

> Perhaps for some users that'd be worth having, but it seems to me like
> it'd have pretty narrow utility. I'm not sure that's the answer.
>
> --
> Craig Ringer
>
> --
> Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-performance


pgsql-performance by date:

Previous
From: Chris Browne
Date:
Subject: Re: Slow count(*) again...
Next
From: Jesper Krogh
Date:
Subject: Re: Slow count(*) again...