Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 82455 invoked from network); 14 Dec 2009 17:45:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Dec 2009 17:45:43 -0000 Received: (qmail 2596 invoked by uid 500); 14 Dec 2009 17:45:41 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 2552 invoked by uid 500); 14 Dec 2009 17:45:41 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 2490 invoked by uid 99); 14 Dec 2009 17:45:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2009 17:45:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2009 17:45:40 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id D174F29A0014 for ; Mon, 14 Dec 2009 09:45:18 -0800 (PST) Message-ID: <1479001823.1260812718856.JavaMail.jira@brutus> Date: Mon, 14 Dec 2009 17:45:18 +0000 (UTC) From: "Knut Anders Hatlen (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Commented: (DERBY-4471) Left outer join reassociation rewrite gives wrong result In-Reply-To: <152574259.1260578178109.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/DERBY-4471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790258#action_12790258 ] Knut Anders Hatlen commented on DERBY-4471: ------------------------------------------- I haven't studied the details, but at least PostgreSQL agrees with Dag that (a,NULL,NULL,NULL) is the correct result. > Left outer join reassociation rewrite gives wrong result > -------------------------------------------------------- > > Key: DERBY-4471 > URL: https://issues.apache.org/jira/browse/DERBY-4471 > Project: Derby > Issue Type: Bug > Components: SQL > Reporter: Dag H. Wanvik > > The following script and output shows the problem: > > create table r(c1 char(1)); > > create table s(c1 char(1), c2 char(1)); > > create table t(c1 char(1)); > > insert into r values 'a'; > > insert into s values ('b', default); > > insert into t values ('c'); > > select * from s left outer join t on s.c2=t.c1 or s.c2 is null; > C1 |C2 |C1 > -------------- > b |NULL|c > > select * from r left outer join s on r.c1=s.c1; > C1 |C1 |C2 > -------------- > a |NULL|NULL > > select * from (r left outer join s on r.c1=s.c1) left outer join t on s.c2=t.c1 or s.c2 is null; > C1 |C1 |C2 |C1 > ------------------- > a |NULL|NULL|c > > select * from r left outer join (s left outer join t on s.c2=t.c1 or s.c2 is null) on r.c1=s.c1; > C1 |C1 |C2 |C1 > ------------------- > a |NULL|NULL|c > The last result is wrong. The correct answer should be: > C1 |C1 |C2 |C1 > ------------------- > a |NULL|NULL|NULL > since in the last form, the left table r has the value 'a', which does > not match any row in result of the compound inner given the join > predicate ("r.c1=s.c1"), so all nulls should be appended to the 'a' > from the outer table r. > This happens because internally the last form is rewritten to the > second but the last form (left-deep), but this rewrite is not > justified here unless the join predicate on s rejects null, which the > present one explicitly does not ("or s.c2 is null"). Cf. for example > [1], page 52, which describes this transform and its prerequisite > condition as indentity #7. > [1] Galindo-Legaria, C. & Rosenthal, A.: "Outerjoin simplification and > reordering for query optimization", ACM Transactions on Database > Systems, Vol 22, No 1, March 1997. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.