X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9DDE752818 for ; Wed, 6 Jul 2005 11:44:15 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 94998-03 for ; Wed, 6 Jul 2005 14:44:10 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4AC615280B for ; Wed, 6 Jul 2005 11:44:10 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j66EiE7c026226; Wed, 6 Jul 2005 10:44:14 -0400 (EDT) To: "Grant Morgan" Cc: pgsql-sql@postgresql.org Subject: Re: left joins In-reply-to: References: Comments: In-reply-to "Grant Morgan" message dated "Wed, 06 Jul 2005 19:01:54 +0900" Date: Wed, 06 Jul 2005 10:44:14 -0400 Message-ID: <26225.1120661054@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/34 X-Sequence-Number: 22012 "Grant Morgan" 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