-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't run sort optimization on size=0 #57044
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -703,6 +703,23 @@ public void testNumericLongOrDateSortOptimization() throws Exception { | |
searchContext.sort(sortAndFormats); | ||
QueryPhase.executeInternal(searchContext); | ||
assertSortResults(searchContext.queryResult().topDocs().topDocs, (long) numDocs, true); | ||
|
||
// 5. Test that sort optimization is NOT run with size 0 | ||
{ | ||
sortAndFormats = new SortAndFormats(longSort, new DocValueFormat[]{DocValueFormat.RAW}); | ||
searchContext = spy(new TestSearchContext(null, indexShard, newContextSearcher(reader))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering why we use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jtibshirani Thanks for the review. I am using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks. |
||
when(searchContext.mapperService()).thenReturn(mapperService); | ||
searchContext.sort(sortAndFormats); | ||
searchContext.parsedQuery(new ParsedQuery(new MatchAllDocsQuery())); | ||
searchContext.setTask(new SearchShardTask(123L, "", "", "", null, Collections.emptyMap())); | ||
searchContext.setSize(0); | ||
|
||
QueryPhase.executeInternal(searchContext); | ||
TotalHits totalHits = searchContext.queryResult().topDocs().topDocs.totalHits; | ||
assertEquals(TotalHits.Relation.EQUAL_TO, totalHits.relation); | ||
assertEquals(numDocs, totalHits.value); | ||
} | ||
|
||
reader.close(); | ||
dir.close(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if 'size' is 0 but 'from' is not, can this case uses sort optimization? if it can, changing this place to "from + size" may be much better.
Feel free about this, just an advice :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyff thanks for pointing this out! It seems unusual to perform a search with
from: n, size: 0
, but I do agree it's more consistent to check 'num hits' (which isfrom + size
) instead of justsize
. @mayya-sharipova what are your thoughts on adjusting this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyff @jtibshirani Thanks for commenting. I have addressed this in #57250