Skip to content

Commit e32f535

Browse files
committed
Merge remote-tracking branch 'romseygeek/bug/sort-still-slow' into bug/sort-still-slow
2 parents cb9a7f5 + 0e0e392 commit e32f535

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

server/src/main/java/org/elasticsearch/lucene/comparators/XNumericComparator.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,12 @@ protected int docCount() {
357357
* @throws IOException i/o exception while fetching min and max values from point values
358358
*/
359359
void postInitializeCompetitiveIterator() throws IOException {
360-
if (queueFull) {
360+
if (queueFull && hitsThresholdReached) {
361+
// if some documents have missing doc values, check that missing values prohibits
362+
// optimization
363+
if (docCount() < maxDoc && isMissingValueCompetitive()) {
364+
return;
365+
}
361366
long bottom = leafComparator.bottomAsComparableLong();
362367
long minValue = sortableBytesToLong(pointValues.getMinPackedValue());
363368
long maxValue = sortableBytesToLong(pointValues.getMaxPackedValue());
@@ -509,7 +514,12 @@ protected int docCount() {
509514
* iterator as competitive iterator.
510515
*/
511516
void postInitializeCompetitiveIterator() {
512-
if (queueFull) {
517+
if (queueFull && hitsThresholdReached) {
518+
// if some documents have missing doc values, check that missing values prohibits
519+
// optimization
520+
if (docCount() < maxDoc && isMissingValueCompetitive()) {
521+
return;
522+
}
513523
long bottom = leafComparator.bottomAsComparableLong();
514524
if (reverse == false && bottom < skipper.minValue()) {
515525
competitiveIterator.update(DocIdSetIterator.empty());

0 commit comments

Comments
 (0)