Search in sources :

Example 6 with RecordQueryPlanWithIndex

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

the class ValueIndexScanMatchCandidate method tryFetchCoveringIndexScan.

@Nonnull
private Optional<RelationalExpression> tryFetchCoveringIndexScan(@Nonnull final PartialMatch partialMatch, @Nonnull final List<ComparisonRange> comparisonRanges, final boolean isReverse) {
    if (recordTypes.size() > 1) {
        return Optional.empty();
    }
    final RecordType recordType = Iterables.getOnlyElement(recordTypes);
    final IndexKeyValueToPartialRecord.Builder builder = IndexKeyValueToPartialRecord.newBuilder(recordType);
    for (int i = 0; i < indexKeyValues.size(); i++) {
        final Value keyValue = indexKeyValues.get(i);
        if (keyValue instanceof FieldValue && keyValue.isFunctionallyDependentOn(recordValue)) {
            final AvailableFields.FieldData fieldData = AvailableFields.FieldData.of(IndexKeyValueToPartialRecord.TupleSource.KEY, i);
            addCoveringField(builder, (FieldValue) keyValue, fieldData);
        }
    }
    for (int i = 0; i < indexValueValues.size(); i++) {
        final Value valueValue = indexValueValues.get(i);
        if (valueValue instanceof FieldValue && valueValue.isFunctionallyDependentOn(recordValue)) {
            final AvailableFields.FieldData fieldData = AvailableFields.FieldData.of(IndexKeyValueToPartialRecord.TupleSource.VALUE, i);
            addCoveringField(builder, (FieldValue) valueValue, fieldData);
        }
    }
    if (!builder.isValid()) {
        return Optional.empty();
    }
    final IndexScanParameters scanParameters = IndexScanComparisons.byValue(toScanComparisons(comparisonRanges));
    final RecordQueryPlanWithIndex indexPlan = new RecordQueryIndexPlan(index.getName(), scanParameters, isReverse, false, (ValueIndexScanMatchCandidate) partialMatch.getMatchCandidate());
    final RecordQueryCoveringIndexPlan coveringIndexPlan = new RecordQueryCoveringIndexPlan(indexPlan, recordType.getName(), // not used except for old planner properties
    AvailableFields.NO_FIELDS, builder.build());
    return Optional.of(new RecordQueryFetchFromPartialRecordPlan(coveringIndexPlan, coveringIndexPlan::pushValueThroughFetch));
}
Also used : IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) IndexKeyValueToPartialRecord(com.apple.foundationdb.record.query.plan.IndexKeyValueToPartialRecord) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) RecordQueryCoveringIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan) AvailableFields(com.apple.foundationdb.record.query.plan.AvailableFields) RecordQueryFetchFromPartialRecordPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryFetchFromPartialRecordPlan) RecordType(com.apple.foundationdb.record.metadata.RecordType) QuantifiedValue(com.apple.foundationdb.record.query.predicates.QuantifiedValue) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue) Value(com.apple.foundationdb.record.query.predicates.Value) QuantifiedColumnValue(com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue) RecordQueryPlanWithIndex(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithIndex) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue) Nonnull(javax.annotation.Nonnull)

Example 7 with RecordQueryPlanWithIndex

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

the class UnmatchedFieldsCountProperty method evaluateAtExpression.

@Nonnull
@Override
public Integer evaluateAtExpression(@Nonnull RelationalExpression expression, @Nonnull List<Integer> childResults) {
    int total = 0;
    for (Integer result : childResults) {
        if (result != null) {
            total += result;
        }
    }
    if (expression instanceof RecordQueryCoveringIndexPlan) {
        expression = ((RecordQueryCoveringIndexPlan) expression).getIndexPlan();
    }
    final int columnSize;
    if (expression instanceof RecordQueryPlanWithComparisons) {
        final ScanComparisons comparisons = ((RecordQueryPlanWithComparisons) expression).getComparisons();
        if (expression instanceof RecordQueryPlanWithIndex) {
            final String indexName = ((RecordQueryPlanWithIndex) expression).getIndexName();
            columnSize = planContext.getIndexByName(indexName).getRootExpression().getColumnSize();
        } else if (expression instanceof RecordQueryScanPlan) {
            columnSize = planContext.getGreatestPrimaryKeyWidth();
        } else {
            throw new RecordCoreException("unhandled plan with comparisons: can't find key expression");
        }
        return total + columnSize - (comparisons.getEqualitySize() + (comparisons.isEquality() ? 0 : 1));
    } else {
        return total;
    }
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) ScanComparisons(com.apple.foundationdb.record.query.plan.ScanComparisons) RecordQueryPlanWithComparisons(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithComparisons) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) RecordQueryCoveringIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan) RecordQueryPlanWithIndex(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithIndex) Nonnull(javax.annotation.Nonnull)

Aggregations

RecordQueryPlanWithIndex (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithIndex)7 Index (com.apple.foundationdb.record.metadata.Index)5 RecordType (com.apple.foundationdb.record.metadata.RecordType)5 RecordQueryCoveringIndexPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryCoveringIndexPlan)4 Nonnull (javax.annotation.Nonnull)4 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)3 RecordQueryFetchFromPartialRecordPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryFetchFromPartialRecordPlan)3 RecordQueryIndexPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan)3 AvailableFields (com.apple.foundationdb.record.query.plan.AvailableFields)2 IndexKeyValueToPartialRecord (com.apple.foundationdb.record.query.plan.IndexKeyValueToPartialRecord)2 ScanComparisons (com.apple.foundationdb.record.query.plan.ScanComparisons)2 RecordQueryScanPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)1 ThenKeyExpression (com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression)1 IndexScanParameters (com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters)1 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)1 RecordQueryFilterPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryFilterPlan)1