selecting from indexes - Mailing list pgsql-sql

From Tim Joyce
Subject selecting from indexes
Date
Msg-id 003a01bf329d$2db2f3a0$0501a8c0@noonoo
Whole thread Raw
Responses Re: [SQL] selecting from indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hi,

I am trying to improve search times on a moderately large table (approx 1
GB).

I have noticed that clustering the data improves performance significantly,
but is a bit of a pain especially with dynamic data.

What I would like to do is select data direct from the index and not have to
go back to the table itself each time.

eg, my query is:

SELECT id FROM books WHERE category_key = 1471;

(this takes ages on a table not ordered by category_key even if I have an
index on category_key)

If I created an index:

CREATE INDEX books_category_id ON books(category_key,id);

and then run the above query,  it has no need to go to the books table to
retrieve the id, and should be fast.  But it appears that it still does
access the books table.

I have tried

SELECT id FROM books_category_id WHERE category_key = 1471;

but you can't select from an index :(

Another option would be to do the clustering using a view, but:

create view books_category as select id,category from books order by
category;
ERROR:  Order by and Distinct on views is not implemented.

Does anyone know when this will be implemented?

Has anyone got any better ideas, or shall I just do static clustering once
in a while?

Thanks for any advice.

Cheers

Tim Joyce




pgsql-sql by date:

Previous
From: "Imtiaz. S. M"
Date:
Subject: Deleting rows with time 55 minutes less than max time
Next
From: Tom Lane
Date:
Subject: Re: [SQL] selecting from indexes