Skip to content

Commit

Permalink
Merge pull request FoundationDB#1897 from normen662/main
Browse files Browse the repository at this point in the history
fix incorrect error thrown when planning queries over synthetic record types
  • Loading branch information
normen662 committed Nov 5, 2022
2 parents 148fc53 + 19bdbeb commit c4a348b
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private ScoredPlan planFilterForInJoin(@Nonnull PlanContext planContext, @Nonnul
List<ScoredPlan> intersectionCandidates = new ArrayList<>();
ScoredPlan bestPlan = null;
Index bestIndex = null;
if (planContext.commonPrimaryKey != null) {
if (planContext.commonPrimaryKey != null && !avoidScanPlan(planContext)) {
bestPlan = planIndex(planContext, filter, null, planContext.commonPrimaryKey, intersectionCandidates);
}
for (Index index : planContext.indexes) {
Expand Down Expand Up @@ -1430,8 +1430,7 @@ private RecordQueryPlan planScan(@Nonnull CandidateScan candidateScan,
possibleTypes = metaData.getRecordTypes().keySet();
}

if (!queriedRecordTypes.isEmpty() && // ok if user queried all record types which excludes synthetic ones
queriedRecordTypes.stream().anyMatch(syntheticRecordTypes::contains)) {
if (avoidScanPlan(candidateScan.planContext)) {
throw new RecordCoreException("cannot create scan plan for a synthetic record type");
}

Expand All @@ -1452,6 +1451,14 @@ private RecordQueryPlan planScan(@Nonnull CandidateScan candidateScan,
return plan;
}

private boolean avoidScanPlan(@Nonnull PlanContext planContext) {
final var queriedRecordTypes = planContext.query.getRecordTypes();
final var syntheticRecordTypes = metaData.getSyntheticRecordTypes().keySet();

return !queriedRecordTypes.isEmpty() && // ok if user queried all record types which excludes synthetic ones
queriedRecordTypes.stream().anyMatch(syntheticRecordTypes::contains);
}

/**
* Method to statically resolve the method of how records are fetched given an index key. In particular,
* {@link com.apple.foundationdb.record.metadata.SyntheticRecordType}s have constituent parts which need to
Expand Down

0 comments on commit c4a348b

Please sign in to comment.