Search in sources :

Example 1 with SubPlan

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

the class SqlQueryExecution method doPlanQuery.

private PlanRoot doPlanQuery() {
    // plan query
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    LogicalPlanner logicalPlanner = new LogicalPlanner(stateMachine.getSession(), planOptimizers, idAllocator, plannerContext, typeAnalyzer, statsCalculator, costCalculator, stateMachine.getWarningCollector());
    Plan plan = logicalPlanner.plan(analysis);
    queryPlan.set(plan);
    // fragment the plan
    SubPlan fragmentedPlan = planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, stateMachine.getWarningCollector());
    // extract inputs
    List<Input> inputs = new InputExtractor(plannerContext.getMetadata(), stateMachine.getSession()).extractInputs(fragmentedPlan);
    stateMachine.setInputs(inputs);
    stateMachine.setOutput(analysis.getTarget());
    boolean explainAnalyze = analysis.getStatement() instanceof ExplainAnalyze;
    return new PlanRoot(fragmentedPlan, !explainAnalyze);
}
Also used : LogicalPlanner(io.trino.sql.planner.LogicalPlanner) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) InputExtractor(io.trino.sql.planner.InputExtractor) SubPlan(io.trino.sql.planner.SubPlan) Plan(io.trino.sql.planner.Plan) SubPlan(io.trino.sql.planner.SubPlan)

Example 2 with SubPlan

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

the class TestCostCalculator method calculateCostFragmentedPlan.

private PlanCostEstimate calculateCostFragmentedPlan(PlanNode node, StatsCalculator statsCalculator, Map<String, Type> types) {
    TypeProvider typeProvider = TypeProvider.copyOf(types.entrySet().stream().collect(toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue)));
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, typeProvider);
    CostProvider costProvider = new CachingCostProvider(costCalculatorUsingExchanges, statsProvider, Optional.empty(), session, typeProvider);
    SubPlan subPlan = fragment(new Plan(node, typeProvider, StatsAndCosts.create(node, statsProvider, costProvider)));
    return subPlan.getFragment().getStatsAndCosts().getCosts().getOrDefault(node.getId(), PlanCostEstimate.unknown());
}
Also used : Symbol(io.trino.sql.planner.Symbol) TypeProvider(io.trino.sql.planner.TypeProvider) SubPlan(io.trino.sql.planner.SubPlan) Plan(io.trino.sql.planner.Plan) SubPlan(io.trino.sql.planner.SubPlan)

Example 3 with SubPlan

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

the class DynamicFilterService method registerQuery.

public void registerQuery(SqlQueryExecution sqlQueryExecution, SubPlan fragmentedPlan) {
    PlanNode queryPlan = sqlQueryExecution.getQueryPlan().getRoot();
    Set<DynamicFilterId> dynamicFilters = getProducedDynamicFilters(queryPlan);
    Set<DynamicFilterId> replicatedDynamicFilters = getReplicatedDynamicFilters(queryPlan);
    Set<DynamicFilterId> lazyDynamicFilters = fragmentedPlan.getAllFragments().stream().flatMap(plan -> getLazyDynamicFilters(plan).stream()).collect(toImmutableSet());
    // register query only if it contains dynamic filters
    if (!dynamicFilters.isEmpty()) {
        registerQuery(sqlQueryExecution.getQueryId(), sqlQueryExecution.getSession(), dynamicFilters, lazyDynamicFilters, replicatedDynamicFilters);
    }
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) QueryId(io.trino.spi.QueryId) PlanFragment(io.trino.sql.planner.PlanFragment) EMPTY(io.trino.spi.connector.DynamicFilter.EMPTY) Inject(com.google.inject.Inject) DynamicFilters.extractDynamicFilters(io.trino.sql.DynamicFilters.extractDynamicFilters) Duration.succinctNanos(io.airlift.units.Duration.succinctNanos) Domain.union(io.trino.spi.predicate.Domain.union) TypeOperators(io.trino.spi.type.TypeOperators) SettableFuture(com.google.common.util.concurrent.SettableFuture) Duration(io.airlift.units.Duration) PlanNode(io.trino.sql.planner.plan.PlanNode) PreDestroy(javax.annotation.PreDestroy) Sets.difference(com.google.common.collect.Sets.difference) HashMultimap(com.google.common.collect.HashMultimap) DynamicFilters.extractSourceSymbols(io.trino.sql.DynamicFilters.extractSourceSymbols) DynamicFilters(io.trino.sql.DynamicFilters) PlanNodeSearcher(io.trino.sql.planner.optimizations.PlanNodeSearcher) Map(java.util.Map) Sets.union(com.google.common.collect.Sets.union) ExpressionExtractor.extractExpressions(io.trino.sql.planner.ExpressionExtractor.extractExpressions) JoinNode(io.trino.sql.planner.plan.JoinNode) Functions.identity(com.google.common.base.Functions.identity) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Domain(io.trino.spi.predicate.Domain) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) TaskId(io.trino.execution.TaskId) JoinUtils(io.trino.operator.join.JoinUtils) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) SubPlan(io.trino.sql.planner.SubPlan) DynamicFilter(io.trino.spi.connector.DynamicFilter) Optional(java.util.Optional) MoreFutures.whenAnyComplete(io.airlift.concurrent.MoreFutures.whenAnyComplete) MoreFutures.unmodifiableFuture(io.airlift.concurrent.MoreFutures.unmodifiableFuture) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StageId(io.trino.execution.StageId) Type(io.trino.spi.type.Type) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Multimap(com.google.common.collect.Multimap) OptionalInt(java.util.OptionalInt) AtomicReference(java.util.concurrent.atomic.AtomicReference) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) DynamicFilterConfig(io.trino.execution.DynamicFilterConfig) ExecutorService(java.util.concurrent.ExecutorService) MoreFutures.toCompletableFuture(io.airlift.concurrent.MoreFutures.toCompletableFuture) Symbol(io.trino.sql.planner.Symbol) SqlQueryExecution(io.trino.execution.SqlQueryExecution) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) SetMultimap(com.google.common.collect.SetMultimap) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) FunctionManager(io.trino.metadata.FunctionManager) Consumer(java.util.function.Consumer) MorePredicates.isInstanceOfAny(io.trino.util.MorePredicates.isInstanceOfAny) Sets.intersection(com.google.common.collect.Sets.intersection) DomainCoercer.applySaturatedCasts(io.trino.sql.planner.DomainCoercer.applySaturatedCasts) SOURCE_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) Metadata(io.trino.metadata.Metadata) TypeProvider(io.trino.sql.planner.TypeProvider) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PlanNode(io.trino.sql.planner.plan.PlanNode) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId)

Example 4 with SubPlan

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

the class GraphvizPrinter method printSubPlan.

private static void printSubPlan(SubPlan plan, Map<PlanFragmentId, PlanFragment> fragmentsById, PlanNodeIdGenerator idGenerator, StringBuilder output) {
    PlanFragment fragment = plan.getFragment();
    printFragmentNodes(output, fragment, idGenerator);
    fragment.getRoot().accept(new EdgePrinter(output, fragmentsById, idGenerator), null);
    for (SubPlan child : plan.getChildren()) {
        printSubPlan(child, fragmentsById, idGenerator, output);
    }
}
Also used : PlanFragment(io.trino.sql.planner.PlanFragment) SubPlan(io.trino.sql.planner.SubPlan)

Example 5 with SubPlan

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

the class TestCostCalculator method assertCostFragmentedPlan.

private CostAssertionBuilder assertCostFragmentedPlan(PlanNode node, Map<String, PlanCostEstimate> costs, Map<String, PlanNodeStatsEstimate> stats, Map<String, Type> types) {
    TypeProvider typeProvider = TypeProvider.copyOf(types.entrySet().stream().collect(toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue)));
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator(stats), session, typeProvider);
    CostProvider costProvider = new TestingCostProvider(costs, costCalculatorUsingExchanges, statsProvider, session, typeProvider);
    SubPlan subPlan = fragment(new Plan(node, typeProvider, StatsAndCosts.create(node, statsProvider, costProvider)));
    return new CostAssertionBuilder(subPlan.getFragment().getStatsAndCosts().getCosts().getOrDefault(node.getId(), PlanCostEstimate.unknown()));
}
Also used : Symbol(io.trino.sql.planner.Symbol) TypeProvider(io.trino.sql.planner.TypeProvider) SubPlan(io.trino.sql.planner.SubPlan) Plan(io.trino.sql.planner.Plan) SubPlan(io.trino.sql.planner.SubPlan)

Aggregations

SubPlan (io.trino.sql.planner.SubPlan)6 Symbol (io.trino.sql.planner.Symbol)3 TypeProvider (io.trino.sql.planner.TypeProvider)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 DynamicFilterConfig (io.trino.execution.DynamicFilterConfig)2 Plan (io.trino.sql.planner.Plan)2 PlanFragment (io.trino.sql.planner.PlanFragment)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Functions.identity (com.google.common.base.Functions.identity)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1