Skip to content

Commit

Permalink
fix PrunePropertiesVisitor bug (#5793)
Browse files Browse the repository at this point in the history
  • Loading branch information
Salieri-004 authored Dec 29, 2023
1 parent 5d308fc commit cba6f5f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/graph/optimizer/Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ StatusOr<const PlanNode *> Optimizer::findBestPlan(QueryContext *qctx) {
auto optCtx = std::make_unique<OptContext>(qctx);

auto root = qctx->plan()->root();
auto spaceID = qctx->rctx()->session()->space().id;

auto spaceID = nebula::graph::kInvalidSpaceID;
if (qctx->vctx()->spaceChosen()) {
spaceID = qctx->vctx()->whichSpace().id;
}
NG_RETURN_IF_ERROR(checkPlanDepth(root));
auto ret = prepare(optCtx.get(), root);
NG_RETURN_IF_ERROR(ret);
Expand Down
12 changes: 2 additions & 10 deletions src/graph/visitor/PropertyTrackerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,8 @@ void PropertyTrackerVisitor::visit(LabelTagPropertyExpression *expr) {

auto ret = qctx_->schemaMng()->toTagID(space_, tagName);
if (!ret.ok()) {
// if the we switch space in the query, we need to get the space id from the validation context
// use xxx; match xxx
if (qctx_->vctx()->spaceChosen()) {
space_ = qctx_->vctx()->whichSpace().id;
ret = qctx_->schemaMng()->toTagID(qctx_->vctx()->whichSpace().id, tagName);
if (!ret.ok()) {
status_ = std::move(ret).status();
return;
}
}
status_ = std::move(ret).status();
return;
}

auto tagId = ret.value();
Expand Down
21 changes: 21 additions & 0 deletions src/graph/visitor/PrunePropertiesVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ void PrunePropertiesVisitor::visit(Filter *node) {
return;
}
visitCurrent(node); // Filter will use properties in filter expression
if (!status_.ok()) {
return;
}
status_ = depsPruneProperties(node->dependencies());
}

Expand All @@ -44,6 +47,9 @@ void PrunePropertiesVisitor::visit(Project *node) {
return;
}
visitCurrent(node); // Project won't use properties in column expression
if (!status_.ok()) {
return;
}
status_ = depsPruneProperties(node->dependencies());
}

Expand Down Expand Up @@ -120,6 +126,9 @@ void PrunePropertiesVisitor::visit(Aggregate *node) {
return;
}
visitCurrent(node);
if (!status_.ok()) {
return;
}
status_ = depsPruneProperties(node->dependencies());
}

Expand Down Expand Up @@ -170,6 +179,9 @@ void PrunePropertiesVisitor::visit(ScanEdges *node) {
}
rootNode_ = false;
pruneCurrent(node);
if (!status_.ok()) {
return;
}
status_ = depsPruneProperties(node->dependencies());
}

Expand Down Expand Up @@ -228,6 +240,9 @@ void PrunePropertiesVisitor::visit(Traverse *node) {
}
rootNode_ = false;
visitCurrent(node);
if (!status_.ok()) {
return;
}
status_ = depsPruneProperties(node->dependencies());
}

Expand Down Expand Up @@ -380,6 +395,9 @@ void PrunePropertiesVisitor::visit(AppendVertices *node) {
return;
}
visitCurrent(node);
if (!status_.ok()) {
return;
}
status_ = depsPruneProperties(node->dependencies());
}

Expand Down Expand Up @@ -524,6 +542,9 @@ void PrunePropertiesVisitor::visit(Unwind *node) {
return;
}
visitCurrent(node);
if (!status_.ok()) {
return;
}
status_ = depsPruneProperties(node->dependencies());
}

Expand Down
27 changes: 27 additions & 0 deletions tests/tck/features/bugfix/PrunePropertiesError.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2023 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: Test PrunePropertiesVisitor when switching space

Scenario: Test PrunePropertiesVisitor when switching space
When executing query:
"""
USE student;
"""
Then the execution should be successful
When profiling query:
"""
USE nba;
MATCH (u:player)
RETURN count(*)
"""
Then the result should be, in any order:
| count(*) |
| 56 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 6 | Aggregate | 8 | |
| 8 | AppendVertices | 2 | { "props": "[{\"props\":[\"_tag\"]}]" } |
| 2 | IndexScan | 1 | |
| 1 | RegisterSpaceToSession | 0 | |
| 0 | Start | | |

0 comments on commit cba6f5f

Please sign in to comment.