Search in sources :

Example 1 with CachingStatsProvider

use of io.prestosql.cost.CachingStatsProvider 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 CachingStatsProvider

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

the class TestJoinEnumerator method createContext.

private Rule.Context createContext() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    Map<Symbol, Type> symbols = new HashMap<>();
    symbols.put(new Symbol("A1"), BIGINT);
    symbols.put(new Symbol("B1"), BIGINT);
    PlanSymbolAllocator planSymbolAllocator = new PlanSymbolAllocator(symbols);
    CachingStatsProvider statsProvider = new CachingStatsProvider(queryRunner.getStatsCalculator(), Optional.empty(), noLookup(), queryRunner.getDefaultSession(), planSymbolAllocator.getTypes());
    CachingCostProvider costProvider = new CachingCostProvider(queryRunner.getCostCalculator(), statsProvider, Optional.empty(), queryRunner.getDefaultSession(), planSymbolAllocator.getTypes());
    return new Rule.Context() {

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

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

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

        @Override
        public Session getSession() {
            return queryRunner.getDefaultSession();
        }

        @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 : Type(io.prestosql.spi.type.Type) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) CachingCostProvider(io.prestosql.cost.CachingCostProvider) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator)

Example 3 with CachingStatsProvider

use of io.prestosql.cost.CachingStatsProvider 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 4 with CachingStatsProvider

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

the class RemoveUnsupportedDynamicFilters method optimize.

@Override
public PlanNode optimize(PlanNode plan, Session session, TypeProvider types, PlanSymbolAllocator planSymbolAllocator, PlanNodeIdAllocator idAllocator, WarningCollector warningCollector) {
    this.removedDynamicFilterIds = new HashSet<>();
    this.statsProvider = new CachingStatsProvider(statsCalculator, session, planSymbolAllocator.getTypes());
    PlanWithConsumedDynamicFilters result = plan.accept(new RemoveUnsupportedDynamicFilters.Rewriter(session, metadata, removedDynamicFilterIds), ImmutableSet.of());
    return SimplePlanRewriter.rewriteWith(new RemoveFilterVisitor(removedDynamicFilterIds, this.metadata), result.getNode(), null);
}
Also used : CachingStatsProvider(io.prestosql.cost.CachingStatsProvider)

Example 5 with CachingStatsProvider

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

the class PlanAssert method assertPlan.

public static void assertPlan(Session session, Metadata metadata, StatsCalculator statsCalculator, Plan actual, Lookup lookup, PlanMatchPattern pattern) {
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, actual.getTypes());
    assertPlan(session, metadata, statsProvider, actual, lookup, pattern);
}
Also used : CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) StatsProvider(io.prestosql.cost.StatsProvider) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider)

Aggregations

CachingStatsProvider (io.prestosql.cost.CachingStatsProvider)9 CachingCostProvider (io.prestosql.cost.CachingCostProvider)7 StatsProvider (io.prestosql.cost.StatsProvider)7 CostProvider (io.prestosql.cost.CostProvider)6 PlanNode (io.prestosql.spi.plan.PlanNode)3 SystemSessionProperties.isSkipAttachingStatsWithPlan (io.prestosql.SystemSessionProperties.isSkipAttachingStatsWithPlan)2 PlanOptimizer (io.prestosql.sql.planner.optimizations.PlanOptimizer)2 PlanNodeIdAllocator (io.prestosql.spi.plan.PlanNodeIdAllocator)1 Symbol (io.prestosql.spi.plan.Symbol)1 Type (io.prestosql.spi.type.Type)1 Plan (io.prestosql.sql.planner.Plan)1 PlanSymbolAllocator (io.prestosql.sql.planner.PlanSymbolAllocator)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 HashMap (java.util.HashMap)1