Search in sources :

Example 1 with UNKNOWN_FILTER_COEFFICIENT

use of io.trino.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT in project trino by trinodb.

the class SimpleFilterProjectSemiJoinStatsRule method calculate.

private Optional<PlanNodeStatsEstimate> calculate(FilterNode filterNode, SemiJoinNode semiJoinNode, StatsProvider statsProvider, Session session, TypeProvider types) {
    PlanNodeStatsEstimate sourceStats = statsProvider.getStats(semiJoinNode.getSource());
    PlanNodeStatsEstimate filteringSourceStats = statsProvider.getStats(semiJoinNode.getFilteringSource());
    Symbol filteringSourceJoinSymbol = semiJoinNode.getFilteringSourceJoinSymbol();
    Symbol sourceJoinSymbol = semiJoinNode.getSourceJoinSymbol();
    Optional<SemiJoinOutputFilter> semiJoinOutputFilter = extractSemiJoinOutputFilter(filterNode.getPredicate(), semiJoinNode.getSemiJoinOutput());
    if (semiJoinOutputFilter.isEmpty()) {
        return Optional.empty();
    }
    PlanNodeStatsEstimate semiJoinStats;
    if (semiJoinOutputFilter.get().isNegated()) {
        semiJoinStats = computeAntiJoin(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol);
    } else {
        semiJoinStats = computeSemiJoin(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol);
    }
    if (semiJoinStats.isOutputRowCountUnknown()) {
        return Optional.of(PlanNodeStatsEstimate.unknown());
    }
    // apply remaining predicate
    PlanNodeStatsEstimate filteredStats = filterStatsCalculator.filterStats(semiJoinStats, semiJoinOutputFilter.get().getRemainingPredicate(), session, types);
    if (filteredStats.isOutputRowCountUnknown()) {
        return Optional.of(semiJoinStats.mapOutputRowCount(rowCount -> rowCount * UNKNOWN_FILTER_COEFFICIENT));
    }
    return Optional.of(filteredStats);
}
Also used : Symbol(io.trino.sql.planner.Symbol) Iterables(com.google.common.collect.Iterables) Lookup(io.trino.sql.planner.iterative.Lookup) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Patterns.filter(io.trino.sql.planner.plan.Patterns.filter) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) UNKNOWN_FILTER_COEFFICIENT(io.trino.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanNode(io.trino.sql.planner.plan.PlanNode) SemiJoinStatsCalculator.computeSemiJoin(io.trino.cost.SemiJoinStatsCalculator.computeSemiJoin) List(java.util.List) Pattern(io.trino.matching.Pattern) SymbolReference(io.trino.sql.tree.SymbolReference) SemiJoinStatsCalculator.computeAntiJoin(io.trino.cost.SemiJoinStatsCalculator.computeAntiJoin) NotExpression(io.trino.sql.tree.NotExpression) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) TypeProvider(io.trino.sql.planner.TypeProvider) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) ExpressionUtils.extractConjuncts(io.trino.sql.ExpressionUtils.extractConjuncts) ExpressionUtils.combineConjuncts(io.trino.sql.ExpressionUtils.combineConjuncts) ProjectNode(io.trino.sql.planner.plan.ProjectNode) Session(io.trino.Session) Symbol(io.trino.sql.planner.Symbol)

Aggregations

ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Session (io.trino.Session)1 UNKNOWN_FILTER_COEFFICIENT (io.trino.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT)1 SemiJoinStatsCalculator.computeAntiJoin (io.trino.cost.SemiJoinStatsCalculator.computeAntiJoin)1 SemiJoinStatsCalculator.computeSemiJoin (io.trino.cost.SemiJoinStatsCalculator.computeSemiJoin)1 Pattern (io.trino.matching.Pattern)1 Metadata (io.trino.metadata.Metadata)1 ExpressionUtils.combineConjuncts (io.trino.sql.ExpressionUtils.combineConjuncts)1 ExpressionUtils.extractConjuncts (io.trino.sql.ExpressionUtils.extractConjuncts)1 Symbol (io.trino.sql.planner.Symbol)1 TypeProvider (io.trino.sql.planner.TypeProvider)1 Lookup (io.trino.sql.planner.iterative.Lookup)1 FilterNode (io.trino.sql.planner.plan.FilterNode)1 Patterns.filter (io.trino.sql.planner.plan.Patterns.filter)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1 ProjectNode (io.trino.sql.planner.plan.ProjectNode)1 SemiJoinNode (io.trino.sql.planner.plan.SemiJoinNode)1 Expression (io.trino.sql.tree.Expression)1 NotExpression (io.trino.sql.tree.NotExpression)1