summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/query_planner_index_test.cpp
diff options
context:
space:
mode:
authorJess Balint <jbalint@gmail.com>2022-02-22 22:39:19 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-22 23:32:44 +0000
commit54b918d73c63483faecedb807722a707ba0e64c2 (patch)
tree2b92e04f078c82e63a02f6c37285b3be222c8a47 /src/mongo/db/query/query_planner_index_test.cpp
parent6be53022af440793953d1e39725f38b728bcb155 (diff)
downloadmongo-54b918d73c63483faecedb807722a707ba0e64c2.tar.gz
SERVER-40691 $nin:[[],...] queries are not indexed #3420
Diffstat (limited to 'src/mongo/db/query/query_planner_index_test.cpp')
-rw-r--r--src/mongo/db/query/query_planner_index_test.cpp57
1 files changed, 57 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 7e043a7d795..045fa35dbe1 100644
--- a/src/mongo/db/query/query_planner_index_test.cpp
+++ b/src/mongo/db/query/query_planner_index_test.cpp
@@ -248,6 +248,63 @@ 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, false],"
+ "[null, [], false, false],"
+ "[[], '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, false],"
+ "[null, [], false, false],"
+ "[[], '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, NotLtEmptyArrayShouldNotUseIndex) {
+ addIndex(fromjson("{a: 1}"), true);
+ runQuery(fromjson("{a: { $not: { $lt: [] } } }"));
+ assertHasOnlyCollscan();
+}
+
TEST_F(QueryPlannerTest, SparseIndexCannotSupportEqualsNull) {
addIndex(BSON("i" << 1),
false, // multikey