Search in sources :

Example 1 with RuleStatsRecorder

use of io.trino.sql.planner.RuleStatsRecorder in project trino by trinodb.

the class TestIterativeOptimizer method optimizerTimeoutsOnNonConvergingPlan.

@Test(timeOut = 10_000)
public void optimizerTimeoutsOnNonConvergingPlan() {
    PlanOptimizer optimizer = new IterativeOptimizer(queryRunner.getPlannerContext(), new RuleStatsRecorder(), queryRunner.getStatsCalculator(), queryRunner.getCostCalculator(), ImmutableSet.of(new AddIdentityOverTableScan(), new RemoveRedundantIdentityProjections()));
    assertTrinoExceptionThrownBy(() -> queryRunner.inTransaction(transactionSession -> queryRunner.createPlan(transactionSession, "SELECT nationkey FROM nation", ImmutableList.of(optimizer), WarningCollector.NOOP))).hasErrorCode(OPTIMIZER_TIMEOUT).hasMessageMatching("The optimizer exhausted the time limit of 1 ms: (no rules invoked|(?s)Top rules:.*(RemoveRedundantIdentityProjections|AddIdentityOverTableScan).*)");
}
Also used : AfterClass(org.testng.annotations.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) RemoveRedundantIdentityProjections(io.trino.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) Assignments(io.trino.sql.planner.plan.Assignments) Test(org.testng.annotations.Test) Patterns.tableScan(io.trino.sql.planner.plan.Patterns.tableScan) TrinoExceptionAssert.assertTrinoExceptionThrownBy(io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy) RuleStatsRecorder(io.trino.sql.planner.RuleStatsRecorder) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) Pattern(io.trino.matching.Pattern) ImmutableList(com.google.common.collect.ImmutableList) Captures(io.trino.matching.Captures) TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) LocalQueryRunner(io.trino.testing.LocalQueryRunner) WarningCollector(io.trino.execution.warnings.WarningCollector) ProjectNode(io.trino.sql.planner.plan.ProjectNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) OPTIMIZER_TIMEOUT(io.trino.spi.StandardErrorCode.OPTIMIZER_TIMEOUT) Session(io.trino.Session) PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) RuleStatsRecorder(io.trino.sql.planner.RuleStatsRecorder) RemoveRedundantIdentityProjections(io.trino.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) Test(org.testng.annotations.Test)

Example 2 with RuleStatsRecorder

use of io.trino.sql.planner.RuleStatsRecorder in project trino by trinodb.

the class TestOptimizeMixedDistinctAggregations method assertUnitPlan.

private void assertUnitPlan(String sql, PlanMatchPattern pattern) {
    List<PlanOptimizer> optimizers = ImmutableList.of(new UnaliasSymbolReferences(getQueryRunner().getMetadata()), new IterativeOptimizer(getQueryRunner().getPlannerContext(), new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getEstimatedExchangesCostCalculator(), ImmutableSet.of(new RemoveRedundantIdentityProjections(), new SingleDistinctAggregationToGroupBy(), new MultipleDistinctAggregationToMarkDistinct())), new OptimizeMixedDistinctAggregations(getQueryRunner().getMetadata()), new IterativeOptimizer(getQueryRunner().getPlannerContext(), new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getEstimatedExchangesCostCalculator(), ImmutableSet.<Rule<?>>builder().add(new RemoveRedundantIdentityProjections()).addAll(columnPruningRules(getQueryRunner().getMetadata())).build()));
    assertPlan(sql, pattern, optimizers);
}
Also used : RuleStatsRecorder(io.trino.sql.planner.RuleStatsRecorder) RemoveRedundantIdentityProjections(io.trino.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) MultipleDistinctAggregationToMarkDistinct(io.trino.sql.planner.iterative.rule.MultipleDistinctAggregationToMarkDistinct) IterativeOptimizer(io.trino.sql.planner.iterative.IterativeOptimizer) SingleDistinctAggregationToGroupBy(io.trino.sql.planner.iterative.rule.SingleDistinctAggregationToGroupBy)

Example 3 with RuleStatsRecorder

use of io.trino.sql.planner.RuleStatsRecorder in project trino by trinodb.

the class TestEliminateSorts method assertUnitPlan.

private void assertUnitPlan(@Language("SQL") String sql, PlanMatchPattern pattern) {
    TypeAnalyzer typeAnalyzer = createTestingTypeAnalyzer(getQueryRunner().getPlannerContext());
    List<PlanOptimizer> optimizers = ImmutableList.of(new IterativeOptimizer(getQueryRunner().getPlannerContext(), new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getCostCalculator(), ImmutableSet.of(new RemoveRedundantIdentityProjections(), new DetermineTableScanNodePartitioning(getQueryRunner().getMetadata(), getQueryRunner().getNodePartitioningManager(), new TaskCountEstimator(() -> 10)))), new AddExchanges(getQueryRunner().getPlannerContext(), typeAnalyzer, getQueryRunner().getStatsCalculator()));
    assertPlan(sql, pattern, optimizers);
}
Also used : TaskCountEstimator(io.trino.cost.TaskCountEstimator) RuleStatsRecorder(io.trino.sql.planner.RuleStatsRecorder) RemoveRedundantIdentityProjections(io.trino.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) IterativeOptimizer(io.trino.sql.planner.iterative.IterativeOptimizer) DetermineTableScanNodePartitioning(io.trino.sql.planner.iterative.rule.DetermineTableScanNodePartitioning) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer)

Example 4 with RuleStatsRecorder

use of io.trino.sql.planner.RuleStatsRecorder in project trino by trinodb.

the class TestSetFlattening method assertPlan.

@Override
protected void assertPlan(String sql, PlanMatchPattern pattern) {
    List<PlanOptimizer> optimizers = ImmutableList.of(new UnaliasSymbolReferences(getQueryRunner().getMetadata()), new IterativeOptimizer(getQueryRunner().getPlannerContext(), new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getEstimatedExchangesCostCalculator(), ImmutableSet.<Rule<?>>builder().add(new RemoveRedundantIdentityProjections()).add(new MergeUnion()).add(new MergeIntersect()).add(new MergeExcept()).add(new PruneDistinctAggregation()).addAll(columnPruningRules(getQueryRunner().getMetadata())).build()));
    assertPlan(sql, pattern, optimizers);
}
Also used : MergeExcept(io.trino.sql.planner.iterative.rule.MergeExcept) RuleStatsRecorder(io.trino.sql.planner.RuleStatsRecorder) RemoveRedundantIdentityProjections(io.trino.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) PruneDistinctAggregation(io.trino.sql.planner.iterative.rule.PruneDistinctAggregation) IterativeOptimizer(io.trino.sql.planner.iterative.IterativeOptimizer) MergeIntersect(io.trino.sql.planner.iterative.rule.MergeIntersect) MergeUnion(io.trino.sql.planner.iterative.rule.MergeUnion)

Example 5 with RuleStatsRecorder

use of io.trino.sql.planner.RuleStatsRecorder in project trino by trinodb.

the class TestMergeWindows method assertUnitPlan.

private void assertUnitPlan(@Language("SQL") String sql, PlanMatchPattern pattern) {
    List<PlanOptimizer> optimizers = ImmutableList.of(new UnaliasSymbolReferences(getQueryRunner().getMetadata()), new IterativeOptimizer(getQueryRunner().getPlannerContext(), new RuleStatsRecorder(), getQueryRunner().getStatsCalculator(), getQueryRunner().getEstimatedExchangesCostCalculator(), ImmutableSet.<Rule<?>>builder().add(new RemoveRedundantIdentityProjections()).addAll(GatherAndMergeWindows.rules()).addAll(columnPruningRules(getQueryRunner().getMetadata())).build()));
    assertPlan(sql, pattern, optimizers);
}
Also used : RuleStatsRecorder(io.trino.sql.planner.RuleStatsRecorder) RemoveRedundantIdentityProjections(io.trino.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) IterativeOptimizer(io.trino.sql.planner.iterative.IterativeOptimizer) Rule(io.trino.sql.planner.iterative.Rule)

Aggregations

RuleStatsRecorder (io.trino.sql.planner.RuleStatsRecorder)7 RemoveRedundantIdentityProjections (io.trino.sql.planner.iterative.rule.RemoveRedundantIdentityProjections)7 IterativeOptimizer (io.trino.sql.planner.iterative.IterativeOptimizer)6 Rule (io.trino.sql.planner.iterative.Rule)2 PlanOptimizer (io.trino.sql.planner.optimizations.PlanOptimizer)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Session (io.trino.Session)1 TaskCountEstimator (io.trino.cost.TaskCountEstimator)1 WarningCollector (io.trino.execution.warnings.WarningCollector)1 Captures (io.trino.matching.Captures)1 Pattern (io.trino.matching.Pattern)1 TpchConnectorFactory (io.trino.plugin.tpch.TpchConnectorFactory)1 OPTIMIZER_TIMEOUT (io.trino.spi.StandardErrorCode.OPTIMIZER_TIMEOUT)1 TypeAnalyzer (io.trino.sql.planner.TypeAnalyzer)1 TypeAnalyzer.createTestingTypeAnalyzer (io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer)1 DetermineTableScanNodePartitioning (io.trino.sql.planner.iterative.rule.DetermineTableScanNodePartitioning)1 GatherAndMergeWindows (io.trino.sql.planner.iterative.rule.GatherAndMergeWindows)1 MergeExcept (io.trino.sql.planner.iterative.rule.MergeExcept)1