From c76b92dd517a2eb770e4014ca2503b511f3c3e5f Mon Sep 17 00:00:00 2001 From: Anton Korshunov Date: Tue, 22 Oct 2019 17:25:58 +0000 Subject: SERVER-44065 Call optimize() on ParsedAggregationProjection when building projection executor from AST --- src/mongo/db/exec/projection_executor.cpp | 1 + src/mongo/db/exec/projection_executor_test.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/mongo/db/exec/projection_executor.cpp b/src/mongo/db/exec/projection_executor.cpp index 29192f19547..19a7fd7eb55 100644 --- a/src/mongo/db/exec/projection_executor.cpp +++ b/src/mongo/db/exec/projection_executor.cpp @@ -252,6 +252,7 @@ auto buildProjectionExecutor(boost::intrusive_ptr expCtx, ProjectionExecutorVisitor executorVisitor{&context}; projection_ast::PathTrackingWalker walker{&context, {&executorVisitor}, {}}; projection_ast_walker::walk(&walker, root); + context.data().executor->optimize(); return std::move(context.data().executor); } } // namespace diff --git a/src/mongo/db/exec/projection_executor_test.cpp b/src/mongo/db/exec/projection_executor_test.cpp index 7d3b7410205..a1ac7467510 100644 --- a/src/mongo/db/exec/projection_executor_test.cpp +++ b/src/mongo/db/exec/projection_executor_test.cpp @@ -176,4 +176,11 @@ TEST_F(ProjectionExecutorTest, CanProjectFindSliceAndPositional) { Document{fromjson("{a: {b: [2,3]}, c: [6]}")}, executor->applyTransformation(Document{fromjson("{a: {b: [1,2,3,4]}, c: [5,6,7]}")})); } + +TEST_F(ProjectionExecutorTest, ExecutorOptimizesExpression) { + auto proj = parseWithDefaultPolicies(fromjson("{a: 1, b: {$add: [1, 2]}}")); + auto executor = buildProjectionExecutor(getExpCtx(), &proj, {}); + ASSERT_DOCUMENT_EQ(Document{fromjson("{_id: true, a: true, b: {$const: 3}}")}, + executor->serializeTransformation(boost::none)); +} } // namespace mongo::projection_executor -- cgit v1.2.1