From: Laurent Martelli <laurent.martelli@enercoop.org>
To: pgsql-performance@postgresql.org
Subject: Re: IS NOT NULL and LEFT JOIN
Date: Mon, 20 Oct 2014 23:02:33 +0200
Message-ID: <54457869.3030601@enercoop.org> (raw)
In-Reply-To: <3181.1413813488@sss.pgh.pa.us>
References: <544339CA.5090202@enercoop.org>
<CAApHDvoqMm-hdoktQ+9ErGZ3rkF6=vgeHTJ-M6OeQepr1XLDoQ@mail.gmail.com>
<5444D5FF.5070407@enercoop.org>
<3181.1413813488@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
Le 20/10/2014 15:58, Tom Lane a écrit :
> Laurent Martelli <laurent.martelli@enercoop.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
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: laurent.martelli@enercoop.org
Subject: Re: IS NOT NULL and LEFT JOIN
In-Reply-To: <54457869.3030601@enercoop.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox