Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 64700 invoked from network); 10 Jul 2010 23:10:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Jul 2010 23:10:13 -0000 Received: (qmail 165 invoked by uid 500); 10 Jul 2010 23:10:12 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 119 invoked by uid 500); 10 Jul 2010 23:10:12 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 112 invoked by uid 99); 10 Jul 2010 23:10:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Jul 2010 23:10:11 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [148.87.113.121] (HELO rcsinet10.oracle.com) (148.87.113.121) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Jul 2010 23:10:04 +0000 Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id o6AN9BTE002834 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 10 Jul 2010 23:09:12 GMT Received: from acsmt353.oracle.com (acsmt353.oracle.com [141.146.40.153]) by acsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o6A55Wsc030712 for ; Sat, 10 Jul 2010 23:09:11 GMT Received: from abhmt007.oracle.com by acsmt353.oracle.com with ESMTP id 394969711278803263; Sat, 10 Jul 2010 16:07:43 -0700 Received: from localhost (/89.11.157.219) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 10 Jul 2010 16:07:42 -0700 From: Knut Anders Hatlen To: "Derby Discussion" Subject: Re: Inconsistent SQLSyntaxErrorException (Hash join requires an optimizable equijoin predicate...) References: <2e954a49-d25e-4928-8f09-5c76154cf6b9@default> Date: Sun, 11 Jul 2010 01:08:19 +0200 In-Reply-To: <2e954a49-d25e-4928-8f09-5c76154cf6b9@default> (Charles Coates's message of "Thu, 8 Jul 2010 15:37:49 -0700 (PDT)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (usg-unix-v) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Source-IP: acsmt353.oracle.com [141.146.40.153] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090204.4C38FD97.0065:SCFMA4539814,ss=1,fgs=0 X-Virus-Checked: Checked by ClamAV on apache.org Hi Chuck, Please see my comments inline. Charles Coates writes: > I am using embedded Derby version 10.5.3.0_1. I am experiencing an > occasional SQLSytaxErrorException with the following error message: > > java.sql.SQLSyntaxErrorException: Hash join requires an optimizable > equijoin predicate on a column in the selected index or heap. An > optimizable equijoin predicate does not exist on any column in table > or index ''. Use the 'index' optimizer override to specify such an > index or the heap on table ''. This error means that Derby's optimizer has picked hash join as the strategy for a join that does not satisfy the requirements for a hash join, so it sounds very much like a bug in the optimizer. It would be good to have this problem logged in the bug tracker: https://issues.apache.org/jira/browse/DERBY > This happens when executing the following SQL statement: > > SELECT > parent_table.id, child_table.value [...] > > It appears that the inner_table query WHERE clause is the cause of the > problem. I think the error message is indicating that "sub_id = 'foo' > AND id LIKE '%%%'" is not optimizable. However, this exact query > works most of the time. And it always works when using a SQL client > tool (like SQirreL SQL Client). It will only fail occasionally when > executed via JDBC within a java application. You may force that part of the query to use a nested loop join instead of a hash join by adding an optimizer override in a comment. Something like this should do the trick: ... ) AS inner_table -- DERBY-PROPERTIES joinStrategy=NESTEDLOOP ON ... > Does anyone have any ideas what could be causing this? Any ideas on > possible modifications to the query that would avoid this error and > still accomplish the same results? If you had been using Derby 10.6, you could have replaced the query in the inner table with a simpler SELECT statement that used OFFSET/FETCH NEXT instead of the nested query with ROW_NUMBER(). (Derby 10.5 doesn't support OFFSET/FETCH NEXT in a sub-query.) I don't know if this would help avoiding the error, but it would make the query less complicated, so it might make it easier for the optimizer to do the right thing. Another thing is that the ROW_NUMBER() implementation was more or less completely rewritten in Derby 10.6 to address some bugs, so perhaps 10.6 would handle this query differently. These are of course only guesses as long as we haven't established the root cause of the problem. -- Knut Anders