From 66e8a6d474735d23ef24b744f4eda3c46682fed5 Mon Sep 17 00:00:00 2001 From: jimingquan <6930445+nevermore3@users.noreply.github.com> Date: Sat, 11 May 2024 18:18:54 +0800 Subject: [PATCH] push step limit down storage (#5880) push step limit down storage " --- src/graph/executor/query/ExpandAllExecutor.cpp | 17 ++++++++++++++--- src/graph/executor/query/ExpandExecutor.cpp | 11 +++++++++-- src/graph/planner/plan/Query.h | 2 +- tests/tck/features/go/SampleLimit.feature | 1 - .../tck/features/go/SampleLimit.intVid.feature | 1 - .../optimizer/PushSampleDownRule.feature | 2 -- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/graph/executor/query/ExpandAllExecutor.cpp b/src/graph/executor/query/ExpandAllExecutor.cpp index d434996f8b1..73aa338004b 100644 --- a/src/graph/executor/query/ExpandAllExecutor.cpp +++ b/src/graph/executor/query/ExpandAllExecutor.cpp @@ -142,6 +142,9 @@ folly::Future ExpandAllExecutor::getNeighbors() { std::vector vids(nextStepVids_.size()); std::move(nextStepVids_.begin(), nextStepVids_.end(), vids.begin()); QueryExpressionContext qec(qctx()->ectx()); + auto stepLimit = + stepLimits_.empty() ? std::numeric_limits::max() : stepLimits_[currentStep_ - 2]; + auto limit = std::min(stepLimit, expand_->limit(qec)); return storageClient ->getNeighbors(param, {nebula::kVid}, @@ -153,9 +156,9 @@ folly::Future ExpandAllExecutor::getNeighbors() { expand_->edgeProps(), nullptr, false, - false, + sample_, std::vector(), - expand_->limit(qec), + limit, expand_->filter(), nullptr) .via(runner()) @@ -402,6 +405,12 @@ folly::Future ExpandAllExecutor::handleResponse(RpcResponse&& resps) { buildResult(curVertexProps, edgeProps); } + if (!stepLimits_.empty()) { + // if stepLimits_ is not empty, do not use cache + nextStepVids_.emplace(dst); + continue; + } + if (adjList_.find(dst) == adjList_.end()) { nextStepVids_.emplace(dst); } else { @@ -413,7 +422,9 @@ folly::Future ExpandAllExecutor::handleResponse(RpcResponse&& resps) { adjList_.emplace(curVid, std::move(adjEdgeProps)); } - resetNextStepVids(visitedVids); + if (stepLimits_.empty()) { + resetNextStepVids(visitedVids); + } if (!preVisitedVids_.empty()) { getNeighborsFromCache(dst2VidsMap, visitedVids, samples); diff --git a/src/graph/executor/query/ExpandExecutor.cpp b/src/graph/executor/query/ExpandExecutor.cpp index 41caf331906..edb388f0e8d 100644 --- a/src/graph/executor/query/ExpandExecutor.cpp +++ b/src/graph/executor/query/ExpandExecutor.cpp @@ -141,6 +141,8 @@ folly::Future ExpandExecutor::getNeighbors() { qctx_->plan()->isProfileEnabled()); std::vector vids(nextStepVids_.size()); std::move(nextStepVids_.begin(), nextStepVids_.end(), vids.begin()); + auto stepLimit = + stepLimits_.empty() ? std::numeric_limits::max() : stepLimits_[currentStep_ - 1]; return storageClient ->getNeighbors(param, {nebula::kVid}, @@ -152,9 +154,9 @@ folly::Future ExpandExecutor::getNeighbors() { expand_->edgeProps(), nullptr, false, - false, + sample_, std::vector(), - -1, + stepLimit, nullptr, nullptr) .via(runner()) @@ -323,6 +325,11 @@ folly::Future ExpandExecutor::handleResponse(RpcResponse&& resps) { if (currentStep_ >= maxSteps_) { continue; } + if (!stepLimits_.empty()) { + // do not use cache when stepLimits_ is not empty + nextStepVids_.emplace(dst); + continue; + } if (adjDsts_.find(dst) == adjDsts_.end()) { nextStepVids_.emplace(dst); } else { diff --git a/src/graph/planner/plan/Query.h b/src/graph/planner/plan/Query.h index 4ab44ceacce..7c5f96f1567 100644 --- a/src/graph/planner/plan/Query.h +++ b/src/graph/planner/plan/Query.h @@ -422,7 +422,7 @@ class ExpandAll : public Expand { } else if (edgeColumns_) { colNames = edgeColumns_->names(); } - setLimit(-1); + setLimit(std::numeric_limits::max()); setColNames(colNames); } diff --git a/tests/tck/features/go/SampleLimit.feature b/tests/tck/features/go/SampleLimit.feature index dc20e0f7550..7ffb6f5052a 100644 --- a/tests/tck/features/go/SampleLimit.feature +++ b/tests/tck/features/go/SampleLimit.feature @@ -72,4 +72,3 @@ Feature: Sample and limit | like._dst | | /[\s\w+]/ | | /[\s\w+]/ | - | /[\s\w+]/ | diff --git a/tests/tck/features/go/SampleLimit.intVid.feature b/tests/tck/features/go/SampleLimit.intVid.feature index 95ae13c6391..4d465e6f71d 100644 --- a/tests/tck/features/go/SampleLimit.intVid.feature +++ b/tests/tck/features/go/SampleLimit.intVid.feature @@ -62,4 +62,3 @@ Feature: Sample and limit | like._dst | | /[\d\-+]/ | | /[\d\-+]/ | - | /[\d\-+]/ | diff --git a/tests/tck/features/optimizer/PushSampleDownRule.feature b/tests/tck/features/optimizer/PushSampleDownRule.feature index 15ce745cdf4..087ae265500 100644 --- a/tests/tck/features/optimizer/PushSampleDownRule.feature +++ b/tests/tck/features/optimizer/PushSampleDownRule.feature @@ -28,7 +28,6 @@ Feature: Push Limit down rule Then the result should be, in any order: | like._dst | | /[\w\s]+/ | - | /[\w\s]+/ | And the execution plan should be: | id | name | dependencies | operator info | | 4 | Project | 3 | | @@ -42,7 +41,6 @@ Feature: Push Limit down rule Then the result should be, in any order: | src | likeness | dst | | /[\w\s]+/ | /\d\d/ | /[\w\s]+/ | - | /[\w\s]+/ | /\d\d/ | /[\w\s]+/ | And the execution plan should be: | id | name | dependencies | profiling data | operator info | | 8 | Project | 7 | | |