-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enhancement/push filter down AppendVertices #5490
Draft
czpmango
wants to merge
4
commits into
vesoft-inc:master
Choose a base branch
from
czpmango:enhancement/PushFilterDownAppendVertices
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e22e6c7
Push filter down AppendVertices
czpmango 21c2430
Merge branch 'master' into enhancement/PushFilterDownAppendVertices
Sophie-Xie ecf81e3
Merge branch 'master' into enhancement/PushFilterDownAppendVertices
Sophie-Xie 2b3decf
Merge branch 'master' into enhancement/PushFilterDownAppendVertices
Sophie-Xie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
118 changes: 118 additions & 0 deletions
118
src/graph/optimizer/rule/PushFilterDownAppendVerticesRule.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,118 @@ | ||
/* Copyright (c) 2023 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#include "graph/optimizer/rule/PushFilterDownAppendVerticesRule.h" | ||
|
||
#include "common/expression/Expression.h" | ||
#include "graph/optimizer/OptContext.h" | ||
#include "graph/optimizer/OptGroup.h" | ||
#include "graph/planner/plan/PlanNode.h" | ||
#include "graph/planner/plan/Query.h" | ||
#include "graph/util/ExpressionUtils.h" | ||
#include "graph/visitor/ExtractFilterExprVisitor.h" | ||
|
||
using nebula::Expression; | ||
using nebula::graph::AppendVertices; | ||
using nebula::graph::Filter; | ||
using nebula::graph::PlanNode; | ||
using nebula::graph::QueryContext; | ||
|
||
namespace nebula { | ||
namespace opt { | ||
|
||
std::unique_ptr<OptRule> PushFilterDownAppendVerticesRule::kInstance = | ||
std::unique_ptr<PushFilterDownAppendVerticesRule>(new PushFilterDownAppendVerticesRule()); | ||
|
||
PushFilterDownAppendVerticesRule::PushFilterDownAppendVerticesRule() { | ||
RuleSet::QueryRules().addRule(this); | ||
} | ||
|
||
const Pattern &PushFilterDownAppendVerticesRule::pattern() const { | ||
static Pattern pattern = | ||
Pattern::create(PlanNode::Kind::kFilter, {Pattern::create(PlanNode::Kind::kAppendVertices)}); | ||
return pattern; | ||
} | ||
|
||
StatusOr<OptRule::TransformResult> PushFilterDownAppendVerticesRule::transform( | ||
OptContext *ctx, const MatchedResult &matched) const { | ||
auto filterGroupNode = matched.node; | ||
auto appendVerticesGroupNode = matched.dependencies.front().node; | ||
auto filter = static_cast<const Filter *>(filterGroupNode->node()); | ||
auto appendVertices = static_cast<const AppendVertices *>(appendVerticesGroupNode->node()); | ||
auto qctx = ctx->qctx(); | ||
auto pool = qctx->objPool(); | ||
auto condition = graph::ExpressionUtils::rewriteVertexPropertyFilter( | ||
pool, appendVertices->colNames().back(), filter->condition()->clone()); | ||
|
||
auto visitor = graph::ExtractFilterExprVisitor::makePushGetVertices( | ||
pool, appendVertices->space(), qctx->schemaMng()); | ||
condition->accept(&visitor); | ||
if (!visitor.ok()) { | ||
return TransformResult::noTransform(); | ||
} | ||
|
||
auto remainedExpr = std::move(visitor).remainedExpr(); | ||
OptGroupNode *newFilterGroupNode = nullptr; | ||
PlanNode *newFilter = nullptr; | ||
if (remainedExpr != nullptr) { | ||
auto *found = graph::ExpressionUtils::findAny(remainedExpr, {Expression::Kind::kTagProperty}); | ||
if (found != nullptr) { // Some tag property expression don't push down | ||
// TODO(shylock): we could push down a part. | ||
return TransformResult::noTransform(); | ||
} | ||
newFilter = Filter::make(qctx, nullptr, remainedExpr); | ||
newFilter->setOutputVar(filter->outputVar()); | ||
newFilter->setInputVar(filter->inputVar()); | ||
newFilterGroupNode = OptGroupNode::create(ctx, newFilter, filterGroupNode->group()); | ||
} | ||
|
||
auto newAppendVerticesFilter = condition; | ||
if (condition->isLogicalExpr()) { | ||
const auto *le = static_cast<const LogicalExpression *>(condition); | ||
if (le->operands().size() == 1) { | ||
newAppendVerticesFilter = le->operands().front(); | ||
} | ||
} | ||
if (appendVertices->filter() != nullptr) { | ||
auto logicExpr = LogicalExpression::makeAnd( | ||
pool, newAppendVerticesFilter, appendVertices->filter()->clone()); | ||
newAppendVerticesFilter = logicExpr; | ||
} | ||
|
||
auto newAppendVertices = static_cast<AppendVertices *>(appendVertices->clone()); | ||
newAppendVertices->setFilter(newAppendVerticesFilter); | ||
|
||
OptGroupNode *newAppendVerticesGroupNode = nullptr; | ||
if (newFilterGroupNode != nullptr) { | ||
// Filter(A&&B)<-AppendVertices(C) => Filter(A)<-AppendVertices(B&&C) | ||
auto newGroup = OptGroup::create(ctx); | ||
newAppendVerticesGroupNode = newGroup->makeGroupNode(newAppendVertices); | ||
newFilterGroupNode->dependsOn(newGroup); | ||
newFilter->setInputVar(newAppendVertices->outputVar()); | ||
} else { | ||
// Filter(A)<-AppendVertices(C) => AppendVertices(A&&C) | ||
newAppendVerticesGroupNode = | ||
OptGroupNode::create(ctx, newAppendVertices, filterGroupNode->group()); | ||
newAppendVertices->setOutputVar(filter->outputVar()); | ||
newAppendVertices->setColNames(appendVertices->colNames()); | ||
} | ||
|
||
for (auto dep : appendVerticesGroupNode->dependencies()) { | ||
newAppendVerticesGroupNode->dependsOn(dep); | ||
} | ||
|
||
TransformResult result; | ||
result.eraseCurr = true; | ||
result.newGroupNodes.emplace_back(newFilterGroupNode ? newFilterGroupNode | ||
: newAppendVerticesGroupNode); | ||
return result; | ||
} | ||
|
||
std::string PushFilterDownAppendVerticesRule::toString() const { | ||
return "PushFilterDownAppendVerticesRule"; | ||
} | ||
|
||
} // namespace opt | ||
} // namespace nebula |
31 changes: 31 additions & 0 deletions
31
src/graph/optimizer/rule/PushFilterDownAppendVerticesRule.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,31 @@ | ||
/* Copyright (c) 2023 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#ifndef GRAPH_OPTIMIZER_RULE_PUSHLIMITDOWNAPPENDVERTICES_H_ | ||
#define GRAPH_OPTIMIZER_RULE_PUSHLIMITDOWNAPPENDVERTICES_H_ | ||
|
||
#include "graph/optimizer/OptRule.h" | ||
|
||
namespace nebula { | ||
namespace opt { | ||
|
||
class PushFilterDownAppendVerticesRule final : public OptRule { | ||
public: | ||
const Pattern &pattern() const override; | ||
|
||
StatusOr<TransformResult> transform(OptContext *ctx, const MatchedResult &matched) const override; | ||
|
||
std::string toString() const override; | ||
|
||
private: | ||
PushFilterDownAppendVerticesRule(); | ||
|
||
static std::unique_ptr<OptRule> kInstance; | ||
}; | ||
|
||
} // namespace opt | ||
} // namespace nebula | ||
|
||
#endif // GRAPH_OPTIMIZER_RULE_PUSHFILTERDOWNAPPENDVERTICES_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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to port the latest version of this file from the ent repo. I introduced a bug fix here at line:48.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which pr?