Skip to content

Commit

Permalink
fix issue 4765
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince committed Oct 21, 2022
1 parent 92e9a08 commit 60105fa
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 138 deletions.
2 changes: 2 additions & 0 deletions src/graph/planner/ngql/GoPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ PlanNode* GoPlanner::lastStep(PlanNode* dep, PlanNode* join) {
gd->setInputVar(goCtx_->vidsVar);
gd->setColNames({goCtx_->dstIdColName});
auto* dedup = Dedup::make(qctx, gd);
dedup->setColNames(gd->colNames());
cur = dedup;

if (goCtx_->joinDst) {
Expand Down Expand Up @@ -486,6 +487,7 @@ SubPlan GoPlanner::nStepsPlan(SubPlan& startVidPlan) {
gd->setColNames({goCtx_->dstIdColName});
auto* dedup = Dedup::make(qctx, gd);
dedup->setOutputVar(goCtx_->vidsVar);
dedup->setColNames(gd->colNames());
getDst = dedup;

loopBody = getDst;
Expand Down
24 changes: 24 additions & 0 deletions src/graph/util/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ const Expression *ExpressionUtils::findAny(const Expression *self,
return nullptr;
}

bool ExpressionUtils::findEdgeDstExpr(const Expression *expr) {
auto finder = [](const Expression *e) -> bool {
if (e->kind() == Expression::Kind::kEdgeDst) {
return true;
} else {
auto name = e->toString();
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
if (name == "id($$)") {
return true;
}
}
return false;
};
if (finder(expr)) {
return true;
}
FindVisitor visitor(finder);
const_cast<Expression *>(expr)->accept(&visitor);
if (!visitor.results().empty()) {
return true;
}
return false;
}

// Finds all expressions fit the exprected list
// Returns an empty vector if no expression found
std::vector<const Expression *> ExpressionUtils::collectAll(
Expand Down
3 changes: 3 additions & 0 deletions src/graph/util/ExpressionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class ExpressionUtils {
// Checks if expr contains function call expression that generate a random value
static bool findInnerRandFunction(const Expression* expr);

// Checks if expr contains function EdgeDst expr or id($$) expr
static bool findEdgeDstExpr(const Expression* expr);

// ** Loop node condition **
// Generates an expression that is used as the condition of loop node:
// ++loopSteps <= steps
Expand Down
11 changes: 10 additions & 1 deletion src/graph/validator/GoValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ Status GoValidator::validateWhere(WhereClause* where) {
return Status::SemanticError(ss.str());
}

goCtx_->filter = rewriteVertexEdge2EdgeProp(filter);
NG_RETURN_IF_ERROR(deduceProps(filter, goCtx_->exprProps, &tagIds_, &goCtx_->over.edgeTypes));
goCtx_->filter = filter;
return Status::OK();
}

Expand Down Expand Up @@ -311,6 +311,15 @@ bool GoValidator::isSimpleCase() {
}
if (exprProps.hasInputVarProperty()) return false;

// Check filter clause
// Because GetDstBySrc doesn't support filter push down,
// so we don't optimize such case.
if (goCtx_->filter) {
if (ExpressionUtils::findEdgeDstExpr(goCtx_->filter)) {
return false;
}
}

// Check yield clause
if (!goCtx_->distinct) return false;
bool atLeastOneDstId = false;
Expand Down
Loading

0 comments on commit 60105fa

Please sign in to comment.