diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2017-06-30 11:48:35 -0400 |
---|---|---|
committer | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2017-07-07 13:19:15 -0400 |
commit | 23f44557852e61349fd28505ec6b953e22024d8b (patch) | |
tree | 5898f879e8a5db71ee300cd2ded70e388e4ac21e /src/mongo/db/matcher/expression_algo.cpp | |
parent | be4c4f1fffe6ca69fb67ee872b52b3bd4e630659 (diff) | |
download | mongo-23f44557852e61349fd28505ec6b953e22024d8b.tar.gz |
SERVER-29587: Partition MatchExpression types into categories, fixes an
issue with previous commit where {min/max}Items was categorized as a
leaf.
Diffstat (limited to 'src/mongo/db/matcher/expression_algo.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_algo.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/mongo/db/matcher/expression_algo.cpp b/src/mongo/db/matcher/expression_algo.cpp index 0979eb7b475..609eef099e6 100644 --- a/src/mongo/db/matcher/expression_algo.cpp +++ b/src/mongo/db/matcher/expression_algo.cpp @@ -276,11 +276,12 @@ unique_ptr<MatchExpression> createNorOfNodes(std::vector<unique_ptr<MatchExpress } void applyRenamesToExpression(MatchExpression* expr, const StringMap<std::string>& renames) { - if (expr->isArray()) { + if (expr->getCategory() == MatchExpression::MatchCategory::kArrayMatching || + expr->getCategory() == MatchExpression::MatchCategory::kOther) { return; } - if (expr->isLeaf()) { + if (expr->getCategory() == MatchExpression::MatchCategory::kLeaf) { auto it = renames.find(expr->path()); if (it != renames.end()) { LeafMatchExpression* leafExpr = checked_cast<LeafMatchExpression*>(expr); @@ -300,7 +301,7 @@ splitMatchExpressionByWithoutRenames(unique_ptr<MatchExpression> expr, // 'expr' does not depend upon 'fields', so it can be completely moved. return {std::move(expr), nullptr}; } - if (!expr->isLogical()) { + if (expr->getCategory() != MatchExpression::MatchCategory::kLogical) { // 'expr' is a leaf, and was not independent of 'fields'. return {nullptr, std::move(expr)}; } @@ -410,23 +411,28 @@ bool isSubsetOf(const MatchExpression* lhs, const MatchExpression* rhs) { } bool isIndependentOf(const MatchExpression& expr, const std::set<std::string>& pathSet) { - if (expr.isLogical()) { - // Any logical expression is independent of 'pathSet' if all its children are independent of - // 'pathSet'. - for (size_t i = 0; i < expr.numChildren(); i++) { - if (!isIndependentOf(*expr.getChild(i), pathSet)) { - return false; + switch (expr.getCategory()) { + case MatchExpression::MatchCategory::kLogical: { + // Any logical expression is independent of 'pathSet' if all its children are + // independent of 'pathSet'. + for (size_t i = 0; i < expr.numChildren(); i++) { + if (!isIndependentOf(*expr.getChild(i), pathSet)) { + return false; + } } + return true; + } + case MatchExpression::MatchCategory::kLeaf: { + return isLeafIndependentOf(expr.path(), pathSet); + } + // All other match expressions are never considered independent. + case MatchExpression::MatchCategory::kArrayMatching: + case MatchExpression::MatchCategory::kOther: { + return false; } - return true; - } - - // Array match expressions are never considered independent. - if (expr.isArray()) { - return false; } - return isLeafIndependentOf(expr.path(), pathSet); + MONGO_UNREACHABLE; } std::pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> splitMatchExpressionBy( |