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));
}
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;
}
}
Aggregations