Re: Understanding sequential versus index scans.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert James <srobertjames(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Understanding sequential versus index scans.
Date: 2009-07-19 23:47:40
Message-ID: 11961.1248047260@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Robert James <srobertjames(at)gmail(dot)com> writes:
> Hi. I notice that when I do a WHERE x, Postgres uses an index, and when I
> do WHERE y, it does so as well, but when I do WHERE x OR y, it
> doesn't.

It can use indexes for OR conditions, but not for arbitrary OR
conditions...

> select * from dict
> where
> word in (select substr('moon', 0, generate_series(3,length('moon')))) --
> this is my X above
> OR word like 'moon%' -- this is my Y above

... and that one is pretty arbitrary. You might have some luck with
using a UNION instead, viz

select * from dict where X
union all
select * from dict where Y

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2009-07-19 23:48:07 Re: Understanding sequential versus index scans.
Previous Message Greg Stark 2009-07-19 23:27:24 Re: Understanding sequential versus index scans.