Skip to content

Commit 9d90e14

Browse files
committed
wip
1 parent 1455239 commit 9d90e14

File tree

1 file changed

+11
-9
lines changed
  • core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/optimizer

1 file changed

+11
-9
lines changed

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/optimizer/QueryJoinOptimizer.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,19 @@ private Deque<TupleExpr> reorderJoinArgs(Deque<TupleExpr> orderedJoinArgs) {
342342
// Memo table: for each (a, b), stores statistics.getCardinality(new Join(a,b))
343343
Map<TupleExpr, Map<TupleExpr, Double>> cardCache = new HashMap<>();
344344

345-
// Helper to look up or compute & cache the cardinality of Join(a,b)
345+
// Helper to look up or compute & cache the cardinality of Join(a,b).
346+
// Avoid mutating the outer cache inside a computeIfAbsent lambda to prevent
347+
// ConcurrentModificationException on some Map implementations/JDKs.
346348
BiFunction<TupleExpr, TupleExpr, Double> getCard = (a, b) -> {
347-
// ensure a‐>map exists
348349
Map<TupleExpr, Double> inner = cardCache.computeIfAbsent(a, k -> new HashMap<>());
349-
// cache symmetric result too
350-
return inner.computeIfAbsent(b, bb -> {
351-
double c = statistics.getCardinality(new Join(a, b));
352-
// also store in b’s map for symmetry (optional)
353-
cardCache.computeIfAbsent(b, k -> new HashMap<>()).put(a, c);
354-
return c;
355-
});
350+
Double cached = inner.get(b);
351+
if (cached != null) {
352+
return cached;
353+
}
354+
double c = statistics.getCardinality(new Join(a, b));
355+
inner.put(b, c);
356+
cardCache.computeIfAbsent(b, k -> new HashMap<>()).put(a, c);
357+
return c;
356358
};
357359

358360
while (!tupleExprs.isEmpty()) {

0 commit comments

Comments
 (0)