use of com.apple.foundationdb.record.metadata.expressions.RecordTypeKeyExpression in project fdb-record-layer by FoundationDB.
the class RecordQueryPlanner method planFieldWithComparison.
@Nullable
private ScoredPlan planFieldWithComparison(@Nonnull CandidateScan candidateScan, @Nonnull KeyExpression indexExpr, @Nonnull FieldWithComparison singleField, @Nullable KeyExpression sort, boolean fullKey) {
final Comparisons.Comparison comparison = singleField.getComparison();
final ScanComparisons scanComparisons = ScanComparisons.from(comparison);
if (scanComparisons == null) {
// this index, but this should be handled elsewhere by the planner.
return null;
}
if (indexExpr instanceof FieldKeyExpression) {
FieldKeyExpression field = (FieldKeyExpression) indexExpr;
if (Objects.equals(singleField.getFieldName(), field.getFieldName())) {
if (sort != null) {
if (sort instanceof FieldKeyExpression) {
FieldKeyExpression sortField = (FieldKeyExpression) sort;
if (Objects.equals(sortField.getFieldName(), field.getFieldName())) {
// everything matches, yay!! Hopefully that comparison can be for tuples
return new ScoredPlan(1, valueScan(candidateScan, scanComparisons, fullKey));
}
}
} else {
return new ScoredPlan(1, valueScan(candidateScan, scanComparisons, false));
}
}
return null;
} else if (indexExpr instanceof ThenKeyExpression) {
ThenKeyExpression then = (ThenKeyExpression) indexExpr;
if ((sort == null || sort.equals(then.getChildren().get(0))) && !then.createsDuplicates() && !(then.getChildren().get(0) instanceof RecordTypeKeyExpression)) {
// First column will do it all or not.
return planFieldWithComparison(candidateScan, then.getChildren().get(0), singleField, sort, false);
} else {
// May need second column to do sort, so handle like And, which does such cases.
return new AndWithThenPlanner(candidateScan, then, Collections.singletonList(singleField), sort).plan();
}
}
return null;
}
Aggregations