summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_array.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher/expression_array.cpp')
-rw-r--r--src/mongo/db/matcher/expression_array.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_array.cpp b/src/mongo/db/matcher/expression_array.cpp
index b80e321b976..84c544df2bf 100644
--- a/src/mongo/db/matcher/expression_array.cpp
+++ b/src/mongo/db/matcher/expression_array.cpp
@@ -108,6 +108,14 @@ void ElemMatchObjectMatchExpression::serialize(BSONObjBuilder* out) const {
out->append(path(), BSON("$elemMatch" << subBob.obj()));
}
+MatchExpression::ExpressionOptimizerFunc ElemMatchObjectMatchExpression::getOptimizer() const {
+ return [](std::unique_ptr<MatchExpression> expression) {
+ auto& elemExpression = static_cast<ElemMatchObjectMatchExpression&>(*expression);
+ elemExpression._sub = MatchExpression::optimize(std::move(elemExpression._sub));
+
+ return expression;
+ };
+}
// -------
@@ -184,6 +192,19 @@ void ElemMatchValueMatchExpression::serialize(BSONObjBuilder* out) const {
out->append(path(), BSON("$elemMatch" << emBob.obj()));
}
+MatchExpression::ExpressionOptimizerFunc ElemMatchValueMatchExpression::getOptimizer() const {
+ return [](std::unique_ptr<MatchExpression> expression) {
+ auto& subs = static_cast<ElemMatchValueMatchExpression&>(*expression)._subs;
+
+ for (MatchExpression*& subExpression : subs) {
+ auto optimizedSubExpression =
+ MatchExpression::optimize(std::unique_ptr<MatchExpression>(subExpression));
+ subExpression = optimizedSubExpression.release();
+ }
+
+ return expression;
+ };
+}
// ---------