Disable sort optimization when index is sorted (#49727)

Don't run long sort optimization when index is already
sorted on the same field as the sort query parameter.

Relates to #37043, follow up for  #48804
This commit is contained in:
Mayya Sharipova 2019-12-02 17:01:30 -05:00
parent ad274dd797
commit 3bbaa01764
1 changed files with 4 additions and 0 deletions

View File

@ -413,6 +413,10 @@ public class QueryPhase implements SearchPhase {
if (searchContext.collapse() != null) return null;
if (searchContext.trackScores()) return null;
if (searchContext.aggregations() != null) return null;
if (canEarlyTerminate(reader, searchContext.sort())) {
// disable this optimization if index sorting matches the query sort since it's already optimized by index searcher
return null;
}
Sort sort = searchContext.sort().sort;
SortField sortField = sort.getSort()[0];
if (SortField.Type.LONG.equals(IndexSortConfig.getSortFieldType(sortField)) == false) return null;