pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedClustered/covering indexes (or lack thereof :-)
4+ messages / 4 participants
[nested] [flat]
* Clustered/covering indexes (or lack thereof :-)
@ 2007-11-12 06:59 adrobj <adrobj@yahoo.com>
0 siblings, 2 replies; 4+ messages in thread
From: adrobj @ 2007-11-12 06:59 UTC (permalink / raw)
To: pgsql-performance
This is probably a FAQ, but I can't find a good answer...
So - are there common techniques to compensate for the lack of
clustered/covering indexes in PostgreSQL? To be more specific - here is my
table (simplified):
topic_id int
post_id int
post_text varchar(1024)
The most used query is: SELECT post_id, post_text FROM Posts WHERE
topic_id=XXX. Normally I would have created a clustered index on topic_id,
and the whole query would take ~1 disk seek.
What would be the common way to handle this in PostgreSQL, provided that I
can't afford 1 disk seek per record returned?
--
View this message in context: http://www.nabble.com/Clustered-covering-indexes-%28or-lack-thereof-%3A-%29-tf4789321.html#a13700848
Sent from the PostgreSQL - performance mailing list archive at Nabble.com.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Clustered/covering indexes (or lack thereof :-)
@ 2007-11-16 19:33 Heikki Linnakangas <heikki@enterprisedb.com>
parent: adrobj <adrobj@yahoo.com>
1 sibling, 0 replies; 4+ messages in thread
From: Heikki Linnakangas @ 2007-11-16 19:33 UTC (permalink / raw)
To: adrobj <adrobj@yahoo.com>; +Cc: pgsql-performance
adrobj wrote:
> This is probably a FAQ, but I can't find a good answer...
>
> So - are there common techniques to compensate for the lack of
> clustered/covering indexes in PostgreSQL? To be more specific - here is my
> table (simplified):
>
> topic_id int
> post_id int
> post_text varchar(1024)
>
> The most used query is: SELECT post_id, post_text FROM Posts WHERE
> topic_id=XXX. Normally I would have created a clustered index on topic_id,
> and the whole query would take ~1 disk seek.
>
> What would be the common way to handle this in PostgreSQL, provided that I
> can't afford 1 disk seek per record returned?
You can cluster the table, see
http://www.postgresql.org/docs/8.2/interactive/sql-cluster.html.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Clustered/covering indexes (or lack thereof :-)
@ 2007-11-16 19:34 Jeff Davis <pgsql@j-davis.com>
parent: adrobj <adrobj@yahoo.com>
1 sibling, 1 reply; 4+ messages in thread
From: Jeff Davis @ 2007-11-16 19:34 UTC (permalink / raw)
To: adrobj <adrobj@yahoo.com>; +Cc: pgsql-performance
On Sun, 2007-11-11 at 22:59 -0800, adrobj wrote:
> This is probably a FAQ, but I can't find a good answer...
>
> So - are there common techniques to compensate for the lack of
> clustered/covering indexes in PostgreSQL? To be more specific - here is my
> table (simplified):
>
> topic_id int
> post_id int
> post_text varchar(1024)
>
> The most used query is: SELECT post_id, post_text FROM Posts WHERE
> topic_id=XXX. Normally I would have created a clustered index on topic_id,
> and the whole query would take ~1 disk seek.
>
> What would be the common way to handle this in PostgreSQL, provided that I
> can't afford 1 disk seek per record returned?
>
Periodically CLUSTER the table on the topic_id index. The table will not
be perfectly clustered at all times, but it will be close enough that it
won't make much difference.
There's still the hit of performing a CLUSTER, however.
Another option, if you have a relatively small number of topic_ids, is
to break it into separate tables, one for each topic_id.
Regards,
Jeff Davis
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Clustered/covering indexes (or lack thereof :-)
@ 2007-11-16 19:51 Bill Moran <wmoran@collaborativefusion.com>
parent: Jeff Davis <pgsql@j-davis.com>
0 siblings, 0 replies; 4+ messages in thread
From: Bill Moran @ 2007-11-16 19:51 UTC (permalink / raw)
To: Jeff Davis <pgsql@j-davis.com>; +Cc: adrobj <adrobj@yahoo.com>; pgsql-performance
In response to Jeff Davis <pgsql@j-davis.com>:
> On Sun, 2007-11-11 at 22:59 -0800, adrobj wrote:
> > This is probably a FAQ, but I can't find a good answer...
> >
> > So - are there common techniques to compensate for the lack of
> > clustered/covering indexes in PostgreSQL? To be more specific - here is my
> > table (simplified):
> >
> > topic_id int
> > post_id int
> > post_text varchar(1024)
> >
> > The most used query is: SELECT post_id, post_text FROM Posts WHERE
> > topic_id=XXX. Normally I would have created a clustered index on topic_id,
> > and the whole query would take ~1 disk seek.
> >
> > What would be the common way to handle this in PostgreSQL, provided that I
> > can't afford 1 disk seek per record returned?
> >
>
> Periodically CLUSTER the table on the topic_id index. The table will not
> be perfectly clustered at all times, but it will be close enough that it
> won't make much difference.
>
> There's still the hit of performing a CLUSTER, however.
>
> Another option, if you have a relatively small number of topic_ids, is
> to break it into separate tables, one for each topic_id.
Or materialize the data, if performance is the utmost requirement.
Create second table:
materialized_topics (
topic_id int,
post_ids int[],
post_texts text[]
)
Now add a trigger to your original table that updates materialized_topics
any time the first table is altered. Thus you always have fast lookups.
Of course, this may be non-optimal if that table sees a lot of updates.
--
Bill Moran
Collaborative Fusion Inc.
http://people.collaborativefusion.com/~wmoran/
wmoran@collaborativefusion.com
Phone: 412-422-3463x4023
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2007-11-16 19:51 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-11-12 06:59 Clustered/covering indexes (or lack thereof :-) adrobj <adrobj@yahoo.com>
2007-11-16 19:33 ` Heikki Linnakangas <heikki@enterprisedb.com>
2007-11-16 19:34 ` Jeff Davis <pgsql@j-davis.com>
2007-11-16 19:51 ` Bill Moran <wmoran@collaborativefusion.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox