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

Support variable when seeking by property index in match clause #5553

Merged
merged 10 commits into from
May 18, 2023
Prev Previous commit
Next Next commit
Fix bug
  • Loading branch information
yixinglu committed May 16, 2023
commit c30f87ce51c2fa8521963f618bd239b9e3748320
7 changes: 4 additions & 3 deletions src/graph/executor/query/IndexScanExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ folly::Future<Status> IndexScanExecutor::indexScan() {

IndexQueryContextList ictxs;
if (lookup->lazyIndexHint()) {
Expression *filter = Expression::decode(qctx()->objPool(), ictxs.front().get_filter());
if (filter->kind() != Expression::Kind::kRelEQ || filter->kind() != Expression::Kind::kRelIn) {
auto filterStr = lookup->queryContext().front().get_filter();
Expression *filter = Expression::decode(qctx()->objPool(), filterStr);
if (filter->kind() != Expression::Kind::kRelEQ && filter->kind() != Expression::Kind::kRelIn) {
return Status::Error("The kind of filter expression is invalid.");
}
auto relFilter = static_cast<const RelationalExpression *>(filter);
Expand All @@ -48,7 +49,7 @@ folly::Future<Status> IndexScanExecutor::indexScan() {
return Status::Error("IN expression could not support multi-rows index scan.");
}
const auto &val = iter->getColumn(colName);
if (!val.isList() || !val.isSet()) {
if (!val.isList() && !val.isSet()) {
return Status::Error("The values is not list or set in expression: %s",
filter->toString().c_str());
}
Expand Down
17 changes: 12 additions & 5 deletions src/graph/planner/match/VariablePropIndexSeek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ bool VariablePropIndexSeek::matchNode(NodeContext* nodeCtx) {
bool found = false;
for (auto op : logExpr->operands()) {
if (getIndexItem(nodeCtx, op, label, nodeInfo.alias, &refVarName, &propName, &idxItem)) {
if (!nodeCtx->aliasesAvailable->count(refVarName)) {
return false;
}
// TODO(yee): Only select the first index as candidate filter expression and not support
// the combined index
indexFilter = TagPropertyExpression::make(nodeCtx->qctx->objPool(), label, propName);
Expand All @@ -55,15 +58,17 @@ bool VariablePropIndexSeek::matchNode(NodeContext* nodeCtx) {
if (!getIndexItem(nodeCtx, filter, label, nodeInfo.alias, &refVarName, &propName, &idxItem)) {
return false;
}
}

if (!nodeCtx->aliasesAvailable->count(refVarName)) {
return false;
if (!nodeCtx->aliasesAvailable->count(refVarName)) {
return false;
}

indexFilter = TagPropertyExpression::make(nodeCtx->qctx->objPool(), label, propName);
}

nodeCtx->refVarName = refVarName;

nodeCtx->scanInfo.filter = indexFilter;
nodeCtx->scanInfo.filter = DCHECK_NOTNULL(indexFilter);
nodeCtx->scanInfo.schemaIds = nodeInfo.tids;
nodeCtx->scanInfo.schemaNames = nodeInfo.labels;

Expand All @@ -79,11 +84,13 @@ StatusOr<SubPlan> VariablePropIndexSeek::transformNode(NodeContext* nodeCtx) {
auto qctx = nodeCtx->qctx;
auto argument = Argument::make(qctx, nodeCtx->refVarName);
argument->setColNames({nodeCtx->refVarName});
argument->setInputVertexRequired(false);
IndexQueryContext iqctx;
iqctx.filter_ref() = Expression::encode(*nodeCtx->scanInfo.filter);
auto scan = IndexScan::make(
qctx, argument, nodeCtx->spaceId, {std::move(iqctx)}, {kVid}, false, schemaIds.back());
scan->setColNames({kVid});
scan->setLazyIndexHint(true);
plan.tail = argument;
plan.root = scan;

Expand All @@ -110,7 +117,7 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
return false;
}

if (!MatchSolver::extractTagPropName(relInExpr->left(), label, alias, propName)) {
if (!MatchSolver::extractTagPropName(relInExpr->left(), alias, label, propName)) {
return false;
}
// TODO(yee): workaround for index selection
Expand Down