Re: view or index to optimize performance

From: Richard Huxton <dev(at)archonet(dot)com>
To: Klein Balázs <Balazs(dot)Klein(at)axelero(dot)hu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: view or index to optimize performance
Date: 2005-12-22 07:20:58
Message-ID: 43AA53DA.7010700@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-12-22 07:22:02 Re: contrib extenstions
Previous Message Richard Huxton 2005-12-22 07:18:09 Re: Funky template1 problem?