| From: | Laurent Martelli <laurent(dot)martelli(at)enercoop(dot)org> |
|---|---|
| To: | pgsql-performance(at)postgresql(dot)org |
| Subject: | Re: IS NOT NULL and LEFT JOIN |
| Date: | 2014-10-20 21:02:33 |
| Message-ID: | 54457869.3030601@enercoop.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-performance |
Le 20/10/2014 15:58, Tom Lane a écrit :
> Laurent Martelli <laurent(dot)martelli(at)enercoop(dot)org> writes:
>> Do we agree that both queries are identical ?
> No, they *aren't* identical. Go consult any SQL reference. Left join
> conditions don't work the way you seem to be thinking: after the join,
> the RHS column might be null, rather than equal to the LHS column.
Yes, I was wrong to assume that c.user_info=u.id because of the LEFT JOIN.
But since I only want rows where u.id IS NOT NULL, in any case I will
also have c.user_info IS NOT NULL.
Also, having a foreign key, if c.user_info is not null, it will have a
match in u. So in that case, either both c.user_info and c.id are null
in the result rows, or they are equal.
Regards,
Laurent
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David G Johnston | 2014-10-20 22:19:50 | Re: IS NOT NULL and LEFT JOIN |
| Previous Message | Marco Di Cesare | 2014-10-20 20:32:56 | Query with large number of joins |