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
2 changes: 1 addition & 1 deletion src/graph/context/ast/CypherAstContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct NodeContext final : PatternContext {
: PatternContext(PatternKind::kNode, q, b, g), info(i) {}

const NodeInfo* info;
std::unordered_set<std::string>* nodeAliasesAvailable{nullptr};
std::unordered_set<std::string>* aliasesAvailable{nullptr};

// Output fields
Set ids;
Expand Down
4 changes: 4 additions & 0 deletions src/graph/executor/logic/ArgumentExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ folly::Future<Status> ArgumentExecutor::execute() {
for (auto &v : val.getList().values) {
addRow(v);
}
} else if (val.isSet()) {
for (auto &v : val.getSet().values) {
addRow(v);
}
} else {
addRow(val);
}
Expand Down
46 changes: 45 additions & 1 deletion src/graph/executor/query/IndexScanExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#include "graph/executor/query/IndexScanExecutor.h"

#include "graph/service/GraphFlags.h"
#include "graph/util/OptimizerUtils.h"

using nebula::storage::StorageClient;
using nebula::storage::StorageRpcResponse;
using nebula::storage::cpp2::LookupIndexResp;

using IndexQueryContextList = nebula::graph::OptimizerUtils::IndexQueryContextList;

namespace nebula {
namespace graph {

Expand All @@ -20,8 +23,49 @@ folly::Future<Status> IndexScanExecutor::execute() {
folly::Future<Status> IndexScanExecutor::indexScan() {
StorageClient *storageClient = qctx_->getStorageClient();
auto *lookup = asNode<IndexScan>(node());
auto objPool = qctx()->objPool();

IndexQueryContextList ictxs;
if (lookup->lazyIndexHint()) {
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: %s",
filter->toString().c_str());
}
auto relFilter = static_cast<const RelationalExpression *>(filter);
auto right = DCHECK_NOTNULL(relFilter->right());
if (right->kind() != Expression::Kind::kLabel) {
return Status::Error("The kind of expression is not label expression: %s",
right->toString().c_str());
}
const auto &colName = static_cast<const LabelExpression *>(right)->name();
const auto &result = ectx_->getResult(lookup->inputVar());
std::vector<Expression *> ops;
std::unordered_set<Value> unique;
for (auto iter = result.iterRef(); iter->valid(); iter->next()) {
const auto &val = iter->getColumn(colName);
if (!unique.emplace(val).second) continue;
auto constExpr = ConstantExpression::make(objPool, val);
auto leftExpr = relFilter->left()->clone();
auto newRelExpr = RelationalExpression::makeEQ(objPool, leftExpr, constExpr);
ops.push_back(newRelExpr);
}

const auto &ictxs = lookup->queryContext();
if (ops.empty()) {
return finish(ResultBuilder().value(Value(List())).iter(Iterator::Kind::kProp).build());
}

if (ops.size() == 1u) {
NG_RETURN_IF_ERROR(OptimizerUtils::createIndexQueryCtx(ops[0], qctx(), lookup, ictxs));
} else {
auto logExpr = LogicalExpression::makeOr(objPool);
logExpr->setOperands(std::move(ops));
NG_RETURN_IF_ERROR(OptimizerUtils::createIndexQueryCtx(logExpr, qctx(), lookup, ictxs));
}
} else {
ictxs = lookup->queryContext();
}
auto iter = std::find_if(
ictxs.begin(), ictxs.end(), [](auto &ictx) { return !ictx.index_id_ref().is_set(); });
if (ictxs.empty() || iter != ictxs.end()) {
Expand Down
1 change: 0 additions & 1 deletion src/graph/optimizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
nebula_add_library(
optimizer_obj
OBJECT
OptimizerUtils.cpp
Optimizer.cpp
OptGroup.cpp
OptRule.cpp
Expand Down
Loading