Re: Avoiding sequential scans with OR join condition

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: Sim Zacks <sim(at)compulab(dot)co(dot)il>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Avoiding sequential scans with OR join condition
Date: 2004-10-17 07:03:25
Message-ID: 4172193D.8030202@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sim Zacks wrote:
> I would use 2 left joins and use the where condition to make sure one
> of them is true, such as:
>
> select big_table.* from
> big_table left join little_table as l1 on big_table.y1=l1.y and
> l1.x=10
> left join little_table as l2 on big_table.y2=l2.y and l1.x=10
> where l1.p_key is not null and l2.p_key is not null
>
> I have never tried this in postgresql, but in my experience with
> various other DB engines it is a lot faster then using an or in the
> join and faster then a union.

Wow! Thanks! That certainly did the trick.

Mike Mascari

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Mascari 2004-10-17 07:30:32 Re: Avoiding sequential scans with OR join condition
Previous Message Sim Zacks 2004-10-17 06:25:18 Re: Avoiding sequential scans with OR join condition