Re: Avoiding sequential scans with OR join condition

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mike Mascari <mascarm(at)mascari(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Avoiding sequential scans with OR join condition
Date: 2004-10-16 16:15:18
Message-ID: 4234.1097943318@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mike Mascari <mascarm(at)mascari(dot)com> writes:
> SELECT big_table.*
> FROM little_table, big_table
> WHERE little_table.x = 10 AND
> little_table.y IN (big_table.y1, big_table.y2);

> Is there any way to write the first query such that indexes will be used?

I'm afraid you're stuck with the UNION workaround. The planner's
treatment of OR indexscans is entirely separate from its treatment of
join indexscans, so it's just not capable of forming the sort of plan
you are envisioning. It'd be nice to improve that someday, but it'd
take either a pile of duplicate code, or a fairly thorough rewrite
of indxpath.c/orindxpath.c.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2004-10-16 16:20:35 Re: plpgsql loop not returning value
Previous Message Mark Dexter 2004-10-16 15:11:00 Re: Complex Update Queries with Fromlist