Re: left joins - Mailing list pgsql-sql

From Tom Lane
Subject Re: left joins
Date
Msg-id 26225.1120661054@sss.pgh.pa.us
Whole thread Raw
In response to left joins  ("Grant Morgan" <grant@ryuuguu.com>)
List pgsql-sql
"Grant Morgan" <grant@ryuuguu.com> writes:
> select count(*)
>  from  h left join p using (r,pos)
> where h.tn > 20
> and h.tn < 30
> and p.r_order=1

> since it is a left join I though I should get a number no smaller in
> the left join than the original unjoined query. It seems to be acting
> like an inner join.

Well, yeah.  The condition p.r_order=1 will return NULL (effectively
FALSE) for any row in which p.r_order is NULL, so none of the
null-extended rows can survive the WHERE filter, so it's effectively
an inner join.  Recent versions of PG actively recognize this case
and reduce the LEFT JOIN to plain JOIN, but even if we did not do that
you'd get the same result.

I've heard it claimed that Oracle produces different results; if true,
it must have something to do with their rather standards-challenged
interpretation of NULL ...
        regards, tom lane


pgsql-sql by date:

Previous
From: "Grant Morgan"
Date:
Subject: Re: left joins
Next
From: Jocelyn Turcotte
Date:
Subject: Prepare plan in plpgsql