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)));
}
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;
}
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;
}
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;
}
Aggregations