diff options
author | Ian Boros <ian.boros@10gen.com> | 2018-09-25 11:01:02 -0400 |
---|---|---|
committer | Ian Boros <ian.boros@10gen.com> | 2018-10-10 14:33:05 -0400 |
commit | 3af0f2a6053a7385b89149adce16a23b88cf9be7 (patch) | |
tree | e73e130035bc2cd16df6f10b690748b53e8d89d2 /src/mongo/db/query/query_planner_wildcard_index_test.cpp | |
parent | 92fd23c5696b7fb6ede309784596e3408b39b259 (diff) | |
download | mongo-3af0f2a6053a7385b89149adce16a23b88cf9be7.tar.gz |
SERVER-36465 Support {$ne: null} queries with non-multikey sparse and wildcard indexes
Diffstat (limited to 'src/mongo/db/query/query_planner_wildcard_index_test.cpp')
-rw-r--r-- | src/mongo/db/query/query_planner_wildcard_index_test.cpp | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/mongo/db/query/query_planner_wildcard_index_test.cpp b/src/mongo/db/query/query_planner_wildcard_index_test.cpp index 66c09034a74..5bc23eb2892 100644 --- a/src/mongo/db/query/query_planner_wildcard_index_test.cpp +++ b/src/mongo/db/query/query_planner_wildcard_index_test.cpp @@ -107,13 +107,59 @@ TEST_F(QueryPlannerWildcardTest, EqualsNullQueriesDontUseWildcardIndexes) { assertSolutionExists("{cscan: {dir: 1}}"); } -TEST_F(QueryPlannerWildcardTest, NotEqualsNullQueriesDontUseWildcardIndexes) { +TEST_F(QueryPlannerWildcardTest, NotEqualsNullQueriesUseWildcardIndexes) { addIndex(BSON("$**" << 1)); runQuery(fromjson("{x: {$ne: null}}")); assertNumSolutions(1U); - assertSolutionExists("{cscan: {dir: 1}}"); + assertSolutionExists( + "{fetch: {filter: {x: {$ne: null}}, node: {ixscan: {pattern: {$_path: 1, x: 1}," + "bounds: {'$_path': [['x','x',true,true], ['x.','x/',true,false]]," + "x: [['MinKey','MaxKey',true,true]]}}}}}"); +} + +TEST_F(QueryPlannerWildcardTest, NotEqualsNullQueriesDoNotUseWildcardIndexesWhenMultiKey) { + addWildcardIndex(BSON("$**" << 1), {"x"}); + + runQuery(fromjson("{'x': {$ne: null}}")); + + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerWildcardTest, NotEqualsNullInElemMatchQueriesUseWildcardIndexesWhenMultiKey) { + addWildcardIndex(BSON("$**" << 1), {"x"}); + + runQuery(fromjson("{'x': {$elemMatch: {$ne: null}}}")); + + assertNumSolutions(1U); + assertSolutionExists( + "{fetch: {node: {ixscan: {pattern: {$_path: 1, 'x': 1}," + "bounds: {'$_path': [['x','x',true,true], ['x.','x/',true,false]]," + "'x': [['MinKey', 'MaxKey',true,true]]}}}}}"); +} + +TEST_F(QueryPlannerWildcardTest, NotEqualsNullInElemMatchObjectSparseMultiKeyAboveElemMatch) { + addWildcardIndex(BSON("$**" << 1), {"a", "a.b"}); + + runQuery(fromjson("{'a.b': {$elemMatch: {'c.d': {$ne: null}}}}")); + + assertNumSolutions(1U); + assertSolutionExists( + "{fetch: {node: {ixscan: {pattern: {'$_path': 1, 'a.b.c.d': 1}," + "bounds: {'$_path': [['a.b.c.d','a.b.c.d',true,true], ['a.b.c.d.','a.b.c.d/',true,false]]," + "'a.b.c.d': [['MinKey', 'MaxKey', true, true]]" + "}}}}}"); +} + +TEST_F(QueryPlannerWildcardTest, NotEqualsNullInElemMatchObjectSparseMultiKeyBelowElemMatch) { + // "a.b.c" being multikey will prevent us from using the index since $elemMatch doesn't do + // implicit array traversal. + addWildcardIndex(BSON("$**" << 1), {"a.b.c"}); + + runQuery(fromjson("{'a.b': {$elemMatch: {'c.d': {$ne: null}}}}")); + + assertHasOnlyCollscan(); } TEST_F(QueryPlannerWildcardTest, NotEqualsNullAndExistsQueriesUseWildcardIndexes) { |