summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression.h
diff options
context:
space:
mode:
authorMartin Neupauer <martin.neupauer@mongodb.com>2020-06-11 08:07:39 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-11 11:17:49 +0000
commite3948d4d8817579b6b03618e64e1b9e8cc2ef086 (patch)
tree649bef264a16807b269f7b645a8d2312c4442455 /src/mongo/db/matcher/expression.h
parent0af9c85d7e2ba60f592f2d7a9a35217e254e59fb (diff)
downloadmongo-e3948d4d8817579b6b03618e64e1b9e8cc2ef086.tar.gz
SERVER-48228 Move slot-based execution engine and supporting changes into the master branch
This is an initial commit for the slot-based execution engine (SBE) which contains: * Implementation of the core slot-based engine. * The SBE stage builder, which is responsible for translating a QuerySolution tree into an SBE plan. * Other changes necessary for integration with the find command. Co-authored-by: Anton Korshunov <anton.korshunov@mongodb.com> Co-authored-by: Justin Seyster <justin.seyster@mongodb.com> Co-authored-by: David Storch <david.storch@mongodb.com>
Diffstat (limited to 'src/mongo/db/matcher/expression.h')
-rw-r--r--src/mongo/db/matcher/expression.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression.h b/src/mongo/db/matcher/expression.h
index 052ab19c7ea..e84e3ee0982 100644
--- a/src/mongo/db/matcher/expression.h
+++ b/src/mongo/db/matcher/expression.h
@@ -36,6 +36,7 @@
#include "mongo/base/status.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/db/matcher/expression_visitor.h"
#include "mongo/db/matcher/match_details.h"
#include "mongo/db/matcher/matchable.h"
#include "mongo/db/pipeline/dependencies.h"
@@ -133,6 +134,75 @@ public:
};
/**
+ * An iterator to walk through the children expressions of the given MatchExpressions. Along
+ * with the defined 'begin()' and 'end()' functions, which take a reference to a
+ * MatchExpression, this iterator can be used with a range-based loop. For example,
+ *
+ * const MatchExpression* expr = makeSomeExpression();
+ * for (const auto& child : *expr) {
+ * ...
+ * }
+ *
+ * When incrementing the iterator, no checks are made to ensure the iterator does not pass
+ * beyond the boundary. The caller is responsible to compare the iterator against an iterator
+ * referring to the past-the-end child in the given expression, which can be obtained using
+ * the 'mongo::end(*expr)' call.
+ */
+ template <bool IsConst>
+ class MatchExpressionIterator {
+ public:
+ MatchExpressionIterator(const MatchExpression* expr, size_t index)
+ : _expr(expr), _index(index) {}
+
+ template <bool WasConst, typename = std::enable_if_t<IsConst && !WasConst>>
+ MatchExpressionIterator(const MatchExpressionIterator<WasConst>& other)
+ : _expr(other._expr), _index(other._index) {}
+
+ template <bool WasConst, typename = std::enable_if_t<IsConst && !WasConst>>
+ MatchExpressionIterator& operator=(const MatchExpressionIterator<WasConst>& other) {
+ _expr = other._expr;
+ _index = other._index;
+ return *this;
+ }
+
+ MatchExpressionIterator& operator++() {
+ ++_index;
+ return *this;
+ }
+
+ MatchExpressionIterator operator++(int) {
+ const auto ret{*this};
+ ++(*this);
+ return ret;
+ }
+
+ bool operator==(const MatchExpressionIterator& other) const {
+ return _expr == other._expr && _index == other._index;
+ }
+
+ bool operator!=(const MatchExpressionIterator& other) const {
+ return !(*this == other);
+ }
+
+ template <bool Const = IsConst>
+ auto operator*() const -> std::enable_if_t<!Const, MatchExpression*> {
+ return _expr->getChild(_index);
+ }
+
+ template <bool Const = IsConst>
+ auto operator*() const -> std::enable_if_t<Const, const MatchExpression*> {
+ return _expr->getChild(_index);
+ }
+
+ private:
+ const MatchExpression* _expr;
+ size_t _index;
+ };
+
+ using Iterator = MatchExpressionIterator<false>;
+ using ConstIterator = MatchExpressionIterator<true>;
+
+ /**
* Make simplifying changes to the structure of a MatchExpression tree without altering its
* semantics. This function may return:
* - a pointer to the original, unmodified MatchExpression,
@@ -338,6 +408,9 @@ public:
return false;
}
+ virtual void acceptVisitor(MatchExpressionMutableVisitor* visitor) = 0;
+ virtual void acceptVisitor(MatchExpressionConstVisitor* visitor) const = 0;
+
//
// Debug information
//
@@ -397,4 +470,21 @@ private:
MatchType _matchType;
std::unique_ptr<TagData> _tagData;
};
+
+inline MatchExpression::Iterator begin(MatchExpression& expr) {
+ return {&expr, 0};
+}
+
+inline MatchExpression::ConstIterator begin(const MatchExpression& expr) {
+ return {&expr, 0};
+}
+
+inline MatchExpression::Iterator end(MatchExpression& expr) {
+ return {&expr, expr.numChildren()};
+}
+
+inline MatchExpression::ConstIterator end(const MatchExpression& expr) {
+ return {&expr, expr.numChildren()};
+}
+
} // namespace mongo