diff options
author | David Storch <david.storch@10gen.com> | 2015-01-16 16:52:50 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-01-22 11:27:09 -0500 |
commit | 28b9b81eba5b79f1f83404d2220668fcbacd1aec (patch) | |
tree | 3f1451eddc0ba2384376c93abaa1f92ace891865 | |
parent | e367a48c7ff9eca187712fcfba1322c37af69780 (diff) | |
download | mongo-28b9b81eba5b79f1f83404d2220668fcbacd1aec.tar.gz |
SERVER-16655 do not strip index tags from geo predicates during planning for V2 2dsphere indices
(cherry picked from commit 22ee5a4e87131a2b3791845c96edf4cde5028ba2)
-rw-r--r-- | src/mongo/db/query/planner_ixselect.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/query/query_planner_test.cpp | 31 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp index bb23e7c2f3d..f2c9aeeb237 100644 --- a/src/mongo/db/query/planner_ixselect.cpp +++ b/src/mongo/db/query/planner_ixselect.cpp @@ -542,7 +542,11 @@ namespace mongo { size_t idx, const unordered_set<StringData, StringData::Hasher>& geoFields) { - if (Indexability::nodeCanUseIndexOnOwnField(node)) { + if (Indexability::nodeCanUseIndexOnOwnField(node) + && MatchExpression::GEO != node->matchType() + && MatchExpression::GEO_NEAR != node->matchType()) { + // We found a non-geo predicate tagged to use a V2 2dsphere index which is not + // and-related to a geo predicate that can use the index. removeIndexRelevantTag(node, idx); return; } diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp index 1758274bb39..883b98033a0 100644 --- a/src/mongo/db/query/query_planner_test.cpp +++ b/src/mongo/db/query/query_planner_test.cpp @@ -4341,6 +4341,37 @@ namespace { ASSERT_EQUALS(getNumSolutions(), 1U); } + TEST_F(QueryPlannerTest, TwoDSphereSparseV2BelowOr) { + params.options = QueryPlannerParams::NO_TABLE_SCAN; + + addIndex(BSON("geo1" << "2dsphere" << "a" << 1 << "b" << 1), + BSON("2dsphereIndexVersion" << 2)); + addIndex(BSON("geo2" << "2dsphere" << "a" << 1 << "b" << 1), + BSON("2dsphereIndexVersion" << 2)); + + runQuery(fromjson("{a: 4, b: 5, $or: [" + "{geo1: {$geoWithin: {$centerSphere: [[10, 20], 0.01]}}}," + "{geo2: {$geoWithin: {$centerSphere: [[10, 20], 0.01]}}}]}")); + + assertNumSolutions(1U); + assertSolutionExists("{fetch: {filter: {a: 4, b: 5}, node: {or: {nodes: [" + "{fetch: {node: {ixscan: {pattern: {geo1:'2dsphere',a:1,b:1}}}}}," + "{fetch: {node: {ixscan: {pattern: {geo2:'2dsphere',a:1,b:1}}}}}" + "]}}}}"); + } + + TEST_F(QueryPlannerTest, TwoDSphereSparseV2BelowElemMatch) { + params.options = QueryPlannerParams::NO_TABLE_SCAN; + addIndex(BSON("a.b" << "2dsphere" << "a.c" << 1), + BSON("2dsphereIndexVersion" << 2)); + + runQuery(fromjson("{a: {$elemMatch: {b: {$geoWithin: {$centerSphere: [[10,20], 0.01]}}," + "c: {$gt: 3}}}}")); + + assertNumSolutions(1U); + assertSolutionExists("{fetch: {node: {ixscan: {pattern: {'a.b': '2dsphere', 'a.c': 1}}}}}"); + } + // // Test that we add a KeepMutations when we should and and we don't add one when we shouldn't. // |