Return-Path: X-Original-To: apmail-db-derby-dev-archive@www.apache.org Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 72B17C438 for ; Tue, 10 Sep 2013 15:04:56 +0000 (UTC) Received: (qmail 14221 invoked by uid 500); 10 Sep 2013 15:04:56 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 14013 invoked by uid 500); 10 Sep 2013 15:04:53 -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 13690 invoked by uid 99); 10 Sep 2013 15:04:51 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Sep 2013 15:04:51 +0000 Date: Tue, 10 Sep 2013 15:04:51 +0000 (UTC) From: "ASF subversion and git services (JIRA)" To: derby-dev@db.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DERBY-6317) Optmizer can choose the wrong path when BTreeCostController.java returns an estimate cost and row count of 0.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DERBY-6317?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13763097#comment-13763097 ] ASF subversion and git services commented on DERBY-6317: -------------------------------------------------------- Commit 1521517 from mikem@apache.org in branch 'code/branches/10.10' [ https://svn.apache.org/r1521517 ] DERBY-6317 Optmizer can choose the wrong path when BTreeCostController.java returns an estimate cost and row count of 0.0 backported change #1521310 from trunk to 10.10 branch. The Optimizer estimates do not handle well 0 row counts coming out of store. These estimates end up getting multiplied by other estimates and the resulting 0 costs caused the incorrect plan to be picked in the repro included with this fix. This fix changes store cost to always return at least a minimum of one row when asked to estimate the number of rows in an exact range of keys from an index. This minimum is consistent with the optimizer assumption that an exact key match on a unique index will also return 1 row. Thanks to Brett Bergquist for debugging and suggesting a fix and to mamta satoor for providing a reproducible test case for the bug. > Optmizer can choose the wrong path when BTreeCostController.java returns an estimate cost and row count of 0.0 > -------------------------------------------------------------------------------------------------------------- > > Key: DERBY-6317 > URL: https://issues.apache.org/jira/browse/DERBY-6317 > Project: Derby > Issue Type: Bug > Components: SQL > Affects Versions: 10.8.2.2 > Environment: Derby 10.8.2.2 on Oracle Solaris 10 > Reporter: Brett Bergquist > Assignee: Mike Matrigali > Attachments: derby6317_2.diff, derby6317.diff, DERBY_6317_junit_test_v1_diff.txt, DERBY_6317_junit_test_v2_diff.txt, DERBY_6317_junit_test_v3_diff.txt, DERBY_6317_junit_test_v4_diff.txt, DERBY_6317_temp_changes_for_debugging.txt, testRepro_v1.txt > > > The optimizer can chose the wrong path when BTreeCostController.java returns an estimate cost and row count of 0.0. > Assume that you have two tables that are being joined like: > SELECT * FROM T1, T0 > WHERE T1.ID = T0.F_ID and > T0.ID = 3; > Also assume that T0 has two columns, ID and F_ID and F_ID is a foreign key on T1.ID. Assume that T1.ID is the primary key of T1 and (T0.F_ID, T0.ID) is the primary key on T0. Assume that there is a non-unique index on T0.ID. > The correct query plan for this should be to query T0 using the non-unique index on T0.ID and then use the foreign key value in those rows to do query T1 using the primary key on T1. > With some values of T0.ID in the above query this query plan is chosen and works. With other values of T0.ID , the query plan does an query on T0 using the non-unique index on T0.ID and then does a table scan on T1. > For example, in my case the query: > SELECT * FROM T1, T0 > WHERE T1.ID = T0.F_ID and > T0.ID = 22112129; > has this query plan. > The problem appears to be in BTreeCostController.java. When this returns the same value for the "left_of_start" and the "left_of_stop" (which is being used to estimate the number of rows and cost), then the estimate cost and row count becomes 0.0. When this is used in the join order of T0, T1, then the cost of the table scan for T1 becomes 0.0 as well. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira