Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 48136 invoked from network); 21 Oct 2009 12:27:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Oct 2009 12:27:42 -0000 Received: (qmail 23726 invoked by uid 500); 21 Oct 2009 12:27:41 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 23652 invoked by uid 500); 21 Oct 2009 12:27:40 -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 23644 invoked by uid 99); 21 Oct 2009 12:27:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Oct 2009 12:27:40 +0000 X-ASF-Spam-Status: No, hits=-6.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [192.18.6.21] (HELO gmp-eb-inf-1.sun.com) (192.18.6.21) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Oct 2009 12:27:38 +0000 Received: from fe-emea-10.sun.com (gmp-eb-lb-1-fe1.eu.sun.com [192.18.6.7] (may be forged)) by gmp-eb-inf-1.sun.com (8.13.7+Sun/8.12.9) with ESMTP id n9LCRFR7023864 for ; Wed, 21 Oct 2009 12:27:15 GMT MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from conversion-daemon.fe-emea-10.sun.com by fe-emea-10.sun.com (Sun Java(tm) System Messaging Server 7u2-7.04 64bit (built Jul 2 2009)) id <0KRV00G0068WHM00@fe-emea-10.sun.com> for derby-user@db.apache.org; Wed, 21 Oct 2009 13:27:05 +0100 (BST) Received: from localhost ([unknown] [129.159.112.134]) by fe-emea-10.sun.com (Sun Java(tm) System Messaging Server 7u2-7.04 64bit (built Jul 2 2009)) with ESMTPSA id <0KRV00CCR6L4TKB0@fe-emea-10.sun.com> for derby-user@db.apache.org; Wed, 21 Oct 2009 13:27:04 +0100 (BST) Date: Wed, 21 Oct 2009 14:27:03 +0200 From: Knut Anders Hatlen Subject: Re: Badly performing WHERE caluse In-reply-to: <4ABA4AA0.2080001@amberpoint.com> Sender: Knut.Hatlen@Sun.COM To: Derby Discussion Message-id: Organization: Sun Microsystems References: <25531166.post@talk.nabble.com> <4ABA4AA0.2080001@amberpoint.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (usg-unix-v) Bryan Pendleton writes: >> Do people agree that this appears to be a bug with the query planner, as the >> selection of the most appropriate index should not be influenced by static >> conditions such as 1=1 or 2>1? > > I don't know of any reason why the 1=1 versus 2>1 should have affected the > query plan chosen. Sorry for the late response. I just came across some code in the engine that made me remember this thread. It looks like Derby doesn't treat 1=1 and 2>1 as boolean constants during optimization, so it takes the selectivity from the = operator and the > operator, respectively. The = operator has selectivity 0.1, and > has selectivity 0.33. This means that the optimizer thinks 1=1 will match 10% of the rows and 2>1 will match 33% of the rows. This is apparently enough to make the optimizer choose another plan in this case. Of course, both of the predicates will match 100% of the rows, so the the information that's given to the optimizer is inaccurate in any case. Logged here: https://issues.apache.org/jira/browse/DERBY-4416 -- Knut Anders