summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/planner_analysis.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/query/planner_analysis.cpp')
-rw-r--r--src/mongo/db/query/planner_analysis.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp
index 5b72f1c98fa..cd11da91262 100644
--- a/src/mongo/db/query/planner_analysis.cpp
+++ b/src/mongo/db/query/planner_analysis.cpp
@@ -373,6 +373,12 @@ bool QueryPlannerAnalysis::explodeForSort(const CanonicalQuery& query,
return false;
}
+ if (isn->index.multikey && isn->index.multikeyPaths.empty()) {
+ // The index is multikey but has no path-level multikeyness metadata. In this case, the
+ // index can never provide a sort.
+ return false;
+ }
+
// How many scans will we create if we blow up this ixscan?
size_t numScans = 1;
@@ -405,7 +411,13 @@ bool QueryPlannerAnalysis::explodeForSort(const CanonicalQuery& query,
// the bounds.
BSONObjBuilder resultingSortBob;
while (kpIt.more()) {
- resultingSortBob.append(kpIt.next());
+ auto elem = kpIt.next();
+ if (isn->multikeyFields.find(elem.fieldNameStringData()) != isn->multikeyFields.end()) {
+ // One of the indexed fields providing the sort is multikey. It is not correct for a
+ // field with multikey components to provide a sort, so bail out.
+ return false;
+ }
+ resultingSortBob.append(elem);
}
// See if it's the order we're looking for.