diff options
author | Anton Korshunov <anton.korshunov@mongodb.com> | 2019-10-22 17:25:58 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-22 17:25:58 +0000 |
commit | c76b92dd517a2eb770e4014ca2503b511f3c3e5f (patch) | |
tree | 9c2dc43e196bd901840b9cae9ca12fdad3a9c1db /src/mongo/db | |
parent | 48706d5d2779e16e4f4183bc0fd6343510cb17e0 (diff) | |
download | mongo-c76b92dd517a2eb770e4014ca2503b511f3c3e5f.tar.gz |
SERVER-44065 Call optimize() on ParsedAggregationProjection when building projection executor from AST
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/exec/projection_executor.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/exec/projection_executor_test.cpp | 7 |
2 files changed, 8 insertions, 0 deletions
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<ExpressionContext> expCtx, ProjectionExecutorVisitor<Executor> 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 |