Search in sources :

Example 6 with PlanNodeIdAllocator

use of com.facebook.presto.sql.planner.PlanNodeIdAllocator 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();
}
Also used : StatsRecorder(com.facebook.presto.sql.planner.StatsRecorder) PlanNodeIdAllocator(com.facebook.presto.sql.planner.PlanNodeIdAllocator) PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) ImmutableSet(com.google.common.collect.ImmutableSet) Session(com.facebook.presto.Session) Set(java.util.Set) PrestoException(com.facebook.presto.spi.PrestoException) String.format(java.lang.String.format) Duration(io.airlift.units.Duration) Preconditions.checkState(com.google.common.base.Preconditions.checkState) OPTIMIZER_TIMEOUT(com.facebook.presto.spi.StandardErrorCode.OPTIMIZER_TIMEOUT) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) Symbol(com.facebook.presto.sql.planner.Symbol) Type(com.facebook.presto.spi.type.Type) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Map(java.util.Map) Optional(java.util.Optional) SymbolAllocator(com.facebook.presto.sql.planner.SymbolAllocator) SystemSessionProperties(com.facebook.presto.SystemSessionProperties) PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) Duration(io.airlift.units.Duration)

Aggregations

PlanNodeIdAllocator (com.facebook.presto.sql.planner.PlanNodeIdAllocator)6 SymbolAllocator (com.facebook.presto.sql.planner.SymbolAllocator)4 Symbol (com.facebook.presto.sql.planner.Symbol)3 LogicalPlanner (com.facebook.presto.sql.planner.LogicalPlanner)2 AggregationNode (com.facebook.presto.sql.planner.plan.AggregationNode)2 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)2 ValuesNode (com.facebook.presto.sql.planner.plan.ValuesNode)2 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Session (com.facebook.presto.Session)1 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)1 SqlQueryManager.unwrapExecuteStatement (com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement)1 Signature (com.facebook.presto.metadata.Signature)1 PrestoException (com.facebook.presto.spi.PrestoException)1 OPTIMIZER_TIMEOUT (com.facebook.presto.spi.StandardErrorCode.OPTIMIZER_TIMEOUT)1 Type (com.facebook.presto.spi.type.Type)1