diff options
Diffstat (limited to 'src/mongo')
20 files changed, 69 insertions, 49 deletions
diff --git a/src/mongo/db/matcher/expression.h b/src/mongo/db/matcher/expression.h index 4705c2cdf32..f870dbcbcda 100644 --- a/src/mongo/db/matcher/expression.h +++ b/src/mongo/db/matcher/expression.h @@ -29,6 +29,7 @@ #pragma once +#include <boost/optional.hpp> #include <functional> #include <memory> @@ -185,11 +186,12 @@ public: /** * For MatchExpression nodes that can participate in tree restructuring (like AND/OR), returns a - * non-const vector of MatchExpression* child nodes. + * non-const vector of MatchExpression* child nodes. If the MatchExpression does not + * participated in tree restructuring, returns boost::none. * Do not use to traverse the MatchExpression tree. Use numChildren() and getChild(), which * provide access to all nodes. */ - virtual std::vector<MatchExpression*>* getChildVector() = 0; + virtual boost::optional<std::vector<MatchExpression*>&> getChildVector() = 0; /** * Get the path of the leaf. Returns StringData() if there is no path (node is logical). diff --git a/src/mongo/db/matcher/expression_always_boolean.h b/src/mongo/db/matcher/expression_always_boolean.h index 3e6030ae36e..ff12bcd1da0 100644 --- a/src/mongo/db/matcher/expression_always_boolean.h +++ b/src/mongo/db/matcher/expression_always_boolean.h @@ -29,6 +29,8 @@ #pragma once +#include <boost/optional.hpp> + #include "mongo/db/matcher/expression.h" namespace mongo { @@ -78,8 +80,8 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() override { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } private: diff --git a/src/mongo/db/matcher/expression_arity.h b/src/mongo/db/matcher/expression_arity.h index 8ec77663ea7..0c1b57f3cf9 100644 --- a/src/mongo/db/matcher/expression_arity.h +++ b/src/mongo/db/matcher/expression_arity.h @@ -31,6 +31,7 @@ #include <algorithm> #include <array> +#include <boost/optional.hpp> #include <memory> #include "mongo/db/matcher/expression.h" @@ -80,8 +81,8 @@ public: [](const auto& expr1, const auto& expr2) { return expr1->equivalent(expr2.get()); }); } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } size_t numChildren() const final { diff --git a/src/mongo/db/matcher/expression_array.h b/src/mongo/db/matcher/expression_array.h index 5f6933ad2d7..329d2aea707 100644 --- a/src/mongo/db/matcher/expression_array.h +++ b/src/mongo/db/matcher/expression_array.h @@ -29,6 +29,7 @@ #pragma once +#include <boost/optional.hpp> #include <vector> #include "mongo/base/status.h" @@ -88,8 +89,8 @@ public: BSONObj getSerializedRightHandSide() const final; - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } virtual size_t numChildren() const { @@ -143,8 +144,8 @@ public: BSONObj getSerializedRightHandSide() const final; - virtual std::vector<MatchExpression*>* getChildVector() { - return &_subs; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return _subs; } virtual size_t numChildren() const { @@ -184,8 +185,8 @@ public: return nullptr; } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } virtual bool matchesArray(const BSONObj& anArray, MatchDetails* details) const; diff --git a/src/mongo/db/matcher/expression_expr.h b/src/mongo/db/matcher/expression_expr.h index d3ebae6ec0b..fb9f7d6d628 100644 --- a/src/mongo/db/matcher/expression_expr.h +++ b/src/mongo/db/matcher/expression_expr.h @@ -29,6 +29,7 @@ #pragma once +#include <boost/optional.hpp> #include <vector> #include "mongo/db/matcher/expression.h" @@ -79,8 +80,8 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } boost::intrusive_ptr<ExpressionContext> getExpressionContext() { diff --git a/src/mongo/db/matcher/expression_leaf.h b/src/mongo/db/matcher/expression_leaf.h index 27ecb29622f..ebc69b1230a 100644 --- a/src/mongo/db/matcher/expression_leaf.h +++ b/src/mongo/db/matcher/expression_leaf.h @@ -29,6 +29,7 @@ #pragma once +#include <boost/optional.hpp> #include <memory> #include "mongo/bson/bsonelement_comparator.h" @@ -71,8 +72,8 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() override { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } MatchCategory getCategory() const override { diff --git a/src/mongo/db/matcher/expression_tree.h b/src/mongo/db/matcher/expression_tree.h index 5a33cb1e10d..ddd372db654 100644 --- a/src/mongo/db/matcher/expression_tree.h +++ b/src/mongo/db/matcher/expression_tree.h @@ -29,8 +29,9 @@ #pragma once -#include "mongo/db/matcher/expression.h" +#include <boost/optional.hpp> +#include "mongo/db/matcher/expression.h" /** * this contains all Expessions that define the structure of the tree @@ -82,8 +83,8 @@ public: return child; } - virtual std::vector<MatchExpression*>* getChildVector() { - return &_expressions; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return _expressions; } bool equivalent(const MatchExpression* other) const; @@ -223,8 +224,8 @@ public: return _exp.get(); } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } MatchExpression* releaseChild(void) { diff --git a/src/mongo/db/matcher/expression_where_base.h b/src/mongo/db/matcher/expression_where_base.h index 78db059c218..dc839966fd0 100644 --- a/src/mongo/db/matcher/expression_where_base.h +++ b/src/mongo/db/matcher/expression_where_base.h @@ -29,6 +29,8 @@ #pragma once +#include <boost/optional.hpp> + #include "mongo/db/matcher/expression.h" namespace mongo { @@ -53,8 +55,8 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } bool matchesSingleElement(const BSONElement& e, MatchDetails* details = nullptr) const final { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h index dab875cb80d..c7884c63c33 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h @@ -28,6 +28,8 @@ */ #pragma once +#include <boost/optional.hpp> + #include "mongo/base/string_data.h" #include "mongo/db/matcher/expression.h" #include "mongo/db/matcher/expression_array.h" @@ -67,8 +69,8 @@ public: bool equivalent(const MatchExpression* other) const final; - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } size_t numChildren() const final { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h index c2eaa46bbcc..739cee4db96 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h @@ -29,6 +29,7 @@ #pragma once +#include <boost/optional.hpp> #include <memory> #include <pcrecpp.h> #include <utility> @@ -138,8 +139,8 @@ public: std::unique_ptr<MatchExpression> shallowClone() const final; - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } size_t numChildren() const final { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_eq.h b/src/mongo/db/matcher/schema/expression_internal_schema_eq.h index c2495d991ba..69e18a4fc39 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_eq.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_eq.h @@ -29,6 +29,8 @@ #pragma once +#include <boost/optional.hpp> + #include "mongo/bson/unordered_fields_bsonelement_comparator.h" #include "mongo/db/matcher/expression_leaf.h" @@ -66,10 +68,6 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; - } - private: ExpressionOptimizerFunc getOptimizer() const final { return [](std::unique_ptr<MatchExpression> expression) { return expression; }; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h index 54682da09d4..a5e79e79e7f 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h @@ -29,6 +29,7 @@ #pragma once +#include <boost/optional.hpp> #include <memory> #include "mongo/db/matcher/expression_array.h" @@ -73,8 +74,8 @@ public: std::unique_ptr<MatchExpression> shallowClone() const final; - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } size_t numChildren() const final { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h b/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h index 249de09c030..ecc269641a0 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h @@ -29,6 +29,8 @@ #pragma once +#include <boost/optional.hpp> + #include "mongo/base/string_data.h" #include "mongo/db/matcher/expression_array.h" @@ -60,8 +62,8 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } protected: diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h b/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h index 463420f0dd7..bbc0baf0aa8 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h @@ -29,6 +29,8 @@ #pragma once +#include <boost/optional.hpp> + #include "mongo/base/string_data.h" #include "mongo/db/matcher/expression.h" @@ -55,8 +57,8 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } void debugString(StringBuilder& debug, int indentationLevel) const final; diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h b/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h index 407c6680057..6dda56a1286 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h @@ -29,6 +29,8 @@ #pragma once +#include <boost/optional.hpp> + #include "mongo/db/matcher/expression_path.h" namespace mongo { @@ -49,8 +51,8 @@ public: bool equivalent(const MatchExpression* other) const final; - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } size_t numChildren() const final { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h b/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h index ebfdca1b136..a174eabafd2 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h @@ -29,6 +29,8 @@ #pragma once +#include <boost/optional.hpp> + #include "mongo/bson/unordered_fields_bsonobj_comparator.h" #include "mongo/db/matcher/expression.h" @@ -79,8 +81,8 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } MatchCategory getCategory() const final { diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h b/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h index 9b47e32682f..328bf24d6f0 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h @@ -29,6 +29,7 @@ #pragma once +#include <boost/optional.hpp> #include <utility> #include "mongo/bson/unordered_fields_bsonelement_comparator.h" @@ -57,8 +58,8 @@ public: MONGO_UNREACHABLE; } - std::vector<MatchExpression*>* getChildVector() final { - return nullptr; + boost::optional<std::vector<MatchExpression*>&> getChildVector() final { + return boost::none; } bool matchesArray(const BSONObj& array, MatchDetails*) const final { diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp index 7117827c63a..a0f7c6ec7df 100644 --- a/src/mongo/db/query/canonical_query.cpp +++ b/src/mongo/db/query/canonical_query.cpp @@ -340,8 +340,7 @@ void CanonicalQuery::sortTree(MatchExpression* tree) { for (size_t i = 0; i < tree->numChildren(); ++i) { sortTree(tree->getChild(i)); } - std::vector<MatchExpression*>* children = tree->getChildVector(); - if (nullptr != children) { + if (auto&& children = tree->getChildVector()) { std::stable_sort(children->begin(), children->end(), matchExpressionLessThan); } } diff --git a/src/mongo/db/query/index_tag.cpp b/src/mongo/db/query/index_tag.cpp index 6d636662f16..ddefae1f463 100644 --- a/src/mongo/db/query/index_tag.cpp +++ b/src/mongo/db/query/index_tag.cpp @@ -113,14 +113,13 @@ void sortUsingTags(MatchExpression* tree) { for (size_t i = 0; i < tree->numChildren(); ++i) { sortUsingTags(tree->getChild(i)); } - std::vector<MatchExpression*>* children = tree->getChildVector(); - if (nullptr != children) { + + if (auto&& children = tree->getChildVector()) std::stable_sort(children->begin(), children->end(), [](const MatchExpression* lhs, const MatchExpression* rhs) { return tagComparison(lhs, rhs) < 0; }); - } } // Attaches 'node' to 'target'. If 'target' is an AND, adds 'node' as a child of 'target'. diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp index 1e2adddbd3f..ba2082ed17e 100644 --- a/src/mongo/db/query/planner_ixselect.cpp +++ b/src/mongo/db/query/planner_ixselect.cpp @@ -467,7 +467,7 @@ bool QueryPlannerIXSelect::_compatible(const BSONElement& keyPatternElt, newContext.fullPathToParentElemMatch = fullPathToNode; newContext.innermostParentElemMatch = static_cast<ElemMatchValueMatchExpression*>(node); - auto* children = node->getChildVector(); + auto&& children = node->getChildVector(); if (!std::all_of(children->begin(), children->end(), [&](MatchExpression* child) { const auto newPath = fullPathToNode.toString() + child->path(); return _compatible( |