Search in sources :

Example 1 with Memo

use of io.prestosql.sql.planner.iterative.Memo in project hetu-core by openlookeng.

the class RuleAssert method applyRule.

private RuleApplication applyRule() {
    PlanSymbolAllocator planSymbolAllocator = new PlanSymbolAllocator(types.allTypes());
    Memo memo = new Memo(idAllocator, plan);
    Lookup lookup = Lookup.from(planNode -> Stream.of(memo.resolve(planNode)));
    PlanNode memoRoot = memo.getNode(memo.getRootGroup());
    return inTransaction(session -> applyRule(rule, memoRoot, ruleContext(statsCalculator, costCalculator, planSymbolAllocator, memo, lookup, session)));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) Lookup(io.prestosql.sql.planner.iterative.Lookup) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) Memo(io.prestosql.sql.planner.iterative.Memo)

Example 2 with Memo

use of io.prestosql.sql.planner.iterative.Memo 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)

Example 3 with Memo

use of io.prestosql.sql.planner.iterative.Memo in project hetu-core by openlookeng.

the class CachingCostProvider method getGroupCost.

private PlanCostEstimate getGroupCost(GroupReference groupReference) {
    int group = groupReference.getGroupId();
    Memo tmpMemo = this.memo.orElseThrow(() -> new IllegalStateException("CachingCostProvider without memo cannot handle GroupReferences"));
    Optional<PlanCostEstimate> knownCost = tmpMemo.getCost(group);
    if (knownCost.isPresent()) {
        return knownCost.get();
    }
    PlanCostEstimate cost = calculateCost(tmpMemo.getNode(group));
    verify(!tmpMemo.getCost(group).isPresent(), "Group cost already set");
    tmpMemo.storeCost(group, cost);
    return cost;
}
Also used : Memo(io.prestosql.sql.planner.iterative.Memo)

Example 4 with Memo

use of io.prestosql.sql.planner.iterative.Memo in project hetu-core by openlookeng.

the class CachingStatsProvider method getGroupStats.

private PlanNodeStatsEstimate getGroupStats(GroupReference groupReference) {
    int group = groupReference.getGroupId();
    Memo tmpMemo = this.memo.orElseThrow(() -> new IllegalStateException("CachingStatsProvider without memo cannot handle GroupReferences"));
    Optional<PlanNodeStatsEstimate> stats = tmpMemo.getStats(group);
    if (stats.isPresent()) {
        return stats.get();
    }
    PlanNodeStatsEstimate groupStats = statsCalculator.calculateStats(tmpMemo.getNode(group), this, lookup, session, types);
    verify(!tmpMemo.getStats(group).isPresent(), "Group stats already set");
    tmpMemo.storeStats(group, groupStats);
    return groupStats;
}
Also used : Memo(io.prestosql.sql.planner.iterative.Memo)

Aggregations

Memo (io.prestosql.sql.planner.iterative.Memo)4 PlanNode (io.prestosql.spi.plan.PlanNode)2 Lookup (io.prestosql.sql.planner.iterative.Lookup)2 CachingCostProvider (io.prestosql.cost.CachingCostProvider)1 CachingStatsProvider (io.prestosql.cost.CachingStatsProvider)1 CostProvider (io.prestosql.cost.CostProvider)1 StatsProvider (io.prestosql.cost.StatsProvider)1 PlanSymbolAllocator (io.prestosql.sql.planner.PlanSymbolAllocator)1 RowExpressionPredicateExtractor (io.prestosql.sql.planner.RowExpressionPredicateExtractor)1 SimplePlanRewriter (io.prestosql.sql.planner.plan.SimplePlanRewriter)1 RowExpressionDomainTranslator (io.prestosql.sql.relational.RowExpressionDomainTranslator)1