Skip to content
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

Merged

Conversation

mayya-sharipova
Copy link
Contributor

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 elastic#56923
@mayya-sharipova mayya-sharipova added the :Search/Search Search-related issues that do not fall into other categories label May 21, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

Copy link
Contributor

@jtibshirani jtibshirani left a 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)));
Copy link
Contributor

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?

Copy link
Contributor Author

@mayya-sharipova mayya-sharipova May 21, 2020

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks.

@mayya-sharipova mayya-sharipova merged commit bdfb137 into elastic:master May 21, 2020
@mayya-sharipova mayya-sharipova deleted the sort-optimization-size0 branch May 21, 2020 18:49
mayya-sharipova added a commit that referenced this pull request May 21, 2020
Sort optimization creates TopFieldCollector that errors
when size=0. This ensures that sort optimization is not
run when size=0.

Closes #56923
mayya-sharipova added a commit that referenced this pull request May 21, 2020
Sort optimization creates TopFieldCollector that errors
when size=0. This ensures that sort optimization is not
run when size=0.

Closes #56923
mayya-sharipova added a commit that referenced this pull request May 21, 2020
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) {
Copy link

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.7.1 v7.8.1 v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search can fail when size is 0 and long sort optimization enabled.
5 participants