Re: Better index stategy for many fields with few values

From: PFC <lists(at)peufeu(dot)com>
To: "Oscar Picasso" <oscgoogle(at)yahoo(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Better index stategy for many fields with few values
Date: 2006-04-10 17:26:13
Message-ID: op.s7sypzhpcigqcu@apollo13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


> - My items table:
> code int -- can take one of 100 values
> property varchar(250) -- can take one of 5000 values
> param01 char(10) -- can take one of 10 values
> param02 char(10) -- can take one of 10 values
> ...
> [ 20 similar columns }
> ...
> parama20 char(10) -- can take one of 10 values

Instead of 20 columns, you could instead use a "param" field containing
an array of 20 TEXT fields.
Then create a simple index on (code, param) and SELECT WHERE code BETWEEN
... AND param = '{P,G,....,C}'

If you don't want to modify your structure, you can create a functional
index on an array {param1...param20}, but your queries will be a bit
uglier.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Joshua D. Drake 2006-04-10 18:20:04 Re: Takes too long to fetch the data from database
Previous Message PFC 2006-04-10 17:20:33 Re: Restore performance?