Search in sources :

Example 1 with RecordQueryScanPlan

use of com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan in project fdb-record-layer by FoundationDB.

the class FullUnorderedExpressionToScanPlanRule method onMatch.

@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
    final FullUnorderedScanExpression fullUnorderedScanExpression = call.get(root);
    call.yield(call.ref(new RecordQueryScanPlan(fullUnorderedScanExpression.getRecordTypes(), ScanComparisons.EMPTY, false)));
}
Also used : RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) FullUnorderedScanExpression(com.apple.foundationdb.record.query.plan.temp.expressions.FullUnorderedScanExpression)

Example 2 with RecordQueryScanPlan

use of com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan in project fdb-record-layer by FoundationDB.

the class ExpressionMatcherTest method anyRefMatcher.

@Test
public void anyRefMatcher() {
    // create a matcher and expression to match
    BindingMatcher<? extends ExpressionRef<? extends RelationalExpression>> matcher = ReferenceMatchers.anyRef();
    Quantifier.ForEach quantifier = Quantifier.forEach(GroupExpressionRef.of(new RecordQueryScanPlan(ScanComparisons.EMPTY, false)));
    ExpressionRef<RelationalExpression> root = GroupExpressionRef.of(new LogicalFilterExpression(ImmutableList.of(new QueryComponentPredicate(Query.field("test").equalsValue(5))), quantifier));
    // try to match to expression
    Optional<PlannerBindings> newBindings = matcher.bindMatches(PlannerBindings.empty(), root).findFirst();
    // check the the bindings are what we expect, and that none of the existing ones were clobbered
    assertTrue(newBindings.isPresent());
    PlannerBindings allBindings = newBindings.get().mergedWith(getExistingBindings());
    assertExistingBindingsSurvived(allBindings);
    assertTrue(newBindings.get().containsKey(matcher));
    assertTrue(allBindings.containsKey(matcher));
    assertEquals(root, allBindings.get(matcher));
}
Also used : RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) QueryComponentPredicate(com.apple.foundationdb.record.query.predicates.QueryComponentPredicate) LogicalFilterExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) Test(org.junit.jupiter.api.Test)

Example 3 with RecordQueryScanPlan

use of com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreLimitTestBase method plans.

public Stream<Arguments> plans(boolean fail) {
    RecordQueryPlan scanPlan = new RecordQueryScanPlan(ScanComparisons.EMPTY, false);
    IndexScanParameters fullValueScan = IndexScanComparisons.byValue();
    RecordQueryPlan indexPlan = new RecordQueryIndexPlan("MySimpleRecord$str_value_indexed", fullValueScan, false);
    QueryComponent filter = Query.field("str_value_indexed").equalsValue("odd");
    QueryComponent middleFilter = Query.and(Query.field("rec_no").greaterThan(24L), Query.field("rec_no").lessThan(60L));
    RecordQueryPlan firstChild = indexPlanEquals("MySimpleRecord$str_value_indexed", "even");
    RecordQueryPlan secondChild = indexPlanEquals("MySimpleRecord$num_value_3_indexed", 0);
    return Stream.of(Arguments.of("full record scan", fail, scanPlan), Arguments.of("simple index scan", fail, indexPlan), Arguments.of("reverse index scan", fail, new RecordQueryIndexPlan("MySimpleRecord$str_value_indexed", fullValueScan, true)), Arguments.of("filter on scan plan", fail, new RecordQueryFilterPlan(scanPlan, filter)), Arguments.of("filter on index plan", fail, new RecordQueryFilterPlan(indexPlan, filter)), Arguments.of("type filter on scan plan", fail, new RecordQueryTypeFilterPlan(scanPlan, Collections.singletonList("MySimpleRecord"))), Arguments.of("type filter on index plan", fail, new RecordQueryTypeFilterPlan(indexPlan, Collections.singletonList("MySimpleRecord"))), Arguments.of("disjoint union", fail, RecordQueryUnionPlan.from(indexPlanEquals("MySimpleRecord$str_value_indexed", "odd"), indexPlanEquals("MySimpleRecord$str_value_indexed", "even"), primaryKey(), false)), Arguments.of("overlapping union", fail, RecordQueryUnionPlan.from(firstChild, secondChild, primaryKey(), false)), Arguments.of("overlapping union (swapped args)", fail, RecordQueryUnionPlan.from(secondChild, firstChild, primaryKey(), false)), Arguments.of("overlapping intersection", fail, RecordQueryIntersectionPlan.from(firstChild, secondChild, primaryKey())), Arguments.of("overlapping intersection", fail, RecordQueryIntersectionPlan.from(secondChild, firstChild, primaryKey())), Arguments.of("union with inner filter", fail, RecordQueryUnionPlan.from(new RecordQueryFilterPlan(firstChild, middleFilter), secondChild, primaryKey(), false)), Arguments.of("union with two inner filters", fail, RecordQueryUnionPlan.from(new RecordQueryFilterPlan(firstChild, middleFilter), new RecordQueryFilterPlan(secondChild, Query.field("rec_no").lessThan(55L)), primaryKey(), false)), Arguments.of("intersection with inner filter", fail, RecordQueryIntersectionPlan.from(new RecordQueryFilterPlan(firstChild, middleFilter), secondChild, primaryKey())), Arguments.of("intersection with two inner filters", fail, RecordQueryIntersectionPlan.from(new RecordQueryFilterPlan(firstChild, middleFilter), new RecordQueryFilterPlan(secondChild, Query.field("rec_no").lessThan(55L)), primaryKey())));
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) RecordQueryFilterPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryFilterPlan) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) RecordQueryTypeFilterPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryTypeFilterPlan)

Example 4 with RecordQueryScanPlan

use of com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan in project fdb-record-layer by FoundationDB.

the class QueryPlanStructuralInstrumentationTest method fullScan.

@Test
public void fullScan() {
    StoreTimer timer = new FDBStoreTimer();
    RecordQueryPlan plan = new RecordQueryScanPlan(ScanComparisons.EMPTY, false);
    plan.logPlanStructure(timer);
    assertNoIndexes(plan);
    assertEquals(timer.getCount(FDBStoreTimer.Counts.PLAN_SCAN), 1);
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Test(org.junit.jupiter.api.Test)

Example 5 with RecordQueryScanPlan

use of com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan in project fdb-record-layer by FoundationDB.

the class ExpressionMatcherTest method treeDescentWithMixedBindings.

@Test
public void treeDescentWithMixedBindings() {
    // build a relatively complicated matcher
    BindingMatcher<? extends ExpressionRef<? extends RelationalExpression>> filterLeafMatcher = ReferenceMatchers.anyRef();
    BindingMatcher<QueryPredicate> predicateMatcher = QueryPredicateMatchers.anyPredicate();
    final BindingMatcher<LogicalFilterExpression> filterPlanMatcher = RelationalExpressionMatchers.logicalFilterExpression(MultiMatcher.AllMatcher.all(predicateMatcher), AnyMatcher.any(QuantifierMatchers.forEachQuantifierOverRef(filterLeafMatcher)));
    BindingMatcher<RecordQueryScanPlan> scanMatcher = RecordQueryPlanMatchers.scanPlan();
    BindingMatcher<LogicalUnionExpression> matcher = RelationalExpressionMatchers.logicalUnionExpression(ListMatcher.exactly(QuantifierMatchers.forEachQuantifier(filterPlanMatcher), QuantifierMatchers.forEachQuantifier(scanMatcher)));
    // build a relatively complicated expression
    QueryComponent andBranch1 = Query.field("field1").greaterThan(6);
    QueryComponent andBranch2 = Query.field("field2").equalsParameter("param");
    IndexScanParameters fullValueScan = IndexScanComparisons.byValue();
    final Quantifier.ForEach quantifier = Quantifier.forEach(GroupExpressionRef.of(new RecordQueryIndexPlan("an_index", fullValueScan, true)));
    LogicalFilterExpression filterPlan = new LogicalFilterExpression(Query.and(andBranch1, andBranch2).expand(quantifier.getAlias()).getPredicates(), quantifier);
    RecordQueryScanPlan scanPlan = new RecordQueryScanPlan(ScanComparisons.EMPTY, true);
    RelationalExpression root = new LogicalUnionExpression(Quantifiers.forEachQuantifiers(ImmutableList.of(GroupExpressionRef.of(filterPlan), GroupExpressionRef.of(scanPlan))));
    assertTrue(filterPlanMatcher.bindMatches(PlannerBindings.empty(), filterPlan).findFirst().isPresent());
    // try to bind
    Optional<PlannerBindings> possibleBindings = matcher.bindMatches(PlannerBindings.empty(), root).findFirst();
    // check that all the bindings match what we expect
    assertTrue(possibleBindings.isPresent());
    PlannerBindings bindings = possibleBindings.get().mergedWith(getExistingBindings());
    assertEquals(root, bindings.get(matcher));
    assertEquals(filterPlan, bindings.get(filterPlanMatcher));
    assertEquals(scanPlan, bindings.get(scanMatcher));
    assertEquals(filterPlan.getPredicates(), bindings.getAll(predicateMatcher));
    // dereference
    assertEquals(filterPlan.getInner().getRangesOver().get(), bindings.get(filterLeafMatcher).get());
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) LogicalUnionExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalUnionExpression) LogicalFilterExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) Test(org.junit.jupiter.api.Test)

Aggregations

RecordQueryScanPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan)12 RecordQueryIndexPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan)7 Test (org.junit.jupiter.api.Test)6 IndexScanParameters (com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters)5 RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)5 RecordQueryUnionPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryUnionPlan)4 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)3 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)2 RecordQueryFilterPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryFilterPlan)2 RecordQueryPlanWithIndex (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithIndex)2 Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)2 LogicalFilterExpression (com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression)2 Nonnull (javax.annotation.Nonnull)2 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 Index (com.apple.foundationdb.record.metadata.Index)1 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)1 ThenKeyExpression (com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression)1 StoreTimer (com.apple.foundationdb.record.provider.common.StoreTimer)1 FDBStoreTimer (com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer)1 IndexScanComparisons (com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons)1