Re: view or index to optimize performance - Mailing list pgsql-general

From Richard Huxton
Subject Re: view or index to optimize performance
Date
Msg-id 43AA53DA.7010700@archonet.com
Whole thread Raw
In response to view or index to optimize performance  (Klein Balázs <Balazs.Klein@axelero.hu>)
List pgsql-general
Klein Balázs wrote:
> Hello everybody,
>
> I have a table that stores responses to questions in different
> questionnaires. This table will grow to millions of rows.
[snip]
> I can store the fact that it is biodata in the bio field - it is biodata if
> the value of that field is not 0 and I can index that field and simply use
> that as one of the conditions in queries.
>
> Or should I instead create a view that contains only the biodata and select
> from that? But will postgres use the indexes than? Would that be a better
> approach?

Create the index on the table and a view should use it.

You might like to read up on partial indexes where you can do something
like:

CREATE INDEX my_index ON itemresponse (testoccasionid,itemorder)
WHERE bio > 0;

So long as your query/view definition has WHERE bio > 0 in it then this
index can be used.

HTH
--
   Richard Huxton
   Archonet Ltd


pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: contrib extenstions
Next
From: Richard Huxton
Date:
Subject: Re: PostgreSQL crashing