diff --git a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java index a2329555460..aeb474422a9 100644 --- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java @@ -387,15 +387,18 @@ public abstract class PointRangeQuery extends Query { return 0; } - if (reader.hasDeletions() == false - && numDims == 1 - && values.getDocCount() == values.size()) { - // if all documents have at-most one point + if (reader.hasDeletions() == false) { if (relate(values.getMinPackedValue(), values.getMaxPackedValue()) == Relation.CELL_INSIDE_QUERY) { return values.getDocCount(); } - return (int) pointCount(values.getPointTree(), this::relate, this::matches); + // only 1D: we have the guarantee that it will actually run fast since there are at most 2 + // crossing leaves. + // docCount == size : counting according number of points in leaf node, so must be + // single-valued. + if (numDims == 1 && values.getDocCount() == values.size()) { + return (int) pointCount(values.getPointTree(), this::relate, this::matches); + } } return super.count(context); }