Fix execution planning of MATCH statement with optional nodes on empty classes
@@ -75,10 +75,12 @@ public class OMatchExecutionPlanner {
Map<String, Long> estimatedRootEntries = estimateRootEntries(aliasClasses, aliasClusters, aliasRids, aliasFilters, context);
Set<String> aliasesToPrefetch = estimatedRootEntries.entrySet().stream().filter(x -> x.getValue() < this.threshold).
map(x -> x.getKey()).collect(Collectors.toSet());
- if (estimatedRootEntries.values().contains(0l)) {
+ for (Map.Entry<String, Long> entry : estimatedRootEntries.entrySet()) {
+ if (entry.getValue() == 0L && !isOptional(entry.getKey())) {
result.chain(new EmptyStep(context, enableProfiling));
return result;
}
+ }
addPrefetchSteps(result, aliasesToPrefetch, context, enableProfiling);
@@ -156,6 +158,11 @@ public class OMatchExecutionPlanner {
}
+ private boolean isOptional(String key) {
+ PatternNode node = this.pattern.aliasToNode.get(key);
+ return node != null && node.isOptionalNode();
+ }
+
private void manageNotPatterns(OSelectExecutionPlan result, Pattern pattern, List<OMatchExpression> notMatchExpressions,
OCommandContext context, boolean enableProfiling) {
for (OMatchExpression exp : notMatchExpressions) {
