summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSvilen Mihaylov <svilen.mihaylov@mongodb.com>2020-09-09 15:26:53 -0400
committerSvilen Mihaylov <svilen.mihaylov@mongodb.com>2020-09-11 10:10:54 -0400
commit07ee2c7f5ae5ad672f560c851d5625e884cdf3d9 (patch)
tree71623873b36016753acd89da830ca9709ec47375
parent55a0e18e1da582427778d92b994caf0b5d51dd17 (diff)
downloadmongo-07ee2c7f5ae5ad672f560c851d5625e884cdf3d9.tar.gz
fix visitor
-rw-r--r--src/mongo/db/query/optimizer/node.cpp40
-rw-r--r--src/mongo/db/query/optimizer/node.h14
-rw-r--r--src/mongo/db/query/optimizer/optimizer_test.cpp3
-rw-r--r--src/mongo/db/query/optimizer/visitor.h12
4 files changed, 33 insertions, 36 deletions
diff --git a/src/mongo/db/query/optimizer/node.cpp b/src/mongo/db/query/optimizer/node.cpp
index f2b0973ba58..c52d55c1be9 100644
--- a/src/mongo/db/query/optimizer/node.cpp
+++ b/src/mongo/db/query/optimizer/node.cpp
@@ -41,33 +41,31 @@ Node::Node(Context& ctx, NodePtr child) : _nodeId(ctx.getNextNodeId()) {
Node::Node(Context& ctx, std::vector<NodePtr> children)
: _nodeId(ctx.getNextNodeId()), _children(std::move(children)) {}
-void Node::generateMemoBase(std::ostringstream& os) {
+void Node::generateMemoBase(std::ostringstream& os) const {
os << "NodeId: " << _nodeId << "\n";
}
std::string Node::generateMemo() {
- std::ostringstream os;
-
class MemoVisitor: public AbstractVisitor
{
protected:
- void visit(ScanNode& node) override {
- node.generateMemoInternal(os);
+ void visit(const ScanNode& node) override {
+ node.generateScanMemo(os);
}
- void visit(MultiJoinNode& node) override {
- node.generateMemoInternal(os);
+ void visit(const MultiJoinNode& node) override {
+ node.generateMultiJoinMemo(os);
}
- void visit(UnionNode& node) override {
- node.generateMemoInternal(os);
+ void visit(const UnionNode& node) override {
+ node.generateUnionMemo(os);
}
- void visit(GroupByNode& node) override {
- node.generateMemoInternal(os);
+ void visit(const GroupByNode& node) override {
+ node.generateGroupByMemo(os);
}
- void visit(UnwindNode& node) override {
- node.generateMemoInternal(os);
+ void visit(const UnwindNode& node) override {
+ node.generateUnwindMemo(os);
}
- void visit(WindNode& node) override {
- node.generateMemoInternal(os);
+ void visit(const WindNode& node) override {
+ node.generateWindMemo(os);
}
public:
std::ostringstream os;
@@ -92,7 +90,7 @@ NodePtr ScanNode::create(Context& ctx, CollectionNameType collectionName) {
ScanNode::ScanNode(Context& ctx, CollectionNameType collectionName)
: Node(ctx), _collectionName(std::move(collectionName)) {}
-void ScanNode::generateMemoInternal(std::ostringstream& os) {
+void ScanNode::generateScanMemo(std::ostringstream& os) const {
Node::generateMemoBase(os);
os << "Scan" << "\n";
}
@@ -117,7 +115,7 @@ MultiJoinNode::MultiJoinNode(Context& ctx,
_filterSet(std::move(filterSet)),
_projectionMap(std::move(projectionMap)) {}
-void MultiJoinNode::generateMemoInternal(std::ostringstream& os) {
+void MultiJoinNode::generateMultiJoinMemo(std::ostringstream& os) const {
Node::generateMemoBase(os);
os << "MultiJoin" << "\n";
}
@@ -133,7 +131,7 @@ NodePtr UnionNode::create(Context& ctx, std::vector<NodePtr> children) {
UnionNode::UnionNode(Context& ctx, std::vector<NodePtr> children)
: Node(ctx, std::move(children)) {}
-void UnionNode::generateMemoInternal(std::ostringstream& os) {
+void UnionNode::generateUnionMemo(std::ostringstream& os) const {
Node::generateMemoBase(os);
os << "Union" << "\n";
}
@@ -158,7 +156,7 @@ GroupByNode::GroupByNode(Context& ctx,
_groupByVector(std::move(groupByVector)),
_projectionMap(std::move(projectionMap)) {}
-void GroupByNode::generateMemoInternal(std::ostringstream& os) {
+void GroupByNode::generateGroupByMemo(std::ostringstream& os) const {
Node::generateMemoBase(os);
os << "GroupBy" << "\n";
}
@@ -183,7 +181,7 @@ UnwindNode::UnwindNode(Context& ctx,
_projectionName(std::move(projectionName)),
_retainNonArrays(retainNonArrays) {}
-void UnwindNode::generateMemoInternal(std::ostringstream& os) {
+void UnwindNode::generateUnwindMemo(std::ostringstream& os) const {
Node::generateMemoBase(os);
os << "Unwind" << "\n";
}
@@ -199,7 +197,7 @@ NodePtr WindNode::create(Context& ctx, ProjectionName projectionName, NodePtr ch
WindNode::WindNode(Context& ctx, ProjectionName projectionName, NodePtr child)
: Node(ctx, std::move(child)), _projectionName(std::move(projectionName)) {}
-void WindNode::generateMemoInternal(std::ostringstream& os) {
+void WindNode::generateWindMemo(std::ostringstream& os) const {
Node::generateMemoBase(os);
os << "Wind" << "\n";
}
diff --git a/src/mongo/db/query/optimizer/node.h b/src/mongo/db/query/optimizer/node.h
index 6c1549cdc37..ba7da13bf98 100644
--- a/src/mongo/db/query/optimizer/node.h
+++ b/src/mongo/db/query/optimizer/node.h
@@ -56,7 +56,7 @@ protected:
explicit Node(Context& ctx, NodePtr child);
explicit Node(Context& ctx, std::vector<NodePtr> children);
- virtual void generateMemoBase(std::ostringstream& os);
+ void generateMemoBase(std::ostringstream& os) const;
virtual void visit(AbstractVisitor& visitor) = 0;
@@ -77,7 +77,7 @@ class ScanNode : public Node {
public:
static NodePtr create(Context& ctx, CollectionNameType collectionName);
- void generateMemoInternal(std::ostringstream& os);
+ void generateScanMemo(std::ostringstream& os) const;
protected:
void visit(AbstractVisitor& visitor) override;
@@ -98,7 +98,7 @@ public:
ProjectionMap projectionMap,
std::vector<NodePtr> children);
- void generateMemoInternal(std::ostringstream& os);
+ void generateMultiJoinMemo(std::ostringstream& os) const;
protected:
void visit(AbstractVisitor& visitor) override;
@@ -117,7 +117,7 @@ class UnionNode : public Node {
public:
static NodePtr create(Context& ctx, std::vector<NodePtr> children);
- void generateMemoInternal(std::ostringstream& os);
+ void generateUnionMemo(std::ostringstream& os) const;
protected:
void visit(AbstractVisitor& visitor) override;
@@ -136,7 +136,7 @@ public:
ProjectionMap projectionMap,
NodePtr child);
- void generateMemoInternal(std::ostringstream& os);
+ void generateGroupByMemo(std::ostringstream& os) const;
protected:
void visit(AbstractVisitor& visitor) override;
@@ -158,7 +158,7 @@ public:
bool retainNonArrays,
NodePtr child);
- void generateMemoInternal(std::ostringstream& os);
+ void generateUnwindMemo(std::ostringstream& os) const;
protected:
@@ -175,7 +175,7 @@ class WindNode : public Node {
public:
static NodePtr create(Context& ctx, ProjectionName projectionName, NodePtr child);
- void generateMemoInternal(std::ostringstream& os);
+ void generateWindMemo(std::ostringstream& os) const;
protected:
void visit(AbstractVisitor& visitor) override;
diff --git a/src/mongo/db/query/optimizer/optimizer_test.cpp b/src/mongo/db/query/optimizer/optimizer_test.cpp
index 4b36d49760f..7eeaf801b16 100644
--- a/src/mongo/db/query/optimizer/optimizer_test.cpp
+++ b/src/mongo/db/query/optimizer/optimizer_test.cpp
@@ -37,8 +37,7 @@ TEST(Optimizer, Basic) {
Context ctx;
NodePtr ptr = ScanNode::create(ctx, "test");
- const std::string& s = ptr->generateMemo();
- NodePtr ptr1 = ScanNode::create(ctx, "test");
+ ASSERT_EQ("NodeId: 0\nScan\n", ptr->generateMemo());
}
} // namespace
diff --git a/src/mongo/db/query/optimizer/visitor.h b/src/mongo/db/query/optimizer/visitor.h
index bb5acfb7412..1aa0a886fab 100644
--- a/src/mongo/db/query/optimizer/visitor.h
+++ b/src/mongo/db/query/optimizer/visitor.h
@@ -35,12 +35,12 @@ namespace mongo::optimizer {
class AbstractVisitor {
public:
- virtual void visit(ScanNode& node) = 0;
- virtual void visit(MultiJoinNode& node) = 0;
- virtual void visit(UnionNode& node) = 0;
- virtual void visit(GroupByNode& node) = 0;
- virtual void visit(UnwindNode& node) = 0;
- virtual void visit(WindNode& node) = 0;
+ virtual void visit(const ScanNode& node) = 0;
+ virtual void visit(const MultiJoinNode& node) = 0;
+ virtual void visit(const UnionNode& node) = 0;
+ virtual void visit(const GroupByNode& node) = 0;
+ virtual void visit(const UnwindNode& node) = 0;
+ virtual void visit(const WindNode& node) = 0;
};
} // namespace mongo::optimizer