phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From katameru <...@git.apache.org>
Subject [GitHub] phoenix pull request #281: PHOENIX-4288 Indexes not used when ordering by pr...
Date Fri, 17 Nov 2017 07:52:41 GMT
Github user katameru commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/281#discussion_r151620890
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java ---
    @@ -91,8 +91,23 @@ public QueryPlan optimize(PhoenixStatement statement, SelectStatement
select, Co
         }
         
         public QueryPlan optimize(QueryPlan dataPlan, PhoenixStatement statement, List<?
extends PDatum> targetColumns, ParallelIteratorFactory parallelIteratorFactory) throws
SQLException {
    -        List<QueryPlan>plans = getApplicablePlans(dataPlan, statement, targetColumns,
parallelIteratorFactory, true);
    -        return plans.get(0);
    +        List<QueryPlan> plans = getApplicablePlans(dataPlan, statement, targetColumns,
parallelIteratorFactory, false);
    +        if (plans.size() == 1) {
    +            return plans.get(0);
    +        }
    +
    +        // Get the best plan based on their costs. Costs will be ZERO if stats are not
    +        // available, thus the first plan will be returned.
    +        Cost minCost = null;
    +        QueryPlan bestPlan = null;
    +        for (QueryPlan plan : plans) {
    +            Cost cost = plan.getCost();
    +            if (minCost == null || cost.compareTo(minCost) < 0) {
    +                minCost = cost;
    +                bestPlan = plan;
    +            }
    +        }
    +        return bestPlan;
    --- End diff --
    
    I'd argue that the observable behavior should stay the same, so a hinted query plan should
be used above all others. Currently we could just sidestep the cost calculations in favor
of a hinted plan, but I think that having a way to influence the optimizer via hints could
be very useful.


---

Mime
View raw message