diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/matcher/expression_expr.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/matcher/expression_expr.cpp')
| -rw-r--r-- | src/mongo/db/matcher/expression_expr.cpp | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/mongo/db/matcher/expression_expr.cpp b/src/mongo/db/matcher/expression_expr.cpp index 1ce4f0f6954..567039995f6 100644 --- a/src/mongo/db/matcher/expression_expr.cpp +++ b/src/mongo/db/matcher/expression_expr.cpp @@ -77,10 +77,8 @@ Value ExprMatchExpression::evaluateExpression(const MatchableDocument* doc) cons return _expression->evaluate(document, &variables); } -void ExprMatchExpression::serialize(BSONObjBuilder* out, - const SerializationOptions& opts, - bool includePath) const { - *out << "$expr" << _expression->serialize(opts); +void ExprMatchExpression::serialize(BSONObjBuilder* out, bool includePath) const { + *out << "$expr" << _expression->serialize(false); } bool ExprMatchExpression::equivalent(const MatchExpression* other) const { @@ -96,8 +94,8 @@ bool ExprMatchExpression::equivalent(const MatchExpression* other) const { } // TODO SERVER-30982: Add mechanism to allow for checking Expression equivalency. - return ValueComparator().evaluate(_expression->serialize() == - realOther->_expression->serialize()); + return ValueComparator().evaluate(_expression->serialize(false) == + realOther->_expression->serialize(false)); } void ExprMatchExpression::_doSetCollator(const CollatorInterface* collator) { @@ -116,7 +114,7 @@ void ExprMatchExpression::_doSetCollator(const CollatorInterface* collator) { std::unique_ptr<MatchExpression> ExprMatchExpression::shallowClone() const { // TODO SERVER-31003: Replace Expression clone via serialization with Expression::clone(). BSONObjBuilder bob; - bob << "" << _expression->serialize(); + bob << "" << _expression->serialize(false); boost::intrusive_ptr<Expression> clonedExpr = Expression::parseOperand( _expCtx.get(), bob.obj().firstElement(), _expCtx->variablesParseState); @@ -132,9 +130,8 @@ MatchExpression::ExpressionOptimizerFunc ExprMatchExpression::getOptimizer() con return [](std::unique_ptr<MatchExpression> expression) { auto& exprMatchExpr = static_cast<ExprMatchExpression&>(*expression); - // $expr expressions can't take advantage of indexes. We attempt to rewrite the expressions - // as a conjunction of internal match expressions, so the query planner can use the - // internal match expressions to potentially generate an index scan. + // If '_expression' can be rewritten to a MatchExpression, we will return a $and node with + // both the original ExprMatchExpression and the MatchExpression rewrite as children. // Exiting early prevents additional calls to optimize from performing additional rewrites // and adding duplicate MatchExpression sub-trees to the tree. if (exprMatchExpr._rewriteResult) { @@ -146,10 +143,6 @@ MatchExpression::ExpressionOptimizerFunc ExprMatchExpression::getOptimizer() con RewriteExpr::rewrite(exprMatchExpr._expression, exprMatchExpr._expCtx->getCollator()); if (exprMatchExpr._rewriteResult->matchExpression()) { - // If '_expression' can be rewritten to a MatchExpression, we will return a $and node - // with both the original ExprMatchExpression and the MatchExpression rewrite as - // children. The rewritten expression might not be equivalent to the original one so we - // still have to keep the latter for correctness. auto andMatch = std::make_unique<AndMatchExpression>(); andMatch->add(exprMatchExpr._rewriteResult->releaseMatchExpression()); andMatch->add(std::move(expression)); |
