diff options
Diffstat (limited to 'src/mongo/db/query/query_planner_index_test.cpp')
-rw-r--r-- | src/mongo/db/query/query_planner_index_test.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/mongo/db/query/query_planner_index_test.cpp b/src/mongo/db/query/query_planner_index_test.cpp index 87bd2d584d1..559afce88b9 100644 --- a/src/mongo/db/query/query_planner_index_test.cpp +++ b/src/mongo/db/query/query_planner_index_test.cpp @@ -157,6 +157,55 @@ TEST_F(QueryPlannerTest, NegationInElemMatchDoesNotUseSparseIndex) { assertHasOnlyCollscan(); } +TEST_F(QueryPlannerTest, NinListWithOnlyNullAndEmptyArrayShouldUseMultikeyIndex) { + params.options = QueryPlannerParams::NO_TABLE_SCAN; + // Use a multikey index. + addIndex(fromjson("{a: 1}"), true); + runQuery(fromjson("{a: { $nin: [[], null] }}")); + assertNumSolutions(1U); + assertSolutionExists( + "{fetch: {filter: {a: {$not: {$in: [null, []]}}}, node: {ixscan: " + "{pattern: {a: 1}, bounds: " + "{a: [" + "['MinKey', undefined, true, true]," + "[null, 'MaxKey', false, true]" + "]}}}}}"); +} + +TEST_F(QueryPlannerTest, NinListWithOnlyNullAndEmptyArrayShouldUseIndex) { + params.options = QueryPlannerParams::NO_TABLE_SCAN; + // Use an index which is not multikey. + addIndex(fromjson("{a: 1}")); + runQuery(fromjson("{a: { $nin: [[], null] }}")); + assertNumSolutions(1U); + assertSolutionExists( + "{fetch: {node: {ixscan: " + "{pattern: {a: 1}, bounds: " + "{a: [" + "['MinKey', undefined, true, true]," + "[null, 'MaxKey', false, true]" + "]}}}}}"); +} + +TEST_F(QueryPlannerTest, NinListWithNullShouldNotUseIndex) { + addIndex(fromjson("{a: 1}"), true); + runQuery(fromjson("{a: { $nin: [null] }}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, NinListWithRegexCannotUseIndex) { + addIndex(fromjson("{a: 1}"), true); + // This matches the [[], null] pattern but also has a regex. + runQuery(fromjson("{a: { $nin: [[], null, /abc/] }}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, NinListWithNonEmptyArrayShouldNotUseIndex) { + addIndex(fromjson("{a: 1}"), true); + runQuery(fromjson("{a: { $nin: [[], [1]] }}")); + assertHasOnlyCollscan(); +} + TEST_F(QueryPlannerTest, SparseIndexCannotSupportEqualsNull) { addIndex(BSON("i" << 1), false, // multikey |