use of com.facebook.presto.sql.planner.optimizations.PlanOptimizer in project presto by prestodb.
the class TestIterativeOptimizer method optimizerTimeoutsOnNonConvergingPlan.
@Test(timeOut = 1000)
public void optimizerTimeoutsOnNonConvergingPlan() {
PlanOptimizer optimizer = new IterativeOptimizer(new StatsRecorder(), ImmutableSet.of(new NonConvergingRule()));
try {
queryRunner.inTransaction(transactionSession -> {
queryRunner.createPlan(transactionSession, "SELECT * FROM nation", ImmutableList.of(optimizer));
fail("The optimizer should not converge");
return null;
});
} catch (PrestoException ex) {
assertEquals(ex.getErrorCode(), OPTIMIZER_TIMEOUT.toErrorCode());
}
}
use of com.facebook.presto.sql.planner.optimizations.PlanOptimizer in project presto by prestodb.
the class LogicalPlanner method plan.
public Plan plan(Analysis analysis, Stage stage) {
PlanNode root = planStatement(analysis, analysis.getStatement());
if (stage.ordinal() >= Stage.OPTIMIZED.ordinal()) {
for (PlanOptimizer optimizer : planOptimizers) {
root = optimizer.optimize(root, session, symbolAllocator.getTypes(), symbolAllocator, idAllocator);
requireNonNull(root, format("%s returned a null plan", optimizer.getClass().getName()));
}
}
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.validate(root, session, metadata, sqlParser, symbolAllocator.getTypes());
}
return new Plan(root, symbolAllocator);
}
use of com.facebook.presto.sql.planner.optimizations.PlanOptimizer in project presto by prestodb.
the class IterativeOptimizer method optimize.
@Override
public PlanNode optimize(PlanNode plan, Session session, Map<Symbol, Type> types, SymbolAllocator symbolAllocator, PlanNodeIdAllocator idAllocator) {
if (!SystemSessionProperties.isNewOptimizerEnabled(session)) {
for (PlanOptimizer optimizer : legacyRules) {
plan = optimizer.optimize(plan, session, symbolAllocator.getTypes(), symbolAllocator, idAllocator);
}
return plan;
}
Memo memo = new Memo(idAllocator, plan);
Lookup lookup = node -> {
if (node instanceof GroupReference) {
return memo.getNode(((GroupReference) node).getGroupId());
}
return node;
};
Duration timeout = SystemSessionProperties.getOptimizerTimeout(session);
exploreGroup(memo.getRootGroup(), new Context(memo, lookup, idAllocator, symbolAllocator, System.nanoTime(), timeout.toMillis()));
return memo.extract();
}
use of com.facebook.presto.sql.planner.optimizations.PlanOptimizer in project presto by prestodb.
the class BasePlanTest method assertMinimallyOptimizedPlan.
protected void assertMinimallyOptimizedPlan(@Language("SQL") String sql, PlanMatchPattern pattern) {
LocalQueryRunner queryRunner = getQueryRunner();
List<PlanOptimizer> optimizers = ImmutableList.of(new UnaliasSymbolReferences(), new PruneUnreferencedOutputs(), new PruneIdentityProjections());
queryRunner.inTransaction(transactionSession -> {
Plan actualPlan = queryRunner.createPlan(transactionSession, sql, optimizers, LogicalPlanner.Stage.OPTIMIZED);
PlanAssert.assertPlan(transactionSession, queryRunner.getMetadata(), actualPlan, pattern);
return null;
});
}
use of com.facebook.presto.sql.planner.optimizations.PlanOptimizer in project presto by prestodb.
the class AbstractTestQueryFramework method getQueryExplainer.
private QueryExplainer getQueryExplainer() {
Metadata metadata = queryRunner.getMetadata();
FeaturesConfig featuresConfig = new FeaturesConfig().setOptimizeHashGeneration(true);
boolean forceSingleNode = queryRunner.getNodeCount() == 1;
List<PlanOptimizer> optimizers = new PlanOptimizers(metadata, sqlParser, featuresConfig, forceSingleNode, new MBeanExporter(new TestingMBeanServer())).get();
return new QueryExplainer(optimizers, metadata, queryRunner.getAccessControl(), sqlParser, ImmutableMap.of());
}
Aggregations