Skip to content

Commit

Permalink
Feature/optimizer trait match (vesoft-inc#3769)
Browse files Browse the repository at this point in the history
* Add trait for pattern match.

* Implement match plan by trait and reduce some reduncant rules.

* Remove unused header.

* Fix warning.

* Let optimize rule decide collection of matched nodes.

Co-authored-by: kyle.cao <[email protected]>
Co-authored-by: Sophie <[email protected]>
  • Loading branch information
3 people authored and liwenhui-soul committed Jan 29, 2022
1 parent 1815766 commit dba7a0b
Show file tree
Hide file tree
Showing 32 changed files with 74 additions and 1,481 deletions.
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

0 comments on commit dba7a0b

Please sign in to comment.