Search in sources :

Example 6 with StatsProvider

use of com.facebook.presto.cost.StatsProvider in project presto by prestodb.

the class PlanAssert method assertPlan.

public static void assertPlan(Session session, Metadata metadata, StatsCalculator statsCalculator, Plan actual, PlanMatchPattern pattern) {
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, actual.getTypes());
    assertPlan(session, metadata, statsProvider, actual, noLookup(), pattern, Function.identity());
}
Also used : CachingStatsProvider(com.facebook.presto.cost.CachingStatsProvider) StatsProvider(com.facebook.presto.cost.StatsProvider) CachingStatsProvider(com.facebook.presto.cost.CachingStatsProvider)

Example 7 with StatsProvider

use of com.facebook.presto.cost.StatsProvider in project presto by prestodb.

the class RuleAssert method ruleContext.

private Rule.Context ruleContext(StatsCalculator statsCalculator, CostCalculator costCalculator, PlanVariableAllocator variableAllocator, Memo memo, Lookup lookup, Session session) {
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, Optional.of(memo), lookup, session, variableAllocator.getTypes());
    CostProvider costProvider = new CachingCostProvider(costCalculator, statsProvider, Optional.of(memo), session);
    return new Rule.Context() {

        @Override
        public Lookup getLookup() {
            return lookup;
        }

        @Override
        public PlanNodeIdAllocator getIdAllocator() {
            return idAllocator;
        }

        @Override
        public PlanVariableAllocator getVariableAllocator() {
            return variableAllocator;
        }

        @Override
        public Session getSession() {
            return session;
        }

        @Override
        public StatsProvider getStatsProvider() {
            return statsProvider;
        }

        @Override
        public CostProvider getCostProvider() {
            return costProvider;
        }

        @Override
        public void checkTimeoutNotExhausted() {
        }

        @Override
        public WarningCollector getWarningCollector() {
            return WarningCollector.NOOP;
        }
    };
}
Also used : CachingStatsProvider(com.facebook.presto.cost.CachingStatsProvider) CachingStatsProvider(com.facebook.presto.cost.CachingStatsProvider) StatsProvider(com.facebook.presto.cost.StatsProvider) CachingCostProvider(com.facebook.presto.cost.CachingCostProvider) CachingCostProvider(com.facebook.presto.cost.CachingCostProvider) CostProvider(com.facebook.presto.cost.CostProvider)

Example 8 with StatsProvider

use of com.facebook.presto.cost.StatsProvider in project presto by prestodb.

the class DetermineSemiJoinDistributionType method getSemiJoinNodeWithCost.

private PlanNodeWithCost getSemiJoinNodeWithCost(SemiJoinNode possibleJoinNode, Context context) {
    StatsProvider stats = context.getStatsProvider();
    boolean replicated = possibleJoinNode.getDistributionType().get().equals(REPLICATED);
    /*
         *   HACK!
         *
         *   Currently cost model always has to compute the total cost of an operation.
         *   For SEMI-JOIN the total cost consist of 4 parts:
         *     - Cost of exchanges that have to be introduced to execute a JOIN
         *     - Cost of building a hash table
         *     - Cost of probing a hash table
         *     - Cost of building an output for matched rows
         *
         *   When output size for a SEMI-JOIN cannot be estimated the cost model returns
         *   UNKNOWN cost for the join.
         *
         *   However assuming the cost of SEMI-JOIN output is always the same, we can still make
         *   cost based decisions based on the input cost for different types of SEMI-JOINs.
         *
         *   TODO Decision about the distribution should be based on LocalCostEstimate only when PlanCostEstimate cannot be calculated. Otherwise cost comparator cannot take query.max-memory into account.
         */
    int estimatedSourceDistributedTaskCount = taskCountEstimator.estimateSourceDistributedTaskCount();
    LocalCostEstimate cost = calculateJoinCostWithoutOutput(possibleJoinNode.getSource(), possibleJoinNode.getFilteringSource(), stats, replicated, estimatedSourceDistributedTaskCount);
    return new PlanNodeWithCost(cost.toPlanCost(), possibleJoinNode);
}
Also used : StatsProvider(com.facebook.presto.cost.StatsProvider) LocalCostEstimate(com.facebook.presto.cost.LocalCostEstimate)

Example 9 with StatsProvider

use of com.facebook.presto.cost.StatsProvider in project presto by prestodb.

the class DetermineJoinDistributionType method getJoinNodeWithCost.

private PlanNodeWithCost getJoinNodeWithCost(Context context, JoinNode possibleJoinNode) {
    StatsProvider stats = context.getStatsProvider();
    boolean replicated = possibleJoinNode.getDistributionType().get().equals(REPLICATED);
    /*
         *   HACK!
         *
         *   Currently cost model always has to compute the total cost of an operation.
         *   For JOIN the total cost consist of 4 parts:
         *     - Cost of exchanges that have to be introduced to execute a JOIN
         *     - Cost of building a hash table
         *     - Cost of probing a hash table
         *     - Cost of building an output for matched rows
         *
         *   When output size for a JOIN cannot be estimated the cost model returns
         *   UNKNOWN cost for the join.
         *
         *   However assuming the cost of JOIN output is always the same, we can still make
         *   cost based decisions based on the input cost for different types of JOINs.
         *
         *   Although the side flipping can be made purely based on stats (smaller side
         *   always goes to the right), determining JOIN type is not that simple. As when
         *   choosing REPLICATED over REPARTITIONED join the cost of exchanging and building
         *   the hash table scales with the number of nodes where the build side is replicated.
         *
         *   TODO Decision about the distribution should be based on LocalCostEstimate only when PlanCostEstimate cannot be calculated. Otherwise cost comparator cannot take query.max-memory into account.
         */
    int estimatedSourceDistributedTaskCount = taskCountEstimator.estimateSourceDistributedTaskCount();
    LocalCostEstimate cost = calculateJoinCostWithoutOutput(possibleJoinNode.getLeft(), possibleJoinNode.getRight(), stats, replicated, estimatedSourceDistributedTaskCount);
    return new PlanNodeWithCost(cost.toPlanCost(), possibleJoinNode);
}
Also used : StatsProvider(com.facebook.presto.cost.StatsProvider) LocalCostEstimate(com.facebook.presto.cost.LocalCostEstimate)

Example 10 with StatsProvider

use of com.facebook.presto.cost.StatsProvider in project presto by prestodb.

the class IterativeOptimizer method ruleContext.

private Rule.Context ruleContext(Context context) {
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, Optional.of(context.memo), context.lookup, context.session, context.variableAllocator.getTypes());
    CostProvider costProvider = new CachingCostProvider(costCalculator, statsProvider, Optional.of(context.memo), context.session);
    return new Rule.Context() {

        @Override
        public Lookup getLookup() {
            return context.lookup;
        }

        @Override
        public PlanNodeIdAllocator getIdAllocator() {
            return context.idAllocator;
        }

        @Override
        public PlanVariableAllocator getVariableAllocator() {
            return context.variableAllocator;
        }

        @Override
        public Session getSession() {
            return context.session;
        }

        @Override
        public StatsProvider getStatsProvider() {
            return statsProvider;
        }

        @Override
        public CostProvider getCostProvider() {
            return costProvider;
        }

        @Override
        public void checkTimeoutNotExhausted() {
            context.checkTimeoutNotExhausted();
        }

        @Override
        public WarningCollector getWarningCollector() {
            return context.warningCollector;
        }
    };
}
Also used : CachingStatsProvider(com.facebook.presto.cost.CachingStatsProvider) CachingStatsProvider(com.facebook.presto.cost.CachingStatsProvider) StatsProvider(com.facebook.presto.cost.StatsProvider) CachingCostProvider(com.facebook.presto.cost.CachingCostProvider) CachingCostProvider(com.facebook.presto.cost.CachingCostProvider) CostProvider(com.facebook.presto.cost.CostProvider)

Aggregations

StatsProvider (com.facebook.presto.cost.StatsProvider)16 Metadata (com.facebook.presto.metadata.Metadata)8 PlanNode (com.facebook.presto.spi.plan.PlanNode)8 List (java.util.List)8 Session (com.facebook.presto.Session)7 NO_MATCH (com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH)7 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)7 Preconditions.checkState (com.google.common.base.Preconditions.checkState)7 Objects.requireNonNull (java.util.Objects.requireNonNull)7 Optional (java.util.Optional)7 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)6 MatchResult.match (com.facebook.presto.sql.planner.assertions.MatchResult.match)6 CachingStatsProvider (com.facebook.presto.cost.CachingStatsProvider)5 Symbol (com.facebook.presto.sql.planner.Symbol)5 CachingCostProvider (com.facebook.presto.cost.CachingCostProvider)4 CostProvider (com.facebook.presto.cost.CostProvider)4 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)4 PlanMatchPattern.node (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node)3 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3