-
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
Don't run sort optimization on size=0 #57044
Conversation
Sort optimization creates TopFieldCollector that errors when size=0. This ensures that sort optimization is not run when size=0. Closes elastic#56923
Pinging @elastic/es-search (:Search/Search) |
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.
Thanks @mayya-sharipova, this looks good to me. I left a question on the testing strategy but it's not critical.
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering why we use a spy
here, if we don't verify the calls after?
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.
@jtibshirani Thanks for the review. I am using spy
here to wrap an instance of searchContext
for it to return a fake mapperService
on the following line of 711. Since we don't have a real node here, I had to create a fake MapperService on line 646.
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.
Got it, thanks.
Sort optimization creates TopFieldCollector that errors when size=0. This ensures that sort optimization is not run when size=0. Closes #56923
Sort optimization creates TopFieldCollector that errors when size=0. This ensures that sort optimization is not run when size=0. Closes #56923
Sort optimization creates TopFieldCollector that errors when size=0. This ensures that sort optimization is not run when size=0. Closes #56923
@@ -244,7 +244,7 @@ static boolean executeInternal(SearchContext searchContext) throws QueryPhaseExe | |||
|
|||
CheckedConsumer<List<LeafReaderContext>, IOException> leafSorter = l -> {}; | |||
// try to rewrite numeric or date sort to the optimized distanceFeatureQuery | |||
if ((searchContext.sort() != null) && SYS_PROP_REWRITE_SORT) { | |||
if ((searchContext.sort() != null) && (searchContext.size() > 0) && SYS_PROP_REWRITE_SORT) { |
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 is from + size
) instead of just size
. @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
Sort optimization creates TopFieldCollector that errors
when size=0. This ensures that sort optimization is not
run when size=0.
Closes #56923