Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 00D19200CA9 for ; Fri, 16 Jun 2017 19:55:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id F3A69160BDD; Fri, 16 Jun 2017 17:55:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 466E5160BC0 for ; Fri, 16 Jun 2017 19:55:09 +0200 (CEST) Received: (qmail 52381 invoked by uid 500); 16 Jun 2017 17:55:08 -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 52371 invoked by uid 99); 16 Jun 2017 17:55:08 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Jun 2017 17:55:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id EBEB31810D9 for ; Fri, 16 Jun 2017 17:55:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id MvLzmLhTtYf2 for ; Fri, 16 Jun 2017 17:55:07 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 128C35F6BF for ; Fri, 16 Jun 2017 17:55:06 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 987EBE0383 for ; Fri, 16 Jun 2017 17:55:04 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 8F07D23FFE for ; Fri, 16 Jun 2017 17:55:01 +0000 (UTC) Date: Fri, 16 Jun 2017 17:55:01 +0000 (UTC) From: "Sergey Shelukhin (JIRA)" To: derby-dev@db.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DERBY-6358) WHERE clause should be evaluated after the joins in the FROM clause MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 16 Jun 2017 17:55:10 -0000 [ https://issues.apache.org/jira/browse/DERBY-6358?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16052190#comment-16052190 ] Sergey Shelukhin commented on DERBY-6358: ----------------------------------------- from clause appears to include joins as per 7.6 (I am not reading this with a lot of attention right now :)). So, the clauses should be applied to the result of the join, at least logically. > WHERE clause should be evaluated after the joins in the FROM clause > ------------------------------------------------------------------- > > Key: DERBY-6358 > URL: https://issues.apache.org/jira/browse/DERBY-6358 > Project: Derby > Issue Type: Bug > Components: SQL > Affects Versions: 10.2.2.1, 10.10.2.0, 10.11.1.1 > Reporter: Rick Hillegas > > The WHERE clause is supposed to be evaluated after the inner and outer joins specified in the FROM clause. See part 2 of the SQL Standard, section 7.4 (), general rule 1. However, it appears that Derby flattens the inner joins into a cartesian product and mixes their ON clauses into the WHERE clause. As a result, WHERE clause fragments can be evaluated before the ON clauses. The following script shows this problem: > connect 'jdbc:derby:memory:db;create=true'; > create table t1( a varchar( 10 ) ); > create table t2( a varchar( 10 ) ); > insert into t1( a ) values ( 'horse' ), ( 'apple' ), ( 'star' ), ( '6' ); > insert into t2( a ) values ( '6' ); > -- ok if the cast is performed in the select list > select cast( t1.a as int ) > from t1 inner join t2 on t1.a = t2.a; > -- should succeed. > -- but we see a casting error because the WHERE clause is evaluated before the ON clause > select * > from t1 inner join t2 on t1.a = t2.a > where cast( t1.a as int ) > 5; > Fixing this bug may result in serious performance degradation for many queries. A release note will be needed to tell users how to re-write their queries in order to get the old performance. For instance, the user may need to flatten the inner joins themselves, rewriting the query as a cartesian product with a WHERE clause. -- This message was sent by Atlassian JIRA (v6.4.14#64029)