diff options
author | David Storch <david.storch@10gen.com> | 2017-10-10 19:08:11 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2017-10-13 17:58:01 -0400 |
commit | 744738bd23a5aed625dc1eed89851824fcf5e33a (patch) | |
tree | 1dbde58792c15fc42f5d6a064e306c0d6d7a5ab5 /src/mongo/db/query/query_planner_geo_test.cpp | |
parent | 10dbb695223d08dd5a4412e1319228496d606b13 (diff) | |
download | mongo-744738bd23a5aed625dc1eed89851824fcf5e33a.tar.gz |
SERVER-21011 Fix query correctness problem related to covered matching for 2d/text indexes.
The fix ensures that the tightness predicates over the
trailing fields of 2d/text indexes is checked. Predicates
which are INEXACT_FETCH will then get affixed to the FETCH
stage of the plan rather than incorrectly affixed to the
IXSCAN.
Diffstat (limited to 'src/mongo/db/query/query_planner_geo_test.cpp')
-rw-r--r-- | src/mongo/db/query/query_planner_geo_test.cpp | 78 |
1 files changed, 69 insertions, 9 deletions
diff --git a/src/mongo/db/query/query_planner_geo_test.cpp b/src/mongo/db/query/query_planner_geo_test.cpp index a4efc42195b..d9474eddae3 100644 --- a/src/mongo/db/query/query_planner_geo_test.cpp +++ b/src/mongo/db/query/query_planner_geo_test.cpp @@ -240,24 +240,22 @@ TEST_F(QueryPlannerTest, Multikey2DSphereGeoNearReverseCompound) { } TEST_F(QueryPlannerTest, 2DNonNearContainedOr) { - addIndex(BSON("x" << 1 << "a" - << "2d")); + addIndex(BSON("a" + << "2d" + << "x" + << 1)); addIndex(BSON("y" << 1)); runQuery( fromjson("{$and: [{x: 1}, {$or: [{a: {$within: {$polygon: [[0, 0], [0, 1], [1, 0], [0, " "0]]}}}, {y: 1}]}]}")); - assertNumSolutions(3U); + assertNumSolutions(2U); assertSolutionExists( "{fetch: {filter: {x: 1}, node: {or: {nodes: [" - "{ixscan: {pattern: {x: 1, a: '2d'}, bounds: {x: [[1, 1, true, true]]}}}," + "{fetch: {filter: {a: {$within: {$polygon: [[0, 0], [0, 1], [1, 0], [0, 0]]}}}," + "node: {ixscan: {pattern: {a: '2d', x: 1}, filter: {x: 1}}}}}," "{ixscan: {pattern: {y: 1}, bounds: {y: [[1, 1, true, true]]}}}" "]}}}}"); - assertSolutionExists( - "{fetch: {filter: {$or: [{a: {$within: {$polygon: [[0, 0], [0, 1], [1, 0], [0, 0]]}}}, {y: " - "1}]}, node: " - "{ixscan: {pattern: {x: 1, a: '2d'}, bounds: {x: [[1, 1, true, true]], a: [['MinKey', " - "'MaxKey', true, true]]}}}}}"); assertSolutionExists("{cscan: {dir: 1}}}}"); } @@ -1592,4 +1590,66 @@ TEST_F(QueryPlanner2dsphereVersionTest, NegationWithoutGeoPredCannotUseGeoIndex) testMultiple2dsphereIndexVersions(versions, keyPatterns, predicate, solutions); } +TEST_F(QueryPlannerTest, 2dInexactFetchPredicateOverTrailingFieldHandledCorrectly) { + params.options = QueryPlannerParams::NO_TABLE_SCAN; + + addIndex(BSON("a" + << "2d" + << "b" + << 1)); + + runQuery(fromjson("{a: {$geoWithin: {$center: [[0, 0], 1]}}, b: {$exists: true}}")); + assertNumSolutions(1U); + assertSolutionExists( + "{fetch: {filter: {a: {$geoWithin: {$center: [[0, 0], 1]}}, b: {$exists: true}}, node: " + "{ixscan: {filter: null, pattern: {a: '2d', b: 1}}}}}"); +} + +TEST_F(QueryPlannerTest, 2dInexactFetchPredicateOverTrailingFieldHandledCorrectlyMultikey) { + params.options = QueryPlannerParams::NO_TABLE_SCAN; + + const bool multikey = true; + addIndex(BSON("a" + << "2d" + << "b" + << 1), + multikey); + + runQuery(fromjson("{a: {$geoWithin: {$center: [[0, 0], 1]}}, b: {$exists: true}}")); + assertNumSolutions(1U); + assertSolutionExists( + "{fetch: {filter: {a: {$geoWithin: {$center: [[0, 0], 1]}}, b: {$exists: true}}, node: " + "{ixscan: {filter: null, pattern: {a: '2d', b: 1}}}}}"); +} + +TEST_F(QueryPlannerTest, 2dNearInexactFetchPredicateOverTrailingFieldHandledCorrectly) { + params.options = QueryPlannerParams::NO_TABLE_SCAN; + + addIndex(BSON("a" + << "2d" + << "b" + << 1)); + + runQuery(fromjson("{a: {$near: [0, 0]}, b: {$exists: true}}")); + assertNumSolutions(1U); + assertSolutionExists( + "{fetch: {filter: {b: {$exists: true}}, node: {geoNear2d: {a: '2d', b: 1}}}}"); +} + +TEST_F(QueryPlannerTest, 2dNearInexactFetchPredicateOverTrailingFieldMultikey) { + params.options = QueryPlannerParams::NO_TABLE_SCAN; + + const bool multikey = true; + addIndex(BSON("a" + << "2d" + << "b" + << 1), + multikey); + + runQuery(fromjson("{a: {$near: [0, 0]}, b: {$exists: true}}")); + assertNumSolutions(1U); + assertSolutionExists( + "{fetch: {filter: {b: {$exists: true}}, node: {geoNear2d: {a: '2d', b: 1}}}}"); +} + } // namespace |