use of io.prestosql.sql.planner.optimizations.PlanOptimizer in project hetu-core by openlookeng.
the class BasePlanTest method assertMinimallyOptimizedPlan.
protected void assertMinimallyOptimizedPlan(@Language("SQL") String sql, PlanMatchPattern pattern) {
List<PlanOptimizer> optimizers = ImmutableList.of(new UnaliasSymbolReferences(queryRunner.getMetadata()), new PruneUnreferencedOutputs(), new IterativeOptimizer(new RuleStatsRecorder(), queryRunner.getStatsCalculator(), queryRunner.getCostCalculator(), ImmutableSet.of(new RemoveRedundantIdentityProjections())));
assertPlan(sql, LogicalPlanner.Stage.OPTIMIZED, pattern, optimizers);
}
use of io.prestosql.sql.planner.optimizations.PlanOptimizer 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));
}
}
use of io.prestosql.sql.planner.optimizations.PlanOptimizer in project hetu-core by openlookeng.
the class TestIterativeOptimizer method optimizerTimeoutsOnNonConvergingPlan.
@Test(timeOut = 1000)
public void optimizerTimeoutsOnNonConvergingPlan() {
PlanOptimizer optimizer = new IterativeOptimizer(new RuleStatsRecorder(), queryRunner.getStatsCalculator(), queryRunner.getCostCalculator(), ImmutableSet.of(new NonConvergingRule()));
try {
queryRunner.inTransaction(transactionSession -> {
queryRunner.createPlan(transactionSession, "SELECT * FROM nation", ImmutableList.of(optimizer), WarningCollector.NOOP);
fail("The optimizer should not converge");
return null;
});
} catch (PrestoException ex) {
assertEquals(ex.getErrorCode(), OPTIMIZER_TIMEOUT.toErrorCode());
}
}
use of io.prestosql.sql.planner.optimizations.PlanOptimizer 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));
}
}
use of io.prestosql.sql.planner.optimizations.PlanOptimizer in project hetu-core by openlookeng.
the class IterativeOptimizer method optimize.
@Override
public PlanNode optimize(PlanNode plan, Session session, TypeProvider types, PlanSymbolAllocator planSymbolAllocator, PlanNodeIdAllocator idAllocator, WarningCollector warningCollector) {
PlanNode tmpPlan = plan;
// only disable new rules if we have legacy rules to fall back to
if (!SystemSessionProperties.isNewOptimizerEnabled(session) && !legacyRules.isEmpty()) {
for (PlanOptimizer optimizer : legacyRules) {
if (OptimizerUtils.isEnabledLegacy(optimizer, session, tmpPlan)) {
tmpPlan = optimizer.optimize(tmpPlan, session, planSymbolAllocator.getTypes(), planSymbolAllocator, idAllocator, warningCollector);
}
}
return plan;
}
Memo memo = new Memo(idAllocator, plan);
Lookup lookup = Lookup.from(planNode -> Stream.of(memo.resolve(planNode)));
Duration timeout = SystemSessionProperties.getOptimizerTimeout(session);
Context context = new Context(memo, lookup, idAllocator, planSymbolAllocator, System.nanoTime(), timeout.toMillis(), session, warningCollector);
exploreGroup(memo.getRootGroup(), context);
return memo.extract();
}
Aggregations