Re: Can this be indexed? - Mailing list pgsql-general

From Tatsuo Ishii
Subject Re: Can this be indexed?
Date
Msg-id 20041108.103959.32716752.t-ishii@sra.co.jp
Whole thread Raw
In response to Can this be indexed?  ("Net Virtual Mailing Lists" <mailinglists@net-virtual.com>)
List 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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re:
Next
From: "Gary L. Burnore"
Date:
Subject: Re: Postresql RFD version 2.0 Help Wanted.