summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSvilen Mihaylov <svilen.mihaylov@mongodb.com>2022-09-01 13:47:15 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-01 14:24:35 +0000
commitab2d5005886706ebcb3f267181328f00f1707ceb (patch)
tree0c8287c2ec41e656e6dbea314597c8d9187ebd21
parentf90cd684ed7e314875b40094c377cfe25e655635 (diff)
downloadmongo-ab2d5005886706ebcb3f267181328f00f1707ceb.tar.gz
SERVER-69287 [CQF] Support $expr in find
-rw-r--r--jstests/cqf/match_expr.js34
-rw-r--r--src/mongo/db/pipeline/abt/canonical_query_translation.cpp6
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));