diff options
author | David Storch <david.storch@10gen.com> | 2017-11-08 10:23:21 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2017-11-10 10:12:52 -0500 |
commit | 69ab9781d7a646a6029e5c46d340685e80e404fa (patch) | |
tree | e766e96057dbcc3f191dc28f1f8ff228d851aba6 /src/mongo/db/query/planner_analysis.cpp | |
parent | bf53cbe298bc6724b1f2b5bf16afbd9e3876c623 (diff) | |
download | mongo-69ab9781d7a646a6029e5c46d340685e80e404fa.tar.gz |
SERVER-31858 Fix explodeForSort() path to handle multikeyness correctly.
Diffstat (limited to 'src/mongo/db/query/planner_analysis.cpp')
-rw-r--r-- | src/mongo/db/query/planner_analysis.cpp | 14 |
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. |