Skip to content

Commit 2dc1202

Browse files
committed
Bypass competitive iteration in single filter bucket case
1 parent 12451b6 commit 2dc1202

File tree

1 file changed

+3
-50
lines changed

1 file changed

+3
-50
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FiltersAggregator.java

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.lucene.index.LeafReaderContext;
1313
import org.apache.lucene.search.DisiPriorityQueue;
1414
import org.apache.lucene.search.DisiWrapper;
15-
import org.apache.lucene.search.DisjunctionDISIApproximation;
1615
import org.apache.lucene.search.DocIdSetIterator;
1716
import org.apache.lucene.search.LeafCollector;
1817
import org.apache.lucene.search.Scorable;
@@ -313,10 +312,9 @@ protected LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCt
313312
// and the cost of per-filter doc iterator is smaller than maxDoc, indicating that there are docs matching the main
314313
// query but not the filter query.
315314
final boolean hasOtherBucket = otherBucketKey != null;
316-
final boolean usesCompetitiveIterator = (parent == null
317-
&& hasOtherBucket == false
318-
&& filterWrappers.isEmpty() == false
319-
&& totalCost < aggCtx.getLeafReaderContext().reader().maxDoc());
315+
// TODO: https://github.com/elastic/elasticsearch/issues/126955
316+
// competitive iterator is currently broken, we would rather be slow than broken
317+
final boolean usesCompetitiveIterator = false;
320318

321319
if (filterWrappers.size() == 1) {
322320
return new SingleFilterLeafCollector(
@@ -329,12 +327,7 @@ protected LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCt
329327
);
330328
}
331329
// TODO: https://github.com/elastic/elasticsearch/issues/126955
332-
// competitive iterator is currently broken, we would rather be slow than broken
333330
return new MultiFilterLeafCollector(sub, filterWrappers, numFilters, totalNumKeys, hasOtherBucket);
334-
// if (usesCompetitiveIterator) {
335-
// return new MultiFilterCompetitiveLeafCollector(sub, filterWrappers, numFilters, totalNumKeys, hasOtherBucket);
336-
// } else {
337-
// }
338331
}
339332
}
340333

@@ -458,46 +451,6 @@ public DocIdSetIterator competitiveIterator() {
458451
}
459452
}
460453

461-
private final class MultiFilterCompetitiveLeafCollector extends AbstractLeafCollector {
462-
463-
private final DisjunctionDISIApproximation disjunctionDisi;
464-
465-
MultiFilterCompetitiveLeafCollector(
466-
LeafBucketCollector sub,
467-
List<FilterMatchingDisiWrapper> filterWrappers,
468-
int numFilters,
469-
int totalNumKeys,
470-
boolean hasOtherBucket
471-
) {
472-
super(sub, numFilters, totalNumKeys, true, hasOtherBucket);
473-
assert filterWrappers.isEmpty() == false;
474-
disjunctionDisi = DisjunctionDISIApproximation.of(filterWrappers, Long.MAX_VALUE);
475-
}
476-
477-
public void collect(int doc, long bucket) throws IOException {
478-
boolean matched = false;
479-
int target = disjunctionDisi.advance(doc);
480-
if (target == doc) {
481-
for (DisiWrapper w = disjunctionDisi.topList(); w != null; w = w.next) {
482-
FilterMatchingDisiWrapper topMatch = (FilterMatchingDisiWrapper) w;
483-
if (topMatch.checkDocForMatch(doc)) {
484-
collectBucket(sub, doc, bucketOrd(bucket, topMatch.filterOrd));
485-
matched = true;
486-
}
487-
}
488-
}
489-
490-
if (hasOtherBucket && false == matched) {
491-
collectBucket(sub, doc, bucketOrd(bucket, numFilters));
492-
}
493-
}
494-
495-
@Override
496-
public DocIdSetIterator competitiveIterator() {
497-
return disjunctionDisi;
498-
}
499-
}
500-
501454
private static class FilterMatchingDisiWrapper extends DisiWrapper {
502455
final int filterOrd;
503456

0 commit comments

Comments
 (0)