diff --git a/src/graph/planner/match/LabelIndexSeek.cpp b/src/graph/planner/match/LabelIndexSeek.cpp index d2245a34e1a..e9418492140 100644 --- a/src/graph/planner/match/LabelIndexSeek.cpp +++ b/src/graph/planner/match/LabelIndexSeek.cpp @@ -88,11 +88,18 @@ StatusOr LabelIndexSeek::transformNode(NodeContext* nodeCtx) { auto* filter = ExpressionUtils::rewriteInnerInExpr(nodeCtx->bindWhereClause->filter); const auto& nodeAlias = nodeCtx->info->alias; const auto& schemaName = nodeCtx->scanInfo.schemaNames.back(); - if (filter->kind() == Expression::Kind::kLogicalOr) { - auto exprs = ExpressionUtils::collectAll(filter, {Expression::Kind::kLabelTagProperty}); + auto exprs = ExpressionUtils::collectAll( + filter, {Expression::Kind::kLabelTagProperty, Expression::Kind::kLabelAttribute}); bool matched = exprs.empty() ? false : true; for (auto* expr : exprs) { + if (expr->kind() == Expression::Kind::kLabelAttribute) { + // The LabelAttributeExpression should not be encoded. For attributes on vertices, they + // should be rewritten as LabelTagPropertyExpression, and for attributes on edges, they + // should not be embedded into this planNode. + matched = false; + break; + } auto tagPropExpr = static_cast(expr); if (static_cast(tagPropExpr->label())->prop() != nodeAlias || tagPropExpr->sym() != schemaName) { diff --git a/tests/tck/features/bugfix/LabelIndexCrash.feature b/tests/tck/features/bugfix/LabelIndexCrash.feature new file mode 100644 index 00000000000..05a9d0a875f --- /dev/null +++ b/tests/tck/features/bugfix/LabelIndexCrash.feature @@ -0,0 +1,29 @@ +# Copyright (c) 2024 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. +Feature: label index bug fix + + Background: + Given a graph with space named "nba" + + @testmark + Scenario: attribute expression encode crash + When try to execute query: + """ + MATCH (x:bachelor) + WHERE x.bachelor.name == "Tim Duncan" + or x.name == "Tim Duncan" + RETURN x.bachelor.name; + """ + Then the result should be, in any order: + | x.bachelor.name | + | "Tim Duncan" | + When try to execute query: + """ + MATCH (v:bachelor)-[e:serve]-(v2) + WHERE v.bachelor.name == "Tim Duncan" or e.start_year > 2000 + RETURN v.bachelor.name,e.start_year + """ + Then the result should be, in any order: + | v.bachelor.name | e.start_year | + | "Tim Duncan" | 1997 |