Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 64928 invoked from network); 29 Nov 2009 02:36:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Nov 2009 02:36:45 -0000 Received: (qmail 79743 invoked by uid 500); 29 Nov 2009 02:36:44 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 79634 invoked by uid 500); 29 Nov 2009 02:36:44 -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 79626 invoked by uid 99); 29 Nov 2009 02:36:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Nov 2009 02:36:44 +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; Sun, 29 Nov 2009 02:36:41 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id A770C234C052 for ; Sat, 28 Nov 2009 18:36:20 -0800 (PST) Message-ID: <1013293811.1259462180669.JavaMail.jira@brutus> Date: Sun, 29 Nov 2009 02:36:20 +0000 (UTC) From: "Dag H. Wanvik (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Updated: (DERBY-4405) Transformation to inner join not performed for certain three-way joins In-Reply-To: <229540704.1255347451313.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-4405?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dag H. Wanvik updated DERBY-4405: --------------------------------- Attachment: derby-4405.stat derby-4405.diff Uploading a patch which lets the two variant outer join statements be rewritten to inner join, by looking not just at the top level inner table for match when analyzing the null intolerant predicates, but checking against tables in nested inner join (inner join in the inner position of an outer join) as well. Added a repro test case to JoinNode which checks for the presence of a hash join to indicate the rewrite did happen (not used before the rewrite). Running regressions. > Transformation to inner join not performed for certain three-way joins > ---------------------------------------------------------------------- > > Key: DERBY-4405 > URL: https://issues.apache.org/jira/browse/DERBY-4405 > Project: Derby > Issue Type: Improvement > Components: SQL > Affects Versions: 10.6.0.0 > Reporter: Knut Anders Hatlen > Priority: Minor > Attachments: derby-4405.diff, derby-4405.stat > > > In the CROSS JOIN section in the reference manual (http://db.apache.org/derby/docs/dev/ref/rrefsqljcrossjoin.html) there are three examples that are supposed to be equivalent. However, the performance differs significantly between the different queries. > The queries use the tours db and look like this: > (1) > SELECT * FROM CITIES LEFT OUTER JOIN > (FLIGHTS CROSS JOIN COUNTRIES) > ON CITIES.AIRPORT = FLIGHTS.ORIG_AIRPORT > WHERE COUNTRIES.COUNTRY_ISO_CODE = 'US' > (2) > SELECT * FROM CITIES LEFT OUTER JOIN > FLIGHTS INNER JOIN COUNTRIES ON 1=1 > ON CITIES.AIRPORT = FLIGHTS.ORIG_AIRPORT > WHERE COUNTRIES.COUNTRY_ISO_CODE = 'US' > (3) > SELECT * FROM CITIES LEFT OUTER JOIN > (SELECT * FROM FLIGHTS, COUNTRIES) S > ON CITIES.AIRPORT = S.ORIG_AIRPORT > WHERE S.COUNTRY_ISO_CODE = 'US' > When executed in ij, (1) and (2) need 6 seconds to complete, whereas (3) completes in 50 ms. > The query plans for (1) and (2) use nested loop joins and table scans. (3) uses a combination of hash join and nested loop join, and index scans as well as table scans. > It looks like (3) has been rewritten from a left outer join to an inner join internally. This is fine because all rows that have the right-side columns filled with NULLs will be filtered out by the predicate S.COUNTRY_ISO_CODE='US', so the extra rows generated by the outer join will not be returned. > This optimization should also be possible for (1) and (2). We should improve the logic so that those joins are transformed too. The transformation happens in HalfOuterJoinNode.transformOuterJoins(). -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.