Re: Can this be indexed?

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: mailinglists(at)net-virtual(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Can this be indexed?
Date: 2004-11-08 01:39:59
Message-ID: 20041108.103959.32716752.t-ishii@sra.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Is there a way to create an index that would make this query be efficient
> and not perform a sequential scan?
>
> SELECT count(*) AS count,id FROM sometable GROUP BY id;
>
> .. I've considered creating a rule on this table which would put the
> results of this into another table anytime it is updated, but I thought
> there might be an easier way.

Sure. Try to create an index on id. Another way to improve this query
is to use HashAggregate (this is new in 7.4). Sometimes it is much
faster than group-by-using-index-scan. To enable HashAggregate
you might want to increase sort_mem.
--
Tatsuo Ishii

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gary L. Burnore 2004-11-08 02:10:48 Re: Postresql RFD version 2.0 Help Wanted.
Previous Message Marc G. Fournier 2004-11-08 01:14:35 Re: Postresql RFD version 2.0 Help Wanted.