Search in sources :

Example 1 with CostProvider

use of io.prestosql.cost.CostProvider in project hetu-core by openlookeng.

the class RuleAssert method ruleContext.

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

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

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

        @Override
        public PlanSymbolAllocator getSymbolAllocator() {
            return planSymbolAllocator;
        }

        @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(io.prestosql.cost.CachingStatsProvider) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) StatsProvider(io.prestosql.cost.StatsProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider) CostProvider(io.prestosql.cost.CostProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider)

Example 2 with CostProvider

use of io.prestosql.cost.CostProvider in project hetu-core by openlookeng.

the class HetuLogicalPlanner method plan.

@Override
public Plan plan(Analysis analysis, boolean skipStatsWithPlan, Stage stage) {
    PlanNode root = planStatement(analysis, analysis.getStatement());
    PlanNode.SkipOptRuleLevel optimizationLevel = APPLY_ALL_RULES;
    planSanityChecker.validateIntermediatePlan(root, session, metadata, typeAnalyzer, planSymbolAllocator.getTypes(), warningCollector);
    if (stage.ordinal() >= Stage.OPTIMIZED.ordinal()) {
        for (PlanOptimizer optimizer : planOptimizers) {
            if (OptimizerUtils.isEnabledLegacy(optimizer, session, root)) {
                // We run it separately in the SqlQueryExecution
                if (optimizer instanceof BeginTableWrite) {
                    continue;
                }
                if (OptimizerUtils.canApplyOptimizer(optimizer, optimizationLevel)) {
                    root = optimizer.optimize(root, session, planSymbolAllocator.getTypes(), planSymbolAllocator, idAllocator, warningCollector);
                    requireNonNull(root, format("%s returned a null plan", optimizer.getClass().getName()));
                    optimizationLevel = optimizationLevel == APPLY_ALL_RULES ? root.getSkipOptRuleLevel() : optimizationLevel;
                }
            }
        }
    }
    if (stage.ordinal() >= Stage.OPTIMIZED_AND_VALIDATED.ordinal()) {
        // make sure we produce a valid plan after optimizations run. This is mainly to catch programming errors
        planSanityChecker.validateFinalPlan(root, session, metadata, typeAnalyzer, planSymbolAllocator.getTypes(), warningCollector);
    }
    TypeProvider types = planSymbolAllocator.getTypes();
    // we calculate stats here only if need to show as part of EXPLAIN, otherwise not needed.
    if (skipStatsWithPlan && isSkipAttachingStatsWithPlan(session)) {
        return new Plan(root, types, StatsAndCosts.empty());
    } else {
        StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, types);
        CostProvider costProvider = new CachingCostProvider(costCalculator, statsProvider, Optional.empty(), session, types);
        return new Plan(root, types, StatsAndCosts.create(root, statsProvider, costProvider));
    }
}
Also used : PlanOptimizer(io.prestosql.sql.planner.optimizations.PlanOptimizer) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) PlanNode(io.prestosql.spi.plan.PlanNode) BeginTableWrite(io.prestosql.sql.planner.optimizations.BeginTableWrite) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) StatsProvider(io.prestosql.cost.StatsProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider) CostProvider(io.prestosql.cost.CostProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider) TypeProvider(io.prestosql.sql.planner.TypeProvider) Plan(io.prestosql.sql.planner.Plan) SystemSessionProperties.isSkipAttachingStatsWithPlan(io.prestosql.SystemSessionProperties.isSkipAttachingStatsWithPlan)

Example 3 with CostProvider

use of io.prestosql.cost.CostProvider in project hetu-core by openlookeng.

the class LogicalPlanner method plan.

public Plan plan(Analysis analysis, boolean skipStatsWithPlan, Stage stage) {
    PlanNode root = planStatement(analysis, analysis.getStatement());
    PlanNode.SkipOptRuleLevel optimizationLevel = APPLY_ALL_RULES;
    planSanityChecker.validateIntermediatePlan(root, session, metadata, typeAnalyzer, planSymbolAllocator.getTypes(), warningCollector);
    if (stage.ordinal() >= Stage.OPTIMIZED.ordinal()) {
        for (PlanOptimizer optimizer : planOptimizers) {
            if (OptimizerUtils.isEnabledLegacy(optimizer, session, root) && OptimizerUtils.canApplyOptimizer(optimizer, optimizationLevel)) {
                root = optimizer.optimize(root, session, planSymbolAllocator.getTypes(), planSymbolAllocator, idAllocator, warningCollector);
                requireNonNull(root, format("%s returned a null plan", optimizer.getClass().getName()));
                optimizationLevel = optimizationLevel == APPLY_ALL_RULES ? root.getSkipOptRuleLevel() : optimizationLevel;
            }
        }
    }
    if (stage.ordinal() >= Stage.OPTIMIZED_AND_VALIDATED.ordinal()) {
        // make sure we produce a valid plan after optimizations run. This is mainly to catch programming errors
        planSanityChecker.validateFinalPlan(root, session, metadata, typeAnalyzer, planSymbolAllocator.getTypes(), warningCollector);
    }
    TypeProvider types = planSymbolAllocator.getTypes();
    // we calculate stats here only if need to show as part of EXPLAIN, otherwise not needed.
    if (skipStatsWithPlan && isSkipAttachingStatsWithPlan(session)) {
        return new Plan(root, types, StatsAndCosts.empty());
    } else {
        StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, types);
        CostProvider costProvider = new CachingCostProvider(costCalculator, statsProvider, Optional.empty(), session, types);
        return new Plan(root, types, StatsAndCosts.create(root, statsProvider, costProvider));
    }
}
Also used : PlanOptimizer(io.prestosql.sql.planner.optimizations.PlanOptimizer) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) PlanNode(io.prestosql.spi.plan.PlanNode) StatsProvider(io.prestosql.cost.StatsProvider) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider) CostProvider(io.prestosql.cost.CostProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider) SystemSessionProperties.isSkipAttachingStatsWithPlan(io.prestosql.SystemSessionProperties.isSkipAttachingStatsWithPlan)

Example 4 with CostProvider

use of io.prestosql.cost.CostProvider in project hetu-core by openlookeng.

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.planSymbolAllocator.getTypes());
    CostProvider costProvider = new CachingCostProvider(costCalculator, statsProvider, Optional.of(context.memo), context.session, context.planSymbolAllocator.getTypes());
    return new Rule.Context() {

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

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

        @Override
        public PlanSymbolAllocator getSymbolAllocator() {
            return context.planSymbolAllocator;
        }

        @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(io.prestosql.cost.CachingStatsProvider) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) StatsProvider(io.prestosql.cost.StatsProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider) CostProvider(io.prestosql.cost.CostProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider)

Example 5 with CostProvider

use of io.prestosql.cost.CostProvider in project hetu-core by openlookeng.

the class PredicatePushDown method optimize.

@Override
public PlanNode optimize(PlanNode plan, Session session, TypeProvider types, PlanSymbolAllocator planSymbolAllocator, PlanNodeIdAllocator idAllocator, WarningCollector warningCollector) {
    requireNonNull(plan, "plan is null");
    requireNonNull(session, "session is null");
    requireNonNull(types, "types is null");
    requireNonNull(idAllocator, "idAllocator is null");
    RowExpressionPredicateExtractor predicateExtractor = new RowExpressionPredicateExtractor(new RowExpressionDomainTranslator(metadata), metadata, planSymbolAllocator, useTableProperties);
    Memo memo = new Memo(idAllocator, plan);
    Lookup lookup = Lookup.from(planNode -> Stream.of(memo.resolve(planNode)));
    StatsProvider statsProvider = new CachingStatsProvider(costCalculationHandle.getStatsCalculator(), Optional.of(memo), lookup, session, planSymbolAllocator.getTypes(), true);
    CostProvider costProvider = new CachingCostProvider(costCalculationHandle.getCostCalculator(), statsProvider, Optional.of(memo), session, planSymbolAllocator.getTypes());
    FilterPushdownForCTEHandler filterPushdownForCTEHandler = new FilterPushdownForCTEHandler(pushdownForCTE, costProvider, costCalculationHandle.getCostComparator());
    Rewriter rewriter = new Rewriter(planSymbolAllocator, idAllocator, metadata, predicateExtractor, typeAnalyzer, session, dynamicFiltering, filterPushdownForCTEHandler);
    PlanNode rewrittenNode = SimplePlanRewriter.rewriteWith(rewriter, plan, TRUE_CONSTANT);
    if (rewriter.isSecondTraverseRequired()) {
        return SimplePlanRewriter.rewriteWith(rewriter, rewrittenNode, TRUE_CONSTANT);
    }
    return rewrittenNode;
}
Also used : CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) PlanNode(io.prestosql.spi.plan.PlanNode) StatsProvider(io.prestosql.cost.StatsProvider) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider) RowExpressionDomainTranslator(io.prestosql.sql.relational.RowExpressionDomainTranslator) CostProvider(io.prestosql.cost.CostProvider) CachingCostProvider(io.prestosql.cost.CachingCostProvider) SimplePlanRewriter(io.prestosql.sql.planner.plan.SimplePlanRewriter) Lookup(io.prestosql.sql.planner.iterative.Lookup) Memo(io.prestosql.sql.planner.iterative.Memo) RowExpressionPredicateExtractor(io.prestosql.sql.planner.RowExpressionPredicateExtractor)

Aggregations

CachingCostProvider (io.prestosql.cost.CachingCostProvider)6 CachingStatsProvider (io.prestosql.cost.CachingStatsProvider)6 CostProvider (io.prestosql.cost.CostProvider)6 StatsProvider (io.prestosql.cost.StatsProvider)6 PlanNode (io.prestosql.spi.plan.PlanNode)3 SystemSessionProperties.isSkipAttachingStatsWithPlan (io.prestosql.SystemSessionProperties.isSkipAttachingStatsWithPlan)2 PlanOptimizer (io.prestosql.sql.planner.optimizations.PlanOptimizer)2 Plan (io.prestosql.sql.planner.Plan)1 RowExpressionPredicateExtractor (io.prestosql.sql.planner.RowExpressionPredicateExtractor)1 TypeProvider (io.prestosql.sql.planner.TypeProvider)1 Lookup (io.prestosql.sql.planner.iterative.Lookup)1 Memo (io.prestosql.sql.planner.iterative.Memo)1 BeginTableWrite (io.prestosql.sql.planner.optimizations.BeginTableWrite)1 SimplePlanRewriter (io.prestosql.sql.planner.plan.SimplePlanRewriter)1 RowExpressionDomainTranslator (io.prestosql.sql.relational.RowExpressionDomainTranslator)1