diff options
-rw-r--r-- | jstests/cqf/match_expr.js | 34 | ||||
-rw-r--r-- | src/mongo/db/pipeline/abt/canonical_query_translation.cpp | 6 |
2 files changed, 26 insertions, 14 deletions
diff --git a/jstests/cqf/match_expr.js b/jstests/cqf/match_expr.js index a02cfbffde0..ed2ffcdb426 100644 --- a/jstests/cqf/match_expr.js +++ b/jstests/cqf/match_expr.js @@ -20,20 +20,30 @@ for (let va = 0; va < 5; va++) { } assert.commandWorked(bulk.execute()); +const expr = { + $expr: { + $or: [ + {$and: [{$eq: ["$a", 1]}, {$eq: ["$b", 2]}]}, + {$eq: ["$c", 3]}, + ] + } +}; + +const numExpected = 1 * 5 * 5 + 4 * 1 * 1; + { - const res = t.explain("executionStats").aggregate([{ - $match: { - $expr: { - $or: [ - {$and: [{$eq: ["$a", 1]}, {$eq: ["$b", 2]}]}, - {$eq: ["$c", 3]}, - ] - } - } - }]); + const res = t.explain("executionStats").aggregate([{$match: expr}]); + assert.eq(numExpected, res.executionStats.nReturned); - assert.eq(1 * 5 * 5 + 4 * 1 * 1, res.executionStats.nReturned); + assertValueOnPlanPath("Filter", res, "child.nodeType"); + assertValueOnPlanPath("PhysicalScan", res, "child.child.nodeType"); +} + +{ + const res = t.explain("executionStats").find(expr).finish(); + assert.eq(numExpected, res.executionStats.nReturned); - // TODO: verify translated plan. + assertValueOnPlanPath("Filter", res, "child.nodeType"); + assertValueOnPlanPath("PhysicalScan", res, "child.child.nodeType"); } }()); diff --git a/src/mongo/db/pipeline/abt/canonical_query_translation.cpp b/src/mongo/db/pipeline/abt/canonical_query_translation.cpp index 9501b855053..066f060d81f 100644 --- a/src/mongo/db/pipeline/abt/canonical_query_translation.cpp +++ b/src/mongo/db/pipeline/abt/canonical_query_translation.cpp @@ -41,8 +41,10 @@ ABT translateCanonicalQueryToABT(const Metadata& metadata, ProjectionName scanProjName, ABT initialNode, PrefixId& prefixId) { - auto abt = generateMatchExpression( - canonicalQuery.root(), false /* allowAggExpression */, scanProjName, "match"); + auto abt = generateMatchExpression(canonicalQuery.root(), + true /* allowAggExpression */, + scanProjName, + prefixId.getNextId("match")); abt = make<FilterNode>(make<EvalFilter>(std::move(abt), make<Variable>(scanProjName)), std::move(initialNode)); |