-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove useless project and dedup before getdstBysrc
- Loading branch information
Showing
9 changed files
with
153 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/graph/optimizer/rule/RemoveProjectDedupBeforeGetDstBySrcRule.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#include "graph/optimizer/rule/RemoveProjectDedupBeforeGetDstBySrcRule.h" | ||
|
||
#include "graph/optimizer/OptContext.h" | ||
#include "graph/optimizer/OptGroup.h" | ||
#include "graph/planner/plan/PlanNode.h" | ||
#include "graph/planner/plan/Query.h" | ||
|
||
using nebula::graph::PlanNode; | ||
using nebula::graph::QueryContext; | ||
|
||
namespace nebula { | ||
namespace opt { | ||
|
||
std::unique_ptr<OptRule> RemoveProjectDedupBeforeGetDstBySrcRule::kInstance = | ||
std::unique_ptr<RemoveProjectDedupBeforeGetDstBySrcRule>( | ||
new RemoveProjectDedupBeforeGetDstBySrcRule()); | ||
|
||
RemoveProjectDedupBeforeGetDstBySrcRule::RemoveProjectDedupBeforeGetDstBySrcRule() { | ||
RuleSet::QueryRules().addRule(this); | ||
} | ||
|
||
const Pattern& RemoveProjectDedupBeforeGetDstBySrcRule::pattern() const { | ||
static Pattern pattern = Pattern::create( | ||
graph::PlanNode::Kind::kGetDstBySrc, | ||
{Pattern::create(graph::PlanNode::Kind::kDedup, | ||
{Pattern::create(graph::PlanNode::Kind::kProject, | ||
{Pattern::create(graph::PlanNode::Kind::kDataCollect)})})}); | ||
return pattern; | ||
} | ||
|
||
StatusOr<OptRule::TransformResult> RemoveProjectDedupBeforeGetDstBySrcRule::transform( | ||
OptContext* octx, const MatchedResult& matched) const { | ||
auto* getDstBySrcGroupNode = matched.node; | ||
auto* getDstBySrc = static_cast<const graph::GetDstBySrc*>(getDstBySrcGroupNode->node()); | ||
auto* projectGroupNode = matched.dependencies.front().dependencies.front().node; | ||
auto* project = static_cast<const graph::Project*>(projectGroupNode->node()); | ||
|
||
auto* newGetDstBySrc = getDstBySrc->clone(); | ||
newGetDstBySrc->setOutputVar(getDstBySrc->outputVar()); | ||
newGetDstBySrc->setInputVar(project->inputVar()); | ||
newGetDstBySrc->setColNames(newGetDstBySrc->colNames()); | ||
|
||
auto newGetDstBySrcNode = | ||
OptGroupNode::create(octx, newGetDstBySrc, getDstBySrcGroupNode->group()); | ||
for (auto dep : projectGroupNode->dependencies()) { | ||
newGetDstBySrcNode->dependsOn(dep); | ||
} | ||
|
||
TransformResult result; | ||
result.newGroupNodes.emplace_back(newGetDstBySrcNode); | ||
result.eraseAll = true; | ||
return result; | ||
} | ||
|
||
bool RemoveProjectDedupBeforeGetDstBySrcRule::match(OptContext*, | ||
const MatchedResult& matched) const { | ||
auto* getDstBySrc = static_cast<const graph::GetDstBySrc*>(matched.node->node()); | ||
auto* project = static_cast<const graph::Project*>( | ||
matched.dependencies.front().dependencies.front().node->node()); | ||
auto* dataCollect = static_cast<const graph::DataCollect*>( | ||
matched.dependencies.front().dependencies.front().dependencies.front().node->node()); | ||
|
||
if (getDstBySrc->src()->kind() != Expression::Kind::kInputProperty && | ||
getDstBySrc->src()->kind() != Expression::Kind::kColumn) { | ||
return false; | ||
} | ||
if (project->columns()->size() != 1) { | ||
return false; | ||
} | ||
if (dataCollect->kind() != graph::DataCollect::DCKind::kMToN || !dataCollect->distinct() || | ||
dataCollect->colNames().size() != 1) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
std::string RemoveProjectDedupBeforeGetDstBySrcRule::toString() const { | ||
return "RemoveProjectDedupBeforeGetDstBySrcRule"; | ||
} | ||
|
||
} // namespace opt | ||
} // namespace nebula |
54 changes: 54 additions & 0 deletions
54
src/graph/optimizer/rule/RemoveProjectDedupBeforeGetDstBySrcRule.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#ifndef GRAPH_OPTIMIZER_RULE_REMOVEPROJECTDEDUPBEFOREGETDSTBYSRCRULE_H_ | ||
#define GRAPH_OPTIMIZER_RULE_REMOVEPROJECTDEDUPBEFOREGETDSTBYSRCRULE_H_ | ||
|
||
#include <initializer_list> | ||
|
||
#include "graph/optimizer/OptRule.h" | ||
|
||
namespace nebula { | ||
namespace opt { | ||
|
||
// DataCollect contains only one column that is a deduped vid column which GetDstBySrc needs, | ||
// so the following Project and Dedup are useless. | ||
// | ||
// Tranformation: | ||
// Before: | ||
// | ||
// +---------+---------+ | ||
// | GetDstBySrc | | ||
// +---------+---------+ | ||
// | Dedup | | ||
// +---------+---------+ | ||
// | Project | | ||
// +---------+---------+ | ||
// | DataCollect | | ||
// +---------+---------+ | ||
// | ||
// After: | ||
// // Remove Project node | ||
|
||
class RemoveProjectDedupBeforeGetDstBySrcRule final : public OptRule { | ||
public: | ||
const Pattern &pattern() const override; | ||
|
||
StatusOr<TransformResult> transform(OptContext *ctx, const MatchedResult &matched) const override; | ||
|
||
bool match(OptContext *ctx, const MatchedResult &matched) const override; | ||
|
||
std::string toString() const override; | ||
|
||
private: | ||
RemoveProjectDedupBeforeGetDstBySrcRule(); | ||
|
||
static std::unique_ptr<OptRule> kInstance; | ||
}; | ||
|
||
} // namespace opt | ||
} // namespace nebula | ||
|
||
#endif // GRAPH_OPTIMIZER_RULE_REMOVEPROJECTDEDUPBEFOREGETDSTBYSRCRULE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/tck/features/optimizer/PushFilterDownLeftJoinRule.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters