Or selection on index versus union

From: han(dot)holl(at)informationslogik(dot)nl
To: pgsql-general(at)postgresql(dot)org
Subject: Or selection on index versus union
Date: 2005-10-04 19:32:41
Message-ID: 200510042132.41642.han.holl@informationslogik.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hello

I've got a table with an index, let's call it fase.

The following query is fine: 'select something from table where fase = '1';

However, this is disastrously slow:
select something from table where fase = '1' or fase = '2';

The reason is that the query planner decides to ignore the index, and goes for
a sequential scan of the table (with a couple of million records).

If I do:
select something from table where fase = '1'
union
select something from table where fase = '2';

it's fine again, but it's a lot of typing, and the first formulation has a
more natural feel to it.

Is there a way to convince the planner to use the fase index for this type of
query, or is there a hook somewhere that I missed that allows me to rewrite
a query like the above with a server-side function ?

Thanks in advance,

Han Holl

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Aaron Glenn 2005-10-04 19:41:56 Re: License question[VASCL:A1077160A86]
Previous Message Magnus Hagander 2005-10-04 19:27:07 Re: License question