Search in sources :

Example 1 with RuleStatsRecorder

use of com.facebook.presto.sql.planner.RuleStatsRecorder in project presto by prestodb.

the class TestMergeWindows method assertUnitPlan.

private void assertUnitPlan(@Language("SQL") String sql, PlanMatchPattern pattern) {
    List<PlanOptimizer> optimizers = ImmutableList.of(new UnaliasSymbolReferences(getMetadata().getFunctionAndTypeManager()), new IterativeOptimizer(new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getCostCalculator(), new TranslateExpressions(getQueryRunner().getMetadata(), new SqlParser()).rules()), new IterativeOptimizer(new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getEstimatedExchangesCostCalculator(), ImmutableSet.<Rule<?>>builder().add(new RemoveRedundantIdentityProjections()).addAll(GatherAndMergeWindows.rules()).build()), new PruneUnreferencedOutputs());
    assertPlan(sql, pattern, optimizers);
}
Also used : RuleStatsRecorder(com.facebook.presto.sql.planner.RuleStatsRecorder) RemoveRedundantIdentityProjections(com.facebook.presto.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) IterativeOptimizer(com.facebook.presto.sql.planner.iterative.IterativeOptimizer) SqlParser(com.facebook.presto.sql.parser.SqlParser) TranslateExpressions(com.facebook.presto.sql.planner.iterative.rule.TranslateExpressions)

Example 2 with RuleStatsRecorder

use of com.facebook.presto.sql.planner.RuleStatsRecorder in project presto by prestodb.

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());
    }
}
Also used : PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) RuleStatsRecorder(com.facebook.presto.sql.planner.RuleStatsRecorder) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Example 3 with RuleStatsRecorder

use of com.facebook.presto.sql.planner.RuleStatsRecorder in project presto by prestodb.

the class TestPlannerWarnings method createPlan.

private static Plan createPlan(LocalQueryRunner queryRunner, Session session, String sql, WarningCollector warningCollector, List<Rule<?>> rules) {
    // Warnings from testing rules will be added
    PlanOptimizer optimizer = new IterativeOptimizer(new RuleStatsRecorder(), queryRunner.getStatsCalculator(), queryRunner.getCostCalculator(), ImmutableSet.copyOf(rules));
    // Translate all OriginalExpression in planNodes to RowExpression so that we can do plan pattern asserting and printing on RowExpression only.
    PlanOptimizer expressionTranslator = new IterativeOptimizer(new RuleStatsRecorder(), queryRunner.getStatsCalculator(), queryRunner.getCostCalculator(), ImmutableSet.copyOf(new TranslateExpressions(queryRunner.getMetadata(), queryRunner.getSqlParser()).rules()));
    return queryRunner.createPlan(session, sql, ImmutableList.of(optimizer, expressionTranslator), LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, warningCollector);
}
Also used : PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) RuleStatsRecorder(com.facebook.presto.sql.planner.RuleStatsRecorder) IterativeOptimizer(com.facebook.presto.sql.planner.iterative.IterativeOptimizer) TranslateExpressions(com.facebook.presto.sql.planner.iterative.rule.TranslateExpressions)

Example 4 with RuleStatsRecorder

use of com.facebook.presto.sql.planner.RuleStatsRecorder in project presto by prestodb.

the class BasePlanTest method assertMinimallyOptimizedPlan.

protected void assertMinimallyOptimizedPlan(@Language("SQL") String sql, PlanMatchPattern pattern) {
    List<PlanOptimizer> optimizers = ImmutableList.of(new UnaliasSymbolReferences(queryRunner.getMetadata().getFunctionAndTypeManager()), new PruneUnreferencedOutputs(), new IterativeOptimizer(new RuleStatsRecorder(), queryRunner.getStatsCalculator(), queryRunner.getCostCalculator(), ImmutableSet.of(new RemoveRedundantIdentityProjections())), // To avoid assert plan failure not printing out plan (#12885)
    getExpressionTranslator());
    assertPlan(sql, queryRunner.getDefaultSession(), LogicalPlanner.Stage.OPTIMIZED, pattern, optimizers);
}
Also used : PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) RuleStatsRecorder(com.facebook.presto.sql.planner.RuleStatsRecorder) RemoveRedundantIdentityProjections(com.facebook.presto.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) PruneUnreferencedOutputs(com.facebook.presto.sql.planner.optimizations.PruneUnreferencedOutputs) IterativeOptimizer(com.facebook.presto.sql.planner.iterative.IterativeOptimizer) UnaliasSymbolReferences(com.facebook.presto.sql.planner.optimizations.UnaliasSymbolReferences)

Example 5 with RuleStatsRecorder

use of com.facebook.presto.sql.planner.RuleStatsRecorder in project presto by prestodb.

the class TestReorderWindows method assertUnitPlan.

private void assertUnitPlan(@Language("SQL") String sql, PlanMatchPattern pattern) {
    List<PlanOptimizer> optimizers = ImmutableList.of(new UnaliasSymbolReferences(getMetadata().getFunctionAndTypeManager()), new IterativeOptimizer(new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getCostCalculator(), new TranslateExpressions(getQueryRunner().getMetadata(), new SqlParser()).rules()), new PredicatePushDown(getMetadata(), getQueryRunner().getSqlParser()), new IterativeOptimizer(new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getEstimatedExchangesCostCalculator(), ImmutableSet.of(new RemoveRedundantIdentityProjections(), new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(0), new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(1), new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(2))), new PruneUnreferencedOutputs());
    assertPlan(sql, pattern, optimizers);
}
Also used : GatherAndMergeWindows(com.facebook.presto.sql.planner.iterative.rule.GatherAndMergeWindows) RuleStatsRecorder(com.facebook.presto.sql.planner.RuleStatsRecorder) RemoveRedundantIdentityProjections(com.facebook.presto.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) IterativeOptimizer(com.facebook.presto.sql.planner.iterative.IterativeOptimizer) SqlParser(com.facebook.presto.sql.parser.SqlParser) TranslateExpressions(com.facebook.presto.sql.planner.iterative.rule.TranslateExpressions)

Aggregations

RuleStatsRecorder (com.facebook.presto.sql.planner.RuleStatsRecorder)8 IterativeOptimizer (com.facebook.presto.sql.planner.iterative.IterativeOptimizer)7 RemoveRedundantIdentityProjections (com.facebook.presto.sql.planner.iterative.rule.RemoveRedundantIdentityProjections)6 TranslateExpressions (com.facebook.presto.sql.planner.iterative.rule.TranslateExpressions)5 SqlParser (com.facebook.presto.sql.parser.SqlParser)3 PlanOptimizer (com.facebook.presto.sql.planner.optimizations.PlanOptimizer)3 PrestoException (com.facebook.presto.spi.PrestoException)1 PartitioningProviderManager (com.facebook.presto.sql.planner.PartitioningProviderManager)1 GatherAndMergeWindows (com.facebook.presto.sql.planner.iterative.rule.GatherAndMergeWindows)1 MultipleDistinctAggregationToMarkDistinct (com.facebook.presto.sql.planner.iterative.rule.MultipleDistinctAggregationToMarkDistinct)1 SingleDistinctAggregationToGroupBy (com.facebook.presto.sql.planner.iterative.rule.SingleDistinctAggregationToGroupBy)1 PruneUnreferencedOutputs (com.facebook.presto.sql.planner.optimizations.PruneUnreferencedOutputs)1 UnaliasSymbolReferences (com.facebook.presto.sql.planner.optimizations.UnaliasSymbolReferences)1 Test (org.testng.annotations.Test)1