Search in sources :

Example 6 with OrComponent

use of com.apple.foundationdb.record.query.expressions.OrComponent in project fdb-record-layer by FoundationDB.

the class RecordQueryPlanner method planOr.

@Nullable
private ScoredPlan planOr(@Nonnull PlanContext planContext, @Nonnull OrComponent filter) {
    if (filter.getChildren().isEmpty()) {
        return null;
    }
    List<ScoredPlan> subplans = new ArrayList<>(filter.getChildren().size());
    boolean allHaveOrderingKey = true;
    RecordQueryPlan commonFilteredBasePlan = null;
    boolean allHaveSameBasePlan = true;
    for (QueryComponent subfilter : filter.getChildren()) {
        ScoredPlan subplan = planFilter(planContext, subfilter, true);
        if (subplan == null) {
            return null;
        }
        if (subplan.planOrderingKey == null) {
            allHaveOrderingKey = false;
        }
        RecordQueryPlan filteredBasePlan;
        if (subplan.plan instanceof RecordQueryFilterPlan) {
            filteredBasePlan = ((RecordQueryFilterPlan) subplan.plan).getInnerPlan();
        } else {
            filteredBasePlan = null;
        }
        if (subplans.isEmpty()) {
            commonFilteredBasePlan = filteredBasePlan;
            allHaveSameBasePlan = filteredBasePlan != null;
        } else if (allHaveSameBasePlan && !Objects.equals(filteredBasePlan, commonFilteredBasePlan)) {
            allHaveSameBasePlan = false;
        }
        subplans.add(subplan);
    }
    // out there over the equivalent OR(EQUALS) filters.
    if (allHaveSameBasePlan) {
        final RecordQueryPlan combinedOrFilter = new RecordQueryFilterPlan(commonFilteredBasePlan, new OrComponent(subplans.stream().map(subplan -> ((RecordQueryFilterPlan) subplan.plan).getConjunctedFilter()).collect(Collectors.toList())));
        ScoredPlan firstSubPlan = subplans.get(0);
        return new ScoredPlan(combinedOrFilter, Collections.emptyList(), Collections.emptyList(), firstSubPlan.score, firstSubPlan.createsDuplicates, firstSubPlan.includedRankComparisons);
    }
    // neither removes duplicates nor requires the children be in order.
    if (allHaveOrderingKey) {
        final ScoredPlan orderedUnionPlan = planOrderedUnion(planContext, subplans);
        if (orderedUnionPlan != null) {
            return orderedUnionPlan;
        }
    }
    final ScoredPlan unorderedUnionPlan = planUnorderedUnion(planContext, subplans);
    if (unorderedUnionPlan != null) {
        return planRemoveDuplicates(planContext, unorderedUnionPlan);
    }
    return null;
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) RecordQueryFilterPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryFilterPlan) RecordQueryIntersectionPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIntersectionPlan) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) RecordTypeKeyExpression(com.apple.foundationdb.record.metadata.expressions.RecordTypeKeyExpression) LoggerFactory(org.slf4j.LoggerFactory) IndexScanType(com.apple.foundationdb.record.IndexScanType) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) QueryRecordFunctionWithComparison(com.apple.foundationdb.record.query.expressions.QueryRecordFunctionWithComparison) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) VersionKeyExpression(com.apple.foundationdb.record.metadata.expressions.VersionKeyExpression) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) FieldWithComparisonCountProperty(com.apple.foundationdb.record.query.plan.temp.properties.FieldWithComparisonCountProperty) RecordQueryUnionPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryUnionPlan) RecordQueryUnorderedUnionPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryUnorderedUnionPlan) Query(com.apple.foundationdb.record.query.expressions.Query) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) TimeWindowScanComparisons(com.apple.foundationdb.record.provider.foundationdb.leaderboard.TimeWindowScanComparisons) Collection(java.util.Collection) PlannerGraphProperty(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraphProperty) Set(java.util.Set) FanType(com.apple.foundationdb.record.metadata.expressions.KeyExpression.FanType) AndComponent(com.apple.foundationdb.record.query.expressions.AndComponent) TextScanPlanner(com.apple.foundationdb.record.query.plan.planning.TextScanPlanner) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) RecordQueryCoveringIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan) List(java.util.List) OneOfThemWithComponent(com.apple.foundationdb.record.query.expressions.OneOfThemWithComponent) RecordQueryInUnionPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryInUnionPlan) RecordQueryUnorderedPrimaryKeyDistinctPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryUnorderedPrimaryKeyDistinctPlan) RecordStoreState(com.apple.foundationdb.record.RecordStoreState) RecordTypeKeyComparison(com.apple.foundationdb.record.query.expressions.RecordTypeKeyComparison) API(com.apple.foundationdb.annotation.API) RecordQueryTypeFilterPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryTypeFilterPlan) FunctionNames(com.apple.foundationdb.record.FunctionNames) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordQueryPlannerSubstitutionVisitor(com.apple.foundationdb.record.query.plan.visitor.RecordQueryPlannerSubstitutionVisitor) Iterables(com.google.common.collect.Iterables) SpotBugsSuppressWarnings(com.apple.foundationdb.annotation.SpotBugsSuppressWarnings) IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) RecordQueryPlannerSortConfiguration(com.apple.foundationdb.record.query.plan.sorting.RecordQueryPlannerSortConfiguration) InExtractor(com.apple.foundationdb.record.query.plan.planning.InExtractor) KeyWithValueExpression(com.apple.foundationdb.record.metadata.expressions.KeyWithValueExpression) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) BooleanNormalizer(com.apple.foundationdb.record.query.plan.planning.BooleanNormalizer) ArrayList(java.util.ArrayList) Key(com.apple.foundationdb.record.metadata.Key) FieldKeyExpression(com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression) HashSet(java.util.HashSet) UnorderedPrimaryKeyDistinctVisitor(com.apple.foundationdb.record.query.plan.visitor.UnorderedPrimaryKeyDistinctVisitor) FilterVisitor(com.apple.foundationdb.record.query.plan.visitor.FilterVisitor) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) NestingKeyExpression(com.apple.foundationdb.record.metadata.expressions.NestingKeyExpression) ParameterRelationshipGraph(com.apple.foundationdb.record.query.ParameterRelationshipGraph) IndexScanComparisons(com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons) TimeWindowRecordFunction(com.apple.foundationdb.record.provider.foundationdb.leaderboard.TimeWindowRecordFunction) InSource(com.apple.foundationdb.record.query.plan.plans.InSource) Nonnull(javax.annotation.Nonnull) EmptyKeyExpression(com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression) Nullable(javax.annotation.Nullable) QueryKeyExpressionWithComparison(com.apple.foundationdb.record.query.expressions.QueryKeyExpressionWithComparison) FieldWithComparison(com.apple.foundationdb.record.query.expressions.FieldWithComparison) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) RecordQueryPlanWithIndex(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithIndex) Logger(org.slf4j.Logger) FilterSatisfiedMask(com.apple.foundationdb.record.query.plan.planning.FilterSatisfiedMask) Iterator(java.util.Iterator) RecordQueryTextIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryTextIndexPlan) RankComparisons(com.apple.foundationdb.record.query.plan.planning.RankComparisons) OrComponent(com.apple.foundationdb.record.query.expressions.OrComponent) Comparisons(com.apple.foundationdb.record.query.expressions.Comparisons) RecordType(com.apple.foundationdb.record.metadata.RecordType) NestedField(com.apple.foundationdb.record.query.expressions.NestedField) Index(com.apple.foundationdb.record.metadata.Index) RecordQuerySortPlan(com.apple.foundationdb.record.query.plan.sorting.RecordQuerySortPlan) QueryKeyExpressionWithOneOfComparison(com.apple.foundationdb.record.query.expressions.QueryKeyExpressionWithOneOfComparison) OneOfThemWithComparison(com.apple.foundationdb.record.query.expressions.OneOfThemWithComparison) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) ThenKeyExpression(com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression) Collections(java.util.Collections) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) RecordQueryFilterPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryFilterPlan) OrComponent(com.apple.foundationdb.record.query.expressions.OrComponent) ArrayList(java.util.ArrayList) Nullable(javax.annotation.Nullable)

Aggregations

OrComponent (com.apple.foundationdb.record.query.expressions.OrComponent)6 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)5 Index (com.apple.foundationdb.record.metadata.Index)3 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)3 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)3 HashSet (java.util.HashSet)3 Nonnull (javax.annotation.Nonnull)3 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)2 PlanHashable (com.apple.foundationdb.record.PlanHashable)2 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)2 RecordCursorIterator (com.apple.foundationdb.record.RecordCursorIterator)2 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)2 Key (com.apple.foundationdb.record.metadata.Key)2 KeyWithValueExpression (com.apple.foundationdb.record.metadata.expressions.KeyWithValueExpression)2 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)2 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)2 IndexScanComparisons (com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons)2 IndexScanParameters (com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters)2 Comparisons (com.apple.foundationdb.record.query.expressions.Comparisons)2 Query (com.apple.foundationdb.record.query.expressions.Query)2