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:30:32 |
Message-ID: | 41721F98.1050309@mascari.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Mike Mascari wrote:
> 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.
I'm thinking that the WHERE clauses condition should read:
WHERE l1.p_pkey is not null OR l2.p_key is not null;
My condition for a given selection of a big_table tuple is that either
y1 or y2 exist as a valid x from little_table. So I think I need an OR
instead of an AND. And AND condition would require that both y1 and y2
for the sample tuple of big_table be a valid x from little_table. Correct?
Mike Mascari
From | Date | Subject | |
---|---|---|---|
Next Message | Sim Zacks | 2004-10-17 07:39:50 | Re: Avoiding sequential scans with OR join condition |
Previous Message | Mike Mascari | 2004-10-17 07:03:25 | Re: Avoiding sequential scans with OR join condition |