diff options
Diffstat (limited to 'jstests/cqf/project_expr_dependency.js')
-rw-r--r-- | jstests/cqf/project_expr_dependency.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/jstests/cqf/project_expr_dependency.js b/jstests/cqf/project_expr_dependency.js new file mode 100644 index 00000000000..0c3d1510d1b --- /dev/null +++ b/jstests/cqf/project_expr_dependency.js @@ -0,0 +1,26 @@ +(function() { +"use strict"; + +load("jstests/libs/optimizer_utils.js"); // For checkCascadesOptimizerEnabled. +if (!checkCascadesOptimizerEnabled(db)) { + jsTestLog("Skipping test because the optimizer is not enabled"); + return; +} + +const t = db.cqf_project_expr_dependency; +t.drop(); + +for (let i = 0; i < 100; i++) { + assert.commandWorked(t.insert({a1: i, b1: i, c1: i})); +} + +const res = t.explain("executionStats").aggregate([ + {$addFields: {x: '$a1', y: '$b1', z: '$c1'}}, + {$addFields: {a: {$add: ["$x", "$y"]}, b: {$add: ["$y", "$z"]}}}, + {$project: {_id: 0, out: "$b"}} +]); + +// Demonstrate we only need to read "b1" and "c1" from the collection. +const scanNodeProjFieldMap = navigateToPlanPath(res, "child.child.fieldProjectionMap"); +assert.eq(["b1", "c1"], Object.keys(scanNodeProjFieldMap)); +}()); |