Search in sources :

Example 1 with VersionKeyExpression

use of com.apple.foundationdb.record.metadata.expressions.VersionKeyExpression in project fdb-record-layer by FoundationDB.

the class RecordQueryPlanner method planVersion.

@Nullable
private ScoredPlan planVersion(@Nonnull CandidateScan candidateScan, @Nonnull KeyExpression indexExpr, @Nonnull QueryRecordFunctionWithComparison filter, @Nullable KeyExpression sort) {
    if (indexExpr instanceof VersionKeyExpression) {
        final Comparisons.Comparison comparison = filter.getComparison();
        final ScanComparisons comparisons = ScanComparisons.from(comparison);
        if (sort == null || sort.equals(VersionKeyExpression.VERSION)) {
            IndexScanParameters scanParameters = IndexScanComparisons.byValue(comparisons);
            RecordQueryPlan plan = new RecordQueryIndexPlan(candidateScan.index.getName(), scanParameters, candidateScan.reverse);
            return new ScoredPlan(1, plan, Collections.emptyList(), false);
        }
    } else if (indexExpr instanceof ThenKeyExpression) {
        ThenKeyExpression then = (ThenKeyExpression) indexExpr;
        if (sort == null) {
            // && !then.createsDuplicates()) {
            return planVersion(candidateScan, then.getChildren().get(0), filter, null);
        } else {
            return new AndWithThenPlanner(candidateScan, then, Collections.singletonList(filter), sort).plan();
        }
    }
    return null;
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) VersionKeyExpression(com.apple.foundationdb.record.metadata.expressions.VersionKeyExpression) IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) ThenKeyExpression(com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression) TimeWindowScanComparisons(com.apple.foundationdb.record.provider.foundationdb.leaderboard.TimeWindowScanComparisons) IndexScanComparisons(com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons) TimeWindowScanComparisons(com.apple.foundationdb.record.provider.foundationdb.leaderboard.TimeWindowScanComparisons) IndexScanComparisons(com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons) RankComparisons(com.apple.foundationdb.record.query.plan.planning.RankComparisons) Comparisons(com.apple.foundationdb.record.query.expressions.Comparisons) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) Nullable(javax.annotation.Nullable)

Aggregations

ThenKeyExpression (com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression)1 VersionKeyExpression (com.apple.foundationdb.record.metadata.expressions.VersionKeyExpression)1 IndexScanComparisons (com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons)1 IndexScanParameters (com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters)1 TimeWindowScanComparisons (com.apple.foundationdb.record.provider.foundationdb.leaderboard.TimeWindowScanComparisons)1 Comparisons (com.apple.foundationdb.record.query.expressions.Comparisons)1 RankComparisons (com.apple.foundationdb.record.query.plan.planning.RankComparisons)1 RecordQueryIndexPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan)1 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)1 Nullable (javax.annotation.Nullable)1