Search in sources :

Example 1 with DecorrelatedNode

use of io.trino.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode in project trino by trinodb.

the class TransformCorrelatedJoinToJoin method apply.

@Override
public Result apply(CorrelatedJoinNode correlatedJoinNode, Captures captures, Context context) {
    checkArgument(correlatedJoinNode.getType() == INNER || correlatedJoinNode.getType() == LEFT, "correlation in %s JOIN", correlatedJoinNode.getType().name());
    PlanNode subquery = correlatedJoinNode.getSubquery();
    PlanNodeDecorrelator planNodeDecorrelator = new PlanNodeDecorrelator(plannerContext, context.getSymbolAllocator(), context.getLookup());
    Optional<DecorrelatedNode> decorrelatedNodeOptional = planNodeDecorrelator.decorrelateFilters(subquery, correlatedJoinNode.getCorrelation());
    if (decorrelatedNodeOptional.isEmpty()) {
        return Result.empty();
    }
    DecorrelatedNode decorrelatedSubquery = decorrelatedNodeOptional.get();
    Expression filter = combineConjuncts(plannerContext.getMetadata(), decorrelatedSubquery.getCorrelatedPredicates().orElse(TRUE_LITERAL), correlatedJoinNode.getFilter());
    return Result.ofPlanNode(new JoinNode(correlatedJoinNode.getId(), correlatedJoinNode.getType().toJoinNodeType(), correlatedJoinNode.getInput(), decorrelatedSubquery.getNode(), ImmutableList.of(), correlatedJoinNode.getInput().getOutputSymbols(), correlatedJoinNode.getSubquery().getOutputSymbols(), false, filter.equals(TRUE_LITERAL) ? Optional.empty() : Optional.of(filter), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(), Optional.empty()));
}
Also used : PlanNodeDecorrelator(io.trino.sql.planner.optimizations.PlanNodeDecorrelator) PlanNode(io.trino.sql.planner.plan.PlanNode) Expression(io.trino.sql.tree.Expression) CorrelatedJoinNode(io.trino.sql.planner.plan.CorrelatedJoinNode) JoinNode(io.trino.sql.planner.plan.JoinNode) DecorrelatedNode(io.trino.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode)

Aggregations

PlanNodeDecorrelator (io.trino.sql.planner.optimizations.PlanNodeDecorrelator)1 DecorrelatedNode (io.trino.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode)1 CorrelatedJoinNode (io.trino.sql.planner.plan.CorrelatedJoinNode)1 JoinNode (io.trino.sql.planner.plan.JoinNode)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1 Expression (io.trino.sql.tree.Expression)1