Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/optimizer trait match #3769

Merged
merged 13 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/graph/optimizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,12 @@ nebula_add_library(
rule/TagIndexFullScanRule.cpp
rule/EdgeIndexFullScanRule.cpp
rule/PushLimitDownIndexScanRule.cpp
rule/PushLimitDownTagIndexFullScanRule.cpp
rule/PushLimitDownTagIndexPrefixScanRule.cpp
rule/PushLimitDownTagIndexRangeScanRule.cpp
rule/PushLimitDownEdgeIndexFullScanRule.cpp
rule/PushLimitDownEdgeIndexPrefixScanRule.cpp
rule/PushLimitDownEdgeIndexRangeScanRule.cpp
rule/PushLimitDownProjectRule.cpp
rule/EliminateRowCollectRule.cpp
rule/PushLimitDownScanAppendVerticesRule.cpp
rule/GetEdgesTransformRule.cpp
rule/PushLimitDownScanEdgesAppendVerticesRule.cpp
rule/PushTopNDownIndexScanRule.cpp
rule/PushTopNDownTagIndexFullScanRule.cpp
rule/PushTopNDownTagIndexPrefixScanRule.cpp
rule/PushTopNDownTagIndexRangeScanRule.cpp
rule/PushTopNDownEdgeIndexFullScanRule.cpp
rule/PushTopNDownEdgeIndexPrefixScanRule.cpp
rule/PushTopNDownEdgeIndexRangeScanRule.cpp
)

nebula_add_subdirectory(test)
14 changes: 7 additions & 7 deletions src/graph/optimizer/OptRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ const PlanNode *MatchedResult::planNode(const std::vector<int32_t> &pos) const {
}

Pattern Pattern::create(graph::PlanNode::Kind kind, std::initializer_list<Pattern> patterns) {
Pattern pattern;
pattern.kind_ = kind;
for (auto &p : patterns) {
pattern.dependencies_.emplace_back(p);
}
return pattern;
return Pattern(kind, std::move(patterns));
}

/*static*/ Pattern Pattern::create(std::initializer_list<graph::PlanNode::Kind> kinds,
std::initializer_list<Pattern> patterns) {
return Pattern(std::move(kinds), std::move(patterns));
}

StatusOr<MatchedResult> Pattern::match(const OptGroupNode *groupNode) const {
if (groupNode->node()->kind() != kind_) {
if (!node_.match(groupNode->node())) {
return Status::Error();
}

Expand Down
26 changes: 24 additions & 2 deletions src/graph/optimizer/OptRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,39 @@ struct MatchedResult {
const graph::PlanNode *planNode(const std::vector<int32_t> &pos = {}) const;
};

// Match plan node by trait or kind of plan node.
class MatchNode {
public:
explicit MatchNode(graph::PlanNode::Kind kind) : node_({kind}) {}
explicit MatchNode(std::initializer_list<graph::PlanNode::Kind> kinds)
: node_(std::move(kinds)) {}

bool match(const graph::PlanNode *node) const {
auto find = node_.find(node->kind());
return find != node_.end();
}

private:
std::unordered_set<graph::PlanNode::Kind> node_;
};

class Pattern final {
public:
static Pattern create(graph::PlanNode::Kind kind, std::initializer_list<Pattern> patterns = {});
static Pattern create(std::initializer_list<graph::PlanNode::Kind> kinds,
std::initializer_list<Pattern> patterns = {});

StatusOr<MatchedResult> match(const OptGroupNode *groupNode) const;

private:
Pattern() = default;
explicit Pattern(graph::PlanNode::Kind kind, std::initializer_list<Pattern> patterns = {})
: node_(kind), dependencies_(patterns) {}
explicit Pattern(std::initializer_list<graph::PlanNode::Kind> kinds,
std::initializer_list<Pattern> patterns = {})
: node_(std::move(kinds)), dependencies_(patterns) {}
StatusOr<MatchedResult> match(const OptGroup *group) const;

graph::PlanNode::Kind kind_;
MatchNode node_;
std::vector<Pattern> dependencies_;
};

Expand Down
74 changes: 0 additions & 74 deletions src/graph/optimizer/rule/PushLimitDownEdgeIndexFullScanRule.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions src/graph/optimizer/rule/PushLimitDownEdgeIndexFullScanRule.h

This file was deleted.

76 changes: 0 additions & 76 deletions src/graph/optimizer/rule/PushLimitDownEdgeIndexPrefixScanRule.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions src/graph/optimizer/rule/PushLimitDownEdgeIndexPrefixScanRule.h

This file was deleted.

74 changes: 0 additions & 74 deletions src/graph/optimizer/rule/PushLimitDownEdgeIndexRangeScanRule.cpp

This file was deleted.

Loading