Re: count(*) slow on large tables

From: Shridhar Daithankar <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: count(*) slow on large tables
Date: 2003-10-06 06:06:36
Message-ID: 3F81066C.90402@persistent.co.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

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 item.

May I propose alternate approach for this optimisation?

- Postgresql allows to maintain user defined variables in shared memory.
- These variables obey transactions but do not get written to disk at all.
- There should be a facility to detect whether such a variable is initialized or
not.

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 certain conditions.
2. It updates the count as and when required.
3. If the trigger detects the count is not initialized, it would issue the same
query first time. There is no avoiding this issue.

Besides providing facility of resident variables could be used imaginatively as
well.

Does this make sense? IMO this is more generalised approach over all.

Just a thought.

Shridhar

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2003-10-06 06:15:32 Re: [COMMITTERS] pgsql-server/src/backend/catalog aclchk.c
Previous Message Christopher Kings-Lynne 2003-10-06 05:48:08 extra_float_digits question

Browse pgsql-performance by date

  From Date Subject
Next Message Shridhar Daithankar 2003-10-06 06:11:34 Re: Postgres low end processing.
Previous Message Ronald Khoo 2003-10-06 03:07:01 Re: reindex/vacuum locking/performance?