Re: [PERFORM] count(*) slow on large tables

2003-10-06 Thread Shridhar Daithankar
Bruce Momjian wrote: 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

Re: [PERFORM] count(*) slow on large tables

2003-10-06 Thread Sean Chittenden
How it will help? This is in addition to trigger proposal that came up earlier. With triggers it's not possible to make values visible across backends unless trigger updates a table, which eventually leads to vacuum/dead tuples problem. 1. User creates a trigger to check updates/inserts for

Re: [PERFORM] count(*) slow on large tables

2003-10-05 Thread Josh Berkus
Bruce, 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. Hmmm ...

Re: [PERFORM] count(*) slow on large tables

2003-10-05 Thread Rod Taylor
And for those GUIs, wouldn't it be 97% as good to run an ANALYZE and give the approximate record counts for large tables? Interfaces which run a COUNT(*) like that are broken by design. They fail to consider the table may really be a view which of course could not be cached with results like

Re: [PERFORM] count(*) slow on large tables

2003-10-04 Thread Christopher Kings-Lynne
On our message boards each post is a row. The powers that be like to know how many posts there are total (In addition to 'today')- select count(*) from posts is how it has been done on our informix db. With our port to PG I instead select reltuples pg_class. We have exactly the same situation,

Re: [PERFORM] count(*) slow on large tables

2003-10-04 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] 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

Re: [PERFORM] count(*) slow on large tables

2003-10-04 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] 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

Re: [PERFORM] count(*) slow on large tables

2003-10-04 Thread Bruce Momjian
Tom Lane wrote: Bruce Momjian [EMAIL PROTECTED] 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

Re: [PERFORM] count(*) slow on large tables

2003-10-04 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] writes: It doesn't seem complex enough for a separate TODO.detail item. I thought it was, if only because it is so easy to think of wrong implementations. regards, tom lane ---(end of

Re: [PERFORM] count(*) slow on large tables

2003-10-03 Thread Christopher Browne
Oops! [EMAIL PROTECTED] (Dror Matalon) was seen spray-painting on a wall: I smell a religious war in the aii:-). Can you go several days in a row without doing select count(*) on any of your tables? I would be more likely, personally, to run VACUUM VERBOSE ANALYZE, which has useful

Re: [PERFORM] count(*) slow on large tables

2003-10-03 Thread Jeff
On Thu, 2 Oct 2003, Christopher Browne wrote: I can't imagine why the raw number of tuples in a relation would be expected to necessarily be terribly useful. We use stuff like that for reporting queries. example: On our message boards each post is a row. The powers that be like to know how

Re: [PERFORM] count(*) slow on large tables

2003-10-02 Thread Bruno Wolff III
On Thu, Oct 02, 2003 at 12:46:45 -0700, Dror Matalon [EMAIL PROTECTED] wrote: Please keep replies copied to the list. When would it happen that a tuple be invisible to the current transaction? Are we talking about permissions? They could be tuples that were changed by a transaction that

Re: [PERFORM] count(*) slow on large tables

2003-10-02 Thread Greg Stark
Christopher Browne [EMAIL PROTECTED] writes: It would be very hairy to implement it correctly, and all this would cover is the single case of SELECT COUNT(*) FROM SOME_TABLE; If you had a single WHERE clause attached, you would have to revert to walking through the tuples looking for the