-
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
Feature/index scan limit push down #2823
Closed
Shylock-Hg
wants to merge
23
commits into
vesoft-inc:master
from
Shylock-Hg:feature/index-scan-limit-push-down
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6763494
Add the polymorphsim mechanism for plan node.
Shylock-Hg 0cd521a
Merge branch 'master' into feature/node-polymorphsim
Shylock-Hg 2ba7820
Fix the typo.
Shylock-Hg 5f900d9
Merge branch 'feature/node-polymorphsim' into feature/index-scan-limi…
Shylock-Hg 3f78095
Correct the singleton mt-safe.
Shylock-Hg 12b5c3a
Merge branch 'feature/node-polymorphsim' of github.com:Shylock-Hg/neb…
Shylock-Hg eec2f75
Merge branch 'feature/node-polymorphsim' into feature/index-scan-limi…
Shylock-Hg 30f68e5
Push limit to IndexScan.
Shylock-Hg 91e807e
Merge branch 'master' of https://github.com/vesoft-inc/nebula into fe…
Shylock-Hg 03b70a1
Push down to storage.
Shylock-Hg 017356a
Merge branch 'master' into feature/index-scan-limit-push-down
Shylock-Hg 2fb34dd
Merge branch 'master' of https://github.com/vesoft-inc/nebula into fe…
Shylock-Hg 900b88d
Merge branch 'master' into feature/index-scan-limit-push-down
Shylock-Hg eb708d0
Merge branch 'master' into feature/index-scan-limit-push-down
Shylock-Hg e910d28
Merge branch 'master' into feature/index-scan-limit-push-down
Shylock-Hg a5534ea
Limit clause for lookup sentence.
Shylock-Hg fa879b7
Merge branch 'master' into feature/index-scan-limit-push-down
Shylock-Hg 68bff72
Remove the unused include.
Shylock-Hg a34eaf7
Merge branch 'feature/index-scan-limit-push-down' of github.com:Shylo…
Shylock-Hg 94055ca
Add method to check base type.
Shylock-Hg b15ad09
Merge branch 'master' into feature/index-scan-limit-push-down
Shylock-Hg 6a5fb69
Merge branch 'master' of https://github.com/vesoft-inc/nebula into fe…
Shylock-Hg 4b995d8
Reserve space for query kind.
Shylock-Hg 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#include "graph/optimizer/rule/PushLimitDownIndexScanRule.h" | ||
|
||
#include "common/expression/BinaryExpression.h" | ||
#include "common/expression/ConstantExpression.h" | ||
#include "common/expression/Expression.h" | ||
#include "common/expression/FunctionCallExpression.h" | ||
#include "common/expression/LogicalExpression.h" | ||
#include "common/expression/UnaryExpression.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/visitor/ExtractFilterExprVisitor.h" | ||
|
||
using nebula::graph::IndexScan; | ||
using nebula::graph::Limit; | ||
using nebula::graph::PlanNode; | ||
using nebula::graph::Project; | ||
using nebula::graph::QueryContext; | ||
|
||
namespace nebula { | ||
namespace opt { | ||
|
||
std::unique_ptr<OptRule> PushLimitDownIndexScanRule::kInstance = | ||
std::unique_ptr<PushLimitDownIndexScanRule>(new PushLimitDownIndexScanRule()); | ||
|
||
PushLimitDownIndexScanRule::PushLimitDownIndexScanRule() { RuleSet::QueryRules().addRule(this); } | ||
|
||
const Pattern &PushLimitDownIndexScanRule::pattern() const { | ||
static Pattern pattern = Pattern::create( | ||
graph::PlanNode::Kind::kLimit, | ||
{Pattern::create(graph::PlanNode::Kind::kProject, | ||
{Pattern::create(graph::PlanNode::Kind::kIndexScan, {}, true)})}); | ||
return pattern; | ||
} | ||
|
||
StatusOr<OptRule::TransformResult> PushLimitDownIndexScanRule::transform( | ||
OptContext *octx, const MatchedResult &matched) const { | ||
auto limitGroupNode = matched.node; | ||
auto projGroupNode = matched.dependencies.front().node; | ||
auto indexScanGroupNode = matched.dependencies.front().dependencies.front().node; | ||
|
||
const auto limit = limitGroupNode->node()->asNode<const Limit>(); | ||
const auto proj = projGroupNode->node()->asNode<const Project>(); | ||
const auto indexScan = indexScanGroupNode->node()->asNode<const IndexScan>(); | ||
|
||
int64_t limitRows = limit->offset() + limit->count(); | ||
critical27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (indexScan->limit() >= 0 && limitRows >= indexScan->limit()) { | ||
return TransformResult::noTransform(); | ||
} | ||
|
||
auto newLimit = static_cast<Limit *>(limit->clone()); | ||
auto newLimitGroupNode = OptGroupNode::create(octx, newLimit, limitGroupNode->group()); | ||
|
||
auto newProj = static_cast<Project *>(proj->clone()); | ||
auto newProjGroup = OptGroup::create(octx); | ||
auto newProjGroupNode = newProjGroup->makeGroupNode(newProj); | ||
|
||
auto newIndexScan = static_cast<IndexScan *>(indexScan->clone()); | ||
newIndexScan->setLimit(limitRows); | ||
auto newIndexScanGroup = OptGroup::create(octx); | ||
auto newIndexScanGroupNode = newIndexScanGroup->makeGroupNode(newIndexScan); | ||
|
||
newLimitGroupNode->dependsOn(newProjGroup); | ||
newProjGroupNode->dependsOn(newIndexScanGroup); | ||
for (auto dep : indexScanGroupNode->dependencies()) { | ||
newIndexScanGroupNode->dependsOn(dep); | ||
} | ||
|
||
TransformResult result; | ||
result.eraseAll = true; | ||
result.newGroupNodes.emplace_back(newLimitGroupNode); | ||
return result; | ||
} | ||
|
||
std::string PushLimitDownIndexScanRule::toString() const { return "PushLimitDownIndexScanRule"; } | ||
|
||
} // namespace opt | ||
} // namespace nebula |
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,32 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "graph/optimizer/OptRule.h" | ||
|
||
namespace nebula { | ||
namespace opt { | ||
|
||
class PushLimitDownIndexScanRule final : public OptRule { | ||
public: | ||
const Pattern &pattern() const override; | ||
|
||
StatusOr<OptRule::TransformResult> transform(OptContext *ctx, | ||
const MatchedResult &matched) const override; | ||
|
||
std::string toString() const override; | ||
|
||
private: | ||
PushLimitDownIndexScanRule(); | ||
|
||
static std::unique_ptr<OptRule> kInstance; | ||
}; | ||
|
||
} // namespace opt | ||
} // namespace nebula |
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.
here should not be one opt rule, but should be split into two rules: limit <-> project, limit -> indexscan
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.
Why need limit->indexscan?
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.
Push limit down indexscan
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.
The sentence only generate
limit
->project
->indexscan
planThere 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.
You should consider the optimization rules from the perspective of the optimizer, not just for this case.
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.
We don't need to match the nonexistent pattern.