diff options
Diffstat (limited to 'src/mongo/db/query/planner_analysis.cpp')
-rw-r--r-- | src/mongo/db/query/planner_analysis.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp index 3c4b601d1aa..ab8698c4e43 100644 --- a/src/mongo/db/query/planner_analysis.cpp +++ b/src/mongo/db/query/planner_analysis.cpp @@ -542,6 +542,20 @@ bool QueryPlannerAnalysis::explodeForSort(const CanonicalQuery& query, } } + // An index whose collation does not match the query's cannot provide a sort if sort-by + // fields can contain collatable values. + if (!CollatorInterface::collatorsMatch(isn->index.collator, query.getCollator())) { + auto fieldsWithStringBounds = + IndexScanNode::getFieldsWithStringBounds(bounds, isn->index.keyPattern); + for (auto&& element : desiredSort) { + if (fieldsWithStringBounds.count(element.fieldNameStringData()) > 0) { + // The field can contain collatable values and therefore we cannot use the index + // to provide the sort. + return false; + } + } + } + // Do some bookkeeping to see how many ixscans we'll create total. totalNumScans += numScans; |