diff options
author | David Storch <david.storch@10gen.com> | 2014-09-18 11:37:06 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2014-09-18 16:58:22 -0400 |
commit | fcd31bd4dcf1debcef9e8edc5643378757174d10 (patch) | |
tree | 7c5095b2fd69a63c579c613da640b0d9f286d909 | |
parent | aff4ae5f1da121fb94f01cb4e278a4596ec7856a (diff) | |
download | mongo-fcd31bd4dcf1debcef9e8edc5643378757174d10.tar.gz |
SERVER-15286 don't try to explode for sort if zero fields to explode
(cherry picked from commit 55415503b722848d51fe45fc2de2d47cee4db952)
-rw-r--r-- | src/mongo/db/query/planner_analysis.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/query/query_planner_test.cpp | 22 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp index ce54be01cde..9342fc29236 100644 --- a/src/mongo/db/query/planner_analysis.cpp +++ b/src/mongo/db/query/planner_analysis.cpp @@ -306,6 +306,11 @@ namespace mongo { return false; } + // Only explode if there's at least one field to explode for this scan. + if (0 == boundsIdx) { + return false; + } + // The rest of the fields define the sort order we could obtain by exploding // the bounds. BSONObjBuilder resultingSortBob; diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp index b7ab829a738..434b363f81e 100644 --- a/src/mongo/db/query/query_planner_test.cpp +++ b/src/mongo/db/query/query_planner_test.cpp @@ -2323,6 +2323,28 @@ namespace { "{ixscan: {pattern: {d: 1, c: 1}}}]}}}}}}"); } + // SERVER-15286: Make sure that at least the explodeForSort() path bails out + // when it finds that there are no union of point interval fields to explode. + // We could convert this into a MERGE_SORT plan, but we don't yet do this + // optimization. + TEST_F(QueryPlannerTest, CantExplodeOrForSort2) { + addIndex(BSON("a" << 1)); + + runQuerySortProj(fromjson("{$or: [{a: {$gt: 1, $lt: 3}}, {a: {$gt: 6, $lt: 10}}]}"), + BSON("a" << -1), + BSONObj()); + + assertNumSolutions(3U); + assertSolutionExists("{sort: {pattern: {a: -1}, limit: 0, node: {cscan: {dir: 1}}}}"); + assertSolutionExists("{fetch: {node: {ixscan: {pattern: {a: 1}}}}}"); + assertSolutionExists("{sort: {pattern: {a: -1}, limit: 0, node: " + "{fetch: {filter: null, node: {or: {nodes: [" + "{ixscan: {pattern: {a: 1}, bounds: " + "{a: [[1,3,false,false]]}}}," + "{ixscan: {pattern: {a: 1}, bounds: " + "{a: [[6,10,false,false]]}}}]}}}}}}"); + } + // SERVER-13754: too many scans in an $or explosion. TEST_F(QueryPlannerTest, TooManyToExplodeOr) { addIndex(BSON("a" << 1 << "e" << 1)); |