use of com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons 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())));
}
use of com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons in project fdb-record-layer by FoundationDB.
the class RecordQueryPlanner method planCoveringAggregateIndex.
@Nullable
public RecordQueryCoveringIndexPlan planCoveringAggregateIndex(@Nonnull RecordQuery query, @Nonnull Index index, @Nonnull KeyExpression indexExpr) {
final Collection<RecordType> recordTypes = metaData.recordTypesForIndex(index);
if (recordTypes.size() != 1) {
// Unfortunately, since we materialize partial records, we need a unique type for them.
return null;
}
final RecordType recordType = recordTypes.iterator().next();
final PlanContext planContext = getPlanContext(query);
planContext.rankComparisons = new RankComparisons(query.getFilter(), planContext.indexes);
// Repeated fields will be scanned one at a time by covering aggregate, so there is no issue with fan out.
planContext.allowDuplicates = true;
final CandidateScan candidateScan = new CandidateScan(planContext, index, query.isSortReverse());
final ScoredPlan scoredPlan = planCandidateScan(candidateScan, indexExpr, BooleanNormalizer.forConfiguration(configuration).normalizeIfPossible(query.getFilter()), query.getSort());
// It would be possible to handle unsatisfiedFilters if they, too, only involved group key (covering) fields.
if (scoredPlan == null || !scoredPlan.unsatisfiedFilters.isEmpty() || !(scoredPlan.plan instanceof RecordQueryIndexPlan)) {
return null;
}
final IndexKeyValueToPartialRecord.Builder builder = IndexKeyValueToPartialRecord.newBuilder(recordType);
final List<KeyExpression> keyFields = index.getRootExpression().normalizeKeyForPositions();
final List<KeyExpression> valueFields = Collections.emptyList();
for (KeyExpression resultField : query.getRequiredResults()) {
if (!addCoveringField(resultField, builder, keyFields, valueFields)) {
return null;
}
}
builder.addRequiredMessageFields();
if (!builder.isValid(true)) {
return null;
}
RecordQueryIndexPlan plan = (RecordQueryIndexPlan) scoredPlan.plan;
IndexScanParameters scanParameters = new IndexScanComparisons(IndexScanType.BY_GROUP, plan.getComparisons());
plan = new RecordQueryIndexPlan(plan.getIndexName(), scanParameters, plan.isReverse());
return new RecordQueryCoveringIndexPlan(plan, recordType.getName(), AvailableFields.NO_FIELDS, builder.build());
}
use of com.apple.foundationdb.record.provider.foundationdb.IndexScanComparisons in project fdb-record-layer by FoundationDB.
the class RecordQueryPlanner method planScan.
@Nonnull
private RecordQueryPlan planScan(@Nonnull CandidateScan candidateScan, @Nonnull IndexScanComparisons indexScanComparisons, boolean strictlySorted) {
RecordQueryPlan plan;
Set<String> possibleTypes;
if (candidateScan.index == null) {
final ScanComparisons scanComparisons = indexScanComparisons.getComparisons();
if (primaryKeyHasRecordTypePrefix && RecordTypeKeyComparison.hasRecordTypeKeyComparison(scanComparisons)) {
possibleTypes = RecordTypeKeyComparison.recordTypeKeyComparisonTypes(scanComparisons);
} else {
possibleTypes = metaData.getRecordTypes().keySet();
}
plan = new RecordQueryScanPlan(possibleTypes, scanComparisons, candidateScan.reverse, strictlySorted);
} else {
plan = new RecordQueryIndexPlan(candidateScan.index.getName(), indexScanComparisons, candidateScan.reverse, strictlySorted);
possibleTypes = getPossibleTypes(candidateScan.index);
}
// Add a type filter if the query plan might return records of more types than the query specified
plan = addTypeFilterIfNeeded(candidateScan, plan, possibleTypes);
return plan;
}
Aggregations