diff options
author | Ian Boros <puppyofkosh@gmail.com> | 2019-02-11 16:39:51 -0500 |
---|---|---|
committer | Ian Boros <puppyofkosh@gmail.com> | 2019-02-14 16:02:29 -0500 |
commit | 34a1ce6a681e2637d3c29a49a9412efe63821178 (patch) | |
tree | 6ee938976f24167e9855c387dfdb3763980157d4 /src/mongo/db/query/query_planner_test.cpp | |
parent | 6f4155b0fb8b4e93ea09afdd397f5b391d7fd99a (diff) | |
download | mongo-34a1ce6a681e2637d3c29a49a9412efe63821178.tar.gz |
SERVER-38949 ban index usage for {$ne: <array>} queries
Diffstat (limited to 'src/mongo/db/query/query_planner_test.cpp')
-rw-r--r-- | src/mongo/db/query/query_planner_test.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp index aa162aa97f6..8e8cfb6d2bb 100644 --- a/src/mongo/db/query/query_planner_test.cpp +++ b/src/mongo/db/query/query_planner_test.cpp @@ -3017,6 +3017,71 @@ TEST_F(QueryPlannerTest, NegationElemMatchObject2) { assertSolutionExists("{cscan: {dir: 1}}"); } +// Negated $eq: <Array> won't use the index. +TEST_F(QueryPlannerTest, NegationEqArray) { + addIndex(BSON("i" << 1)); + runQuery(fromjson("{i: {$not: {$eq: [1, 2]}}}")); + + assertHasOnlyCollscan(); +} + +// If we negate a $in and any of the members of the $in equalities +// is an array, we don't use the index. +TEST_F(QueryPlannerTest, NegationInArray) { + addIndex(BSON("i" << 1)); + runQuery(fromjson("{i: {$not: {$in: [1, [1, 2]]}}}")); + + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, ElemMatchValueNegationEqArray) { + addIndex(BSON("i" << 1)); + runQuery(fromjson("{i: {$elemMatch: {$not: {$eq: [1]}}}}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, ElemMatchValueNegationInArray) { + addIndex(BSON("i" << 1)); + runQuery(fromjson("{i: {$elemMatch: {$not: {$in: [[1]]}}}}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, NegatedElemMatchValueEqArray) { + addIndex(BSON("i" << 1)); + runQuery(fromjson("{i: {$not: {$elemMatch: {$eq: [1]}}}}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, NegatedElemMatchValueInArray) { + addIndex(BSON("i" << 1)); + runQuery(fromjson("{i: {$not: {$elemMatch: {$in: [[1]]}}}}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, ElemMatchObjectNegationEqArray) { + addIndex(BSON("i.j" << 1)); + runQuery(fromjson("{i: {$elemMatch: {j: {$ne: [1]}}}}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, ElemMatchObjectNegationInArray) { + addIndex(BSON("i.j" << 1)); + runQuery(fromjson("{i: {$elemMatch: {j: {$not: {$in: [[1]]}}}}}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, NegatedElemMatchObjectEqArray) { + addIndex(BSON("i.j" << 1)); + runQuery(fromjson("{i: {$not: {$elemMatch: {j: [1]}}}}")); + assertHasOnlyCollscan(); +} + +TEST_F(QueryPlannerTest, NegatedElemMatchObjectInArray) { + addIndex(BSON("i.j" << 1)); + runQuery(fromjson("{i: {$not: {$elemMatch: {j: {$in: [[1]]}}}}}")); + assertHasOnlyCollscan(); +} + // If there is a negation that can't use the index, // ANDed with a predicate that can use the index, then // we can still use the index for the latter predicate. |