Re: count(*) optimization

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Nikola Ivacic <nikola(at)rs-pi(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: count(*) optimization
Date: 2003-01-08 16:22:58
Message-ID: 20030108162258.GA9033@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jan 08, 2003 at 17:04:40 +0100,
Nikola Ivacic <nikola(at)rs-pi(dot)com> wrote:
> Hi
>
> I have trouble executing count(*) statement.
> On a large dataset it takes quite a while to return result.
> Is there any other way to get number of tupples in relation
> or is the only way to optimize count() function to index it?

Indexes won't help count.

If you retrieve counts a lot more than you do updates that will change their
value, then you may want to keep the counts in another table and use
triggers to keep them updated.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bob Lapique 2003-01-08 16:55:57 What benefits can I expect from schemas ?
Previous Message Ross J. Reedstrom 2003-01-08 16:18:45 Re: Search and Replace