Skip to content

Commit 8fe701c

Browse files
authored
SkipBlockRangeIterator should report docCount as its cost (#16352)
Currently it returns DocIdSetIterator.NO_MORE_DOCS, meaning that it will compare as more costly to almost any other iterator and never be used to drive iteration in conjunctions, even against expensive two-phase queries that report max_doc as their cost.
1 parent 38c1036 commit 8fe701c

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ Optimizations
323323
* GITHUB#16283: Use Panama Vector API to SIMD-evaluate fixed-cardinality sorted numeric range queries in
324324
rangeIntoBitSet. (Costin Leau)
325325

326+
* GITHUB#16352: Better cost() estimation for SkipBlockRangeIterator. (Alan Woodward)
327+
326328
Bug Fixes
327329
---------------------
328330

lucene/core/src/java/org/apache/lucene/search/SkipBlockRangeIterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public Match getMatch() {
108108

109109
@Override
110110
public long cost() {
111-
return DocIdSetIterator.NO_MORE_DOCS;
111+
return skipper.docCount();
112112
}
113113

114114
/**

lucene/core/src/test/org/apache/lucene/search/TestSkipBlockRangeIterator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,10 @@ public void testIntoBitSet() throws Exception {
5454

5555
assertEquals(expected, bitSet);
5656
}
57+
58+
public void testCost() {
59+
DocValuesSkipper skipper = docValuesSkipper(1, 30, random().nextBoolean());
60+
SkipBlockRangeIterator it = new SkipBlockRangeIterator(skipper, 1, 30);
61+
assertEquals(DENSE_END + (MAX_DOC - DENSE_END) / 2, it.cost());
62+
}
5763
}

0 commit comments

Comments
 (0)