diff options
Diffstat (limited to 'src/mongo/db/query/planner_ixselect_test.cpp')
| -rw-r--r-- | src/mongo/db/query/planner_ixselect_test.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/mongo/db/query/planner_ixselect_test.cpp b/src/mongo/db/query/planner_ixselect_test.cpp index 1df4d714e67..2507e65ce56 100644 --- a/src/mongo/db/query/planner_ixselect_test.cpp +++ b/src/mongo/db/query/planner_ixselect_test.cpp @@ -1333,6 +1333,45 @@ TEST(QueryPlannerIXSelectTest, HashedSparseIndexShouldBeRelevantForExistsTrue) { testRateIndices("{a: {$exists: true}}", "", kSimpleCollator, {entry}, "a", expectedIndices); } +TEST(QueryPlannerIXSelectTest, GeoPredicateCanOnlyUse2dsphereIndex) { + std::vector<IndexEntry> indices; + auto btreeEntry = buildSimpleIndexEntry(BSON("loc" << 1)); + auto twodSphereEntry = buildSimpleIndexEntry(BSON("loc" + << "2dsphere")); + indices.push_back(btreeEntry); + indices.push_back(twodSphereEntry); + std::set<size_t> expectedIndices = {1}; + testRateIndices(R"({loc: {$geoWithin: {$geometry: {type: 'Polygon', + coordinates: [[[0,0],[0,1],[1,0],[0,0]]]}}}})", + "", + kSimpleCollator, + indices, + "loc", + expectedIndices); +} + +TEST(QueryPlannerIXSelectTest, GeoPredicateWithNotCanOnlyUse2dsphereIndex) { + std::vector<IndexEntry> indices; + auto btreeEntry = buildSimpleIndexEntry(BSON("loc" << 1)); + auto twodSphereEntry = buildSimpleIndexEntry(BSON("loc" + << "2dsphere")); + indices.push_back(btreeEntry); + indices.push_back(twodSphereEntry); + // This query gets parsed to {$not: {$and: {$geoWithin: <>}}} and then tags + // the 2dsphere index as relevant. If the $and is optimized away ({$not: {$geoWithin: <>}}), + // that tagging is skipped. + // TODO SERVER-92427: The tagging behavior should be made consistent so that this query has no + // expectedIndices. + std::set<size_t> expectedIndices = {1}; + testRateIndices(R"({loc: {$not: {$geoWithin: {$geometry: {type: 'Polygon', + coordinates: [[[0,0],[0,1],[1,0],[0,0]]]}}}}})", + "", + kSimpleCollator, + indices, + "loc", + expectedIndices); +} + /* * Will compare 'keyPatterns' with 'entries'. As part of comparing, it will sort both of them. */ |
