summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-11-03 18:23:00 -0500
committerDavid Storch <david.storch@10gen.com>2014-11-04 11:21:02 -0500
commitdcb68b25fe7351888385cc435f339ada8e8b5e9e (patch)
tree6d9a0773e51cf55a5bae31ceb1ca0ac0bd1b12f8 /src/mongo/db/query
parent159c1ed111216d2aa0ccc7fca4bba07f2058997b (diff)
downloadmongo-dcb68b25fe7351888385cc435f339ada8e8b5e9e.tar.gz
SERVER-15696 don't drop filters while creating a SORT_MERGE plan
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/planner_analysis.cpp5
-rw-r--r--src/mongo/db/query/query_planner_test.cpp20
2 files changed, 25 insertions, 0 deletions
diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp
index 52b081f9ad5..a1ba92b8c70 100644
--- a/src/mongo/db/query/planner_analysis.cpp
+++ b/src/mongo/db/query/planner_analysis.cpp
@@ -203,6 +203,11 @@ namespace mongo {
child->addKeyMetadata = isn->addKeyMetadata;
child->indexIsMultiKey = isn->indexIsMultiKey;
+ // Copy the filter, if there is one.
+ if (isn->filter.get()) {
+ child->filter.reset(isn->filter->shallowClone());
+ }
+
// Create child bounds.
child->bounds.fields.resize(isn->bounds.fields.size());
for (size_t j = 0; j < fieldsToExplode; ++j) {
diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp
index 8467a5a70ff..1762bd49375 100644
--- a/src/mongo/db/query/query_planner_test.cpp
+++ b/src/mongo/db/query/query_planner_test.cpp
@@ -2682,6 +2682,26 @@ namespace {
"{fetch: {node: {ixscan: {pattern: {d: 1, e: 1}}}}}]}}}}");
}
+ // SERVER-15696: Make sure explodeForSort copies filters on IXSCAN stages to all of the
+ // scans resulting from the explode. Regex is the easiest way to have the planner create
+ // an index scan which filters using the index key.
+ TEST_F(QueryPlannerTest, ExplodeIxscanWithFilter) {
+ addIndex(BSON("a" << 1 << "b" << 1));
+
+ runQuerySortProj(fromjson("{$and: [{b: {$regex: 'foo', $options: 'i'}},"
+ "{a: {$in: [1, 2]}}]}"),
+ BSON("b" << 1), BSONObj());
+
+ assertNumSolutions(2U);
+ assertSolutionExists("{sort: {pattern: {b: 1}, limit: 0, node: {cscan: {dir: 1}}}}");
+ assertSolutionExists("{fetch: {node: {mergeSort: {nodes: "
+ "[{ixscan: {pattern: {a:1, b:1},"
+ "filter: {b: {$regex: 'foo', $options: 'i'}}}},"
+ "{ixscan: {pattern: {a:1, b:1},"
+ "filter: {b: {$regex: 'foo', $options: 'i'}}}}]}}}}");
+
+ }
+
TEST_F(QueryPlannerTest, InWithSortAndLimitTrailingField) {
addIndex(BSON("a" << 1 << "b" << -1 << "c" << 1));
runQuerySortProjSkipLimit(fromjson("{a: {$in: [1, 2]}, b: {$gte: 0}}"),