db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brett Bergquist (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-6317) Optmizer can choose the wrong path when BTreeCostController.java returns an estimate cost and row count of 0.0
Date Wed, 28 Aug 2013 12:26:51 GMT

    [ https://issues.apache.org/jira/browse/DERBY-6317?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13752338#comment-13752338
] 

Brett Bergquist commented on DERBY-6317:
----------------------------------------

I have the patch applied and it fixes the estimated row cost.  

But if you look farther above, the estimated_row_count is computed from the ret_fraction (which
can end up as 0.0 if the left_of_start and left_of_stop are the same) and this is used in
computing the initial cost and later used in computed the cached_row_count which is also used
in computing the cost.

Might it not be useful to have the estimated_row_count be set to "1" when the ret_fraction
is 0.0 so that these other calculations are based the one row?  This is nearly what would
happen if in the example above with 48 million rows, that the left_of_start returned 0.07715294
and the left_of_stop returned 0.07715295, the estimated_row_count would be .48 rows.  That
way the cost does not become 0.0 when the left_of_start and left_of_stop are the same.


                
> 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
>         Attachments: derby6317.diff
>
>
> 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

Mime
View raw message