diff --git a/src/graph/optimizer/rule/PushFilterDownTraverseRule.cpp b/src/graph/optimizer/rule/PushFilterDownTraverseRule.cpp index 3ea748a2fd5..434767c359d 100644 --- a/src/graph/optimizer/rule/PushFilterDownTraverseRule.cpp +++ b/src/graph/optimizer/rule/PushFilterDownTraverseRule.cpp @@ -46,9 +46,7 @@ bool PushFilterDownTraverseRule::match(OptContext* ctx, const MatchedResult& mat PlanNode::Kind::kTraverse); auto traverse = static_cast(matched.dependencies[0].dependencies[0].node->node()); - auto step = traverse->stepRange(); - // step == nullptr means one step. - return step == nullptr; + return traverse->isOneStep(); } StatusOr PushFilterDownTraverseRule::transform( @@ -60,27 +58,18 @@ StatusOr PushFilterDownTraverseRule::transform( auto* avGroupNode = matched.dependencies[0].node; auto* av = static_cast(avGroupNode->node()); - auto& avColNames = av->colNames(); - auto& nodeAlias = avColNames.back(); - UNUSED(nodeAlias); auto* tvGroupNode = matched.dependencies[0].dependencies[0].node; auto* tv = static_cast(tvGroupNode->node()); - auto& tvColNames = tv->colNames(); - auto& edgeAlias = tvColNames.back(); + auto& edgeAlias = tv->edgeAlias(); auto qctx = ctx->qctx(); auto pool = qctx->objPool(); // Pick the expr looks like `$-.e[0].likeness auto picker = [&edgeAlias](const Expression* e) -> bool { - auto varProps = graph::ExpressionUtils::collectAll(e, - {Expression::Kind::kTagProperty, - Expression::Kind::kEdgeProperty, - Expression::Kind::kInputProperty, - Expression::Kind::kVarProperty, - Expression::Kind::kDstProperty, - Expression::Kind::kSrcProperty}); + auto varProps = graph::ExpressionUtils::collectAll( + e, {Expression::Kind::kInputProperty, Expression::Kind::kVarProperty}); if (varProps.empty()) { return false; } @@ -89,12 +78,7 @@ StatusOr PushFilterDownTraverseRule::transform( auto& propName = static_cast(expr)->prop(); if (propName != edgeAlias) return false; } - auto finder = [&edgeAlias](const Expression* expr) -> bool { - return graph::ExpressionUtils::isSingleLenExpandExpr(edgeAlias, expr); - }; - graph::FindVisitor visitor(finder, true); - const_cast(e)->accept(&visitor); - return !visitor.results().empty(); + return true; }; Expression* filterPicked = nullptr; Expression* filterUnpicked = nullptr; @@ -103,7 +87,7 @@ StatusOr PushFilterDownTraverseRule::transform( if (!filterPicked) { return TransformResult::noTransform(); } - auto* newfilterPicked = + auto* newFilterPicked = graph::ExpressionUtils::rewriteEdgePropertyFilter(pool, edgeAlias, filterPicked->clone()); Filter* newFilter = nullptr; @@ -129,13 +113,9 @@ StatusOr PushFilterDownTraverseRule::transform( } auto* eFilter = tv->eFilter(); - Expression* newEFilter = nullptr; - if (eFilter) { - auto logicExpr = LogicalExpression::makeAnd(pool, newfilterPicked, eFilter->clone()); - newEFilter = logicExpr; - } else { - newEFilter = newfilterPicked; - } + Expression* newEFilter = eFilter + ? LogicalExpression::makeAnd(pool, newFilterPicked, eFilter->clone()) + : newFilterPicked; auto* newTv = static_cast(tv->clone()); newAv->setInputVar(newTv->outputVar()); diff --git a/src/graph/planner/plan/Query.h b/src/graph/planner/plan/Query.h index b39108d9f7c..24b3c8d03d5 100644 --- a/src/graph/planner/plan/Query.h +++ b/src/graph/planner/plan/Query.h @@ -1538,6 +1538,10 @@ class Traverse final : public GetNeighbors { return range_; } + bool isOneStep() const { + return !range_; + } + // Contains zero step bool zeroStep() const { return range_ != nullptr && range_->min() == 0; @@ -1555,6 +1559,17 @@ class Traverse final : public GetNeighbors { return trackPrevPath_; } + const std::string& nodeAlias() const { + auto& cols = this->colNames(); + DCHECK_GE(cols.size(), 2); + return cols[cols.size() - 2]; + } + + const std::string& edgeAlias() const { + DCHECK(!this->colNames().empty()); + return this->colNames().back(); + } + void setStepRange(MatchStepRange* range) { range_ = range; } @@ -1618,6 +1633,11 @@ class AppendVertices final : public GetVertices { return trackPrevPath_; } + const std::string nodeAlias() const { + DCHECK(!this->colNames().empty()); + return this->colNames().back(); + } + void setVertexFilter(Expression* vFilter) { vFilter_ = vFilter; }