Search in sources :

Example 1 with IndexScanParameters

use of com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters in project fdb-record-layer by FoundationDB.

the class ImplementIndexScanRule method onMatch.

@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
    final IndexScanExpression logical = call.get(root);
    final IndexScanParameters scan = new IndexScanComparisons(logical.getScanType(), logical.scanComparisons());
    call.yield(call.ref(new RecordQueryIndexPlan(Objects.requireNonNull(logical.getIndexName()), scan, logical.isReverse())));
}
Also used : IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) IndexScanComparisons(com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) IndexScanExpression(com.apple.foundationdb.record.query.plan.temp.expressions.IndexScanExpression)

Example 2 with IndexScanParameters

use of com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreScanLimitTest method testExecuteStateReset.

@ParameterizedTest
// for this test, the scan limit must divide 100
@ValueSource(ints = { 2, 5, 10, 20 })
public void testExecuteStateReset(int scanLimit) throws Exception {
    final IndexScanParameters fullValueScan = IndexScanComparisons.byValue();
    final RecordQueryPlan plan = new RecordQueryIndexPlan("MySimpleRecord$str_value_indexed", fullValueScan, false);
    ExecuteProperties properties = ExecuteProperties.newBuilder().setScannedRecordsLimit(scanLimit).build();
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        byte[] continuation = null;
        do {
            try (RecordCursorIterator<FDBQueriedRecord<Message>> cursor = recordStore.executeQuery(plan, continuation, properties).asIterator()) {
                int retrieved = 0;
                while (cursor.hasNext()) {
                    cursor.next();
                    retrieved++;
                }
                continuation = cursor.getContinuation();
                if (continuation != null) {
                    // if this is our last call, we might retrieve 0 results
                    assertEquals(scanLimit, retrieved);
                }
                properties = properties.resetState();
            }
        } while (continuation != null);
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with IndexScanParameters

use of com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters in project fdb-record-layer by FoundationDB.

the class FDBAndQueryToIntersectionTest method intersectionVisitorOnComplexComparisonKey.

/**
 * Verify that an intersection visitor won't defer a record fetch if the comparison key has fields that the index
 * entry doesn't.
 * This sort of plan is never produced by the {@link com.apple.foundationdb.record.query.plan.RecordQueryPlanner},
 * so we have to test the visitor directly.
 */
@Test
public void intersectionVisitorOnComplexComparisonKey() throws Exception {
    complexQuerySetup(null);
    IndexScanParameters fullValueScan = IndexScanComparisons.byValue();
    RecordQueryPlan originalPlan1 = RecordQueryIntersectionPlan.from(new RecordQueryIndexPlan("MySimpleRecord$str_value_indexed", fullValueScan, false), new RecordQueryIndexPlan("MySimpleRecord$num_value_3_indexed", fullValueScan, false), primaryKey("MySimpleRecord"));
    RecordQueryPlan modifiedPlan1 = RecordQueryPlannerSubstitutionVisitor.applyVisitors(originalPlan1, recordStore.getRecordMetaData(), PlannableIndexTypes.DEFAULT, primaryKey("MySimpleRecord"));
    assertThat(modifiedPlan1, fetch(intersection(coveringIndexScan(indexScan("MySimpleRecord$str_value_indexed")), coveringIndexScan(indexScan("MySimpleRecord$num_value_3_indexed")))));
    RecordQueryPlan originalPlan2 = RecordQueryIntersectionPlan.from(new RecordQueryIndexPlan("MySimpleRecord$str_value_indexed", fullValueScan, false), new RecordQueryIndexPlan("MySimpleRecord$num_value_3_indexed", fullValueScan, false), concat(field("num_value_2"), primaryKey("MySimpleRecord")));
    RecordQueryPlan modifiedPlan2 = RecordQueryPlannerSubstitutionVisitor.applyVisitors(originalPlan2, recordStore.getRecordMetaData(), PlannableIndexTypes.DEFAULT, primaryKey("MySimpleRecord"));
    // Visitor should not perform transformation because of comparison key on num_value_unique
    assertEquals(originalPlan2, modifiedPlan2);
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with IndexScanParameters

use of com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters in project fdb-record-layer by FoundationDB.

the class QueryPlanStructuralInstrumentationTest method in.

@Test
public void in() {
    final String indexName = "a_field";
    final IndexScanParameters scan = IndexScanComparisons.byValue(new ScanComparisons(Arrays.asList(new Comparisons.ParameterComparison(Comparisons.Type.EQUALS, "another_field")), Collections.emptySet()));
    final RecordQueryPlan plan = new RecordQueryInValuesJoinPlan(new RecordQueryIndexPlan(indexName, scan, false), "another_field", Bindings.Internal.IN, Arrays.asList(2, 4), false, false);
    assertUsesIndexes(plan, Lists.newArrayList(indexName));
    final StoreTimer timer = new FDBStoreTimer();
    plan.logPlanStructure(timer);
    assertEquals(timer.getCount(FDBStoreTimer.Counts.PLAN_IN_VALUES), 1);
    assertEquals(timer.getCount(FDBStoreTimer.Counts.PLAN_INDEX), 1);
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) IndexScanComparisons(com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons) Comparisons(com.apple.foundationdb.record.query.expressions.Comparisons) IndexScanComparisons(com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) RecordQueryInValuesJoinPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryInValuesJoinPlan) Test(org.junit.jupiter.api.Test)

Example 5 with IndexScanParameters

use of com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters 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)

Aggregations

IndexScanParameters (com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters)14 RecordQueryIndexPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan)14 Test (org.junit.jupiter.api.Test)8 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)6 RecordQueryScanPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan)5 RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)5 IndexScanComparisons (com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons)4 RecordQueryUnionPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryUnionPlan)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 RecordType (com.apple.foundationdb.record.metadata.RecordType)2 ThenKeyExpression (com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression)2 VersionKeyExpression (com.apple.foundationdb.record.metadata.expressions.VersionKeyExpression)2 Comparisons (com.apple.foundationdb.record.query.expressions.Comparisons)2 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)2 RankComparisons (com.apple.foundationdb.record.query.plan.planning.RankComparisons)2 RecordQueryCoveringIndexPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan)2 Nullable (javax.annotation.Nullable)2 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)1 EmptyKeyExpression (com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression)1 FieldKeyExpression (com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression)1