Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crush caused by OptimizeTagIndexScanByFilterRule #3525

Merged
merged 3 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/graph/optimizer/rule/OptimizeTagIndexScanByFilterRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,27 @@ StatusOr<TransformResult> OptimizeTagIndexScanByFilterRule::transform(
}

// case2: logical AND expr
if (condition->kind() == ExprKind::kLogicalAnd) {
size_t operandIndex = 0;
if (conditionType == ExprKind::kLogicalAnd) {
for (auto& operand : static_cast<const LogicalExpression*>(condition)->operands()) {
if (operand->kind() == ExprKind::kRelIn) {
auto inExpr = static_cast<RelationalExpression*>(operand);
// Do not apply this rule if the IN expr has a valid index or it has only 1 element in the
// list
// Do not apply this rule if the IN expr has a valid index or it has more than 1 element in
// the list
if (static_cast<ListExpression*>(inExpr->right())->size() > 1) {
return TransformResult::noTransform();
} else {
transformedExpr = graph::ExpressionUtils::rewriteInExpr(condition);
// If the inner IN expr has only 1 element, rewrite it to an relEQ expression and there is
// no need to check wether it has a index
auto relEqExpr = graph::ExpressionUtils::rewriteInExpr(inExpr);
static_cast<LogicalExpression*>(transformedExpr)->setOperand(operandIndex, relEqExpr);
continue;
}
if (OptimizerUtils::relExprHasIndex(inExpr, indexItems)) {
return TransformResult::noTransform();
}
}
++operandIndex;
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/tck/features/lookup/TagIndexFullScan.feature
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ Feature: Lookup tag index full scan
| 3 | Project | 4 | |
| 4 | IndexScan | 0 | |
| 0 | Start | | |
# c AND (a IN b) where b contains only 1 element
# (https://github.com/vesoft-inc/nebula/issues/3524)
When profiling query:
"""
LOOKUP ON player WHERE player.age IN [40] AND player.name == "Kobe Bryant" YIELD id(vertex) as id, player.age
"""
Then the result should be, in any order:
| id | player.age |
| "Kobe Bryant" | 40 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 3 | Project | 4 | |
| 4 | TagIndexPrefixScan | 0 | |
| 0 | Start | | |

Scenario: Tag with complex relational IN filter
Given an empty graph
Expand Down