diff options
author | Mihai Andrei <mihai.andrei@10gen.com> | 2022-04-22 14:29:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-22 14:59:06 +0000 |
commit | 0a16e785f7016c92fb3357377ef2d6d50db3ffc9 (patch) | |
tree | 90600534ec4f0c8aa3d32a4bb847f6a1557a8b12 | |
parent | e2409b8fe098383a18ad98eda9ae176fa9d05779 (diff) | |
download | mongo-0a16e785f7016c92fb3357377ef2d6d50db3ffc9.tar.gz |
SERVER-65665 Disallow the use of indexes with partial filter expressions in INLJ (cherry picked from commit b02798f3032ff6df56a45b4bcb9296b247c37be4)
-rw-r--r-- | jstests/noPassthrough/lookup_pushdown.js | 10 | ||||
-rw-r--r-- | src/mongo/db/query/planner_analysis.cpp | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/jstests/noPassthrough/lookup_pushdown.js b/jstests/noPassthrough/lookup_pushdown.js index 1f91a4abecf..b14ab066437 100644 --- a/jstests/noPassthrough/lookup_pushdown.js +++ b/jstests/noPassthrough/lookup_pushdown.js @@ -306,6 +306,16 @@ function setLookupPushdownDisabled(value) { assert.commandWorked(foreignColl.dropIndexes()); })(); +// Construct an index with a partial filter expression. In this case, we should NOT use INLJ. +(function testPartialFilterExpressionIndexesAreIgnored() { + assert.commandWorked(foreignColl.dropIndexes()); + assert.commandWorked(foreignColl.createIndex({b: 1}, {partialFilterExpression: {b: 1}})); + runTest(coll, + [{$lookup: {from: foreignCollName, localField: "a", foreignField: "b", as: "out"}}], + JoinAlgorithm.NLJ /* expectedJoinAlgorithm */); + assert.commandWorked(foreignColl.dropIndexes()); +})(); + // Build a hashed index on the foreign collection that matches the foreignField. Indexed nested loop // join strategy should be used. (function testIndexNestedLoopJoinHashedIndex() { diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp index 654fa0f56ca..af4777dc0e2 100644 --- a/src/mongo/db/query/planner_analysis.cpp +++ b/src/mongo/db/query/planner_analysis.cpp @@ -662,7 +662,7 @@ void QueryPlannerAnalysis::determineLookupStrategy( if ((index.type == INDEX_BTREE || index.type == INDEX_HASHED) && index.keyPattern.firstElement().fieldName() == eqLookupNode->joinFieldForeign.fullPath() && - CollatorInterface::collatorsMatch(collator, index.collator)) { + !index.filterExpr && CollatorInterface::collatorsMatch(collator, index.collator)) { return index; } } |