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

fix allpath limit #5699

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion src/graph/executor/algo/AllPathsExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ folly::Future<Status> AllPathsExecutor::execute() {
if (pathNode_->limit() != -1) {
limit_ = pathNode_->limit();
}
if (pathNode_->offset() != 0) {
offset_ = pathNode_->offset();
}
buildRequestVids(true);
buildRequestVids(false);
result_.colNames = pathNode_->colNames();
if (maxStep_ == 0 || leftNextStepVids_.empty() || rightNextStepVids_.empty()) {
if (limit_ == 0 || limit_ == offset_ || maxStep_ == 0 || leftNextStepVids_.empty() ||
rightNextStepVids_.empty()) {
return finish(ResultBuilder().value(Value(std::move(result_))).build());
}
return doAllPaths();
Expand Down Expand Up @@ -556,6 +560,9 @@ folly::Future<Status> AllPathsExecutor::conjunctPath(std::vector<NPath*>& leftPa
if (result_.rows.size() > limit_) {
result_.rows.resize(limit_);
}
if (offset_ != 0) {
result_.rows.erase(result_.rows.begin(), result_.rows.begin() + offset_);
}
return Status::OK();
})
.thenError(folly::tag_t<std::bad_alloc>{},
Expand Down
1 change: 1 addition & 0 deletions src/graph/executor/algo/AllPathsExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class AllPathsExecutor final : public StorageAccessExecutor {
const AllPaths* pathNode_{nullptr};
bool withProp_{false};
bool noLoop_{false};
size_t offset_{0};
size_t limit_{std::numeric_limits<size_t>::max()};
std::atomic<size_t> cnt_{0};
std::atomic<bool> memoryExceeded_{false};
Expand Down
1 change: 1 addition & 0 deletions src/graph/optimizer/rule/PushLimitDownAllPathsRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ StatusOr<OptRule::TransformResult> PushLimitDownAllPathsRule::transform(
OptGroupNode *newPathGroupNode = nullptr;
// Limit<-AllPaths => AllPaths(limit)
newPathGroupNode = OptGroupNode::create(ctx, newPath, limitGroupNode->group());
newPath->setOffset(limit->offset());
newPath->setLimit(limitRows);
newPath->setOutputVar(limit->outputVar());

Expand Down
2 changes: 2 additions & 0 deletions src/graph/planner/plan/Algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PlanNode* AllPaths::clone() const {

void AllPaths::cloneMembers(const AllPaths& path) {
BinaryInputNode::cloneMembers(path);
offset_ = path.offset_;
limit_ = path.limit_;
filter_ = path.filter_;
stepFilter_ = path.stepFilter_;
Expand Down Expand Up @@ -96,6 +97,7 @@ std::unique_ptr<PlanNodeDescription> AllPaths::explain() const {
addDescription("steps", folly::toJson(util::toJson(steps_)), desc.get());
addDescription("filter", filter_ == nullptr ? "" : filter_->toString(), desc.get());
addDescription("stepFilter", stepFilter_ == nullptr ? "" : stepFilter_->toString(), desc.get());
addDescription("offset", folly::toJson(util::toJson(offset_)), desc.get());
addDescription("limit", folly::toJson(util::toJson(limit_)), desc.get());
addDescription(
"vertexProps", vertexProps_ ? folly::toJson(util::toJson(*vertexProps_)) : "", desc.get());
Expand Down
9 changes: 9 additions & 0 deletions src/graph/planner/plan/Algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ class AllPaths final : public BinaryInputNode {
return limit_;
}

int64_t offset() const {
return offset_;
}

const std::vector<EdgeProp>* edgeProps() const {
return edgeProps_.get();
}
Expand All @@ -219,6 +223,10 @@ class AllPaths final : public BinaryInputNode {
return space_;
}

void setOffset(int64_t offset) {
offset_ = offset;
}

void setLimit(int64_t limit) {
limit_ = limit;
}
Expand Down Expand Up @@ -267,6 +275,7 @@ class AllPaths final : public BinaryInputNode {
size_t steps_{0};
bool noLoop_{false};
bool withProp_{false};
int64_t offset_{0};
int64_t limit_{-1};
Expression* filter_{nullptr};
Expression* stepFilter_{nullptr};
Expand Down
27 changes: 27 additions & 0 deletions tests/tck/features/path/AllPath.feature
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,33 @@ Feature: All Path
Then the result should be, in any order, with relax comparison:
| cnt |
| 3 |
When executing query:
"""
$start = LOOKUP ON player WHERE player.age > 30 YIELD id(vertex) AS id;
$end = LOOKUP ON player WHERE player.age <= 30 YIELD id(vertex) AS id;
FIND ALL PATH FROM $start.id TO $end.id OVER * BIDIRECT YIELD path AS p | LIMIT 0, 174 | YIELD count(*)
"""
Then the result should be, in any order, with relax comparison:
| count(*) |
| 174 |
When executing query:
"""
$start = LOOKUP ON player WHERE player.age > 30 YIELD id(vertex) AS id;
$end = LOOKUP ON player WHERE player.age <= 30 YIELD id(vertex) AS id;
FIND ALL PATH FROM $start.id TO $end.id OVER * BIDIRECT YIELD path AS p | LIMIT 100, 174 | YIELD count(*)
"""
Then the result should be, in any order, with relax comparison:
| count(*) |
| 174 |
When executing query:
"""
$start = LOOKUP ON player WHERE player.age > 30 YIELD id(vertex) AS id;
$end = LOOKUP ON player WHERE player.age <= 30 YIELD id(vertex) AS id;
FIND ALL PATH FROM $start.id TO $end.id OVER * BIDIRECT YIELD path AS p | LIMIT 100, 0 | YIELD count(*)
"""
Then the result should be, in any order, with relax comparison:
| count(*) |
| 0 |

Scenario: [1] ALL PATH REVERSELY
When executing query:
Expand Down
Loading