Skip to content

Commit

Permalink
Support variable when seeking vertex id or property index in match (v…
Browse files Browse the repository at this point in the history
…esoft-inc#2776)

* Support variable when seeking by id in match clause vesoft-inc#5486

* Support variable when seeking by property index in match clause (vesoft-inc#5553)

* Support variable when seeking by prop index in match clause

* Rename

* Move the index query context construction outside of OptRule

* Move the optimizer utils to common graph util folder

* Eval argument values in index scan executor

* Fix bug

* refactor and fix error

* Update tck tests

---------

Co-authored-by: Sophie <[email protected]>

* Resolve the conflicts

---------

Co-authored-by: Yee <[email protected]>
  • Loading branch information
Sophie-Xie and yixinglu authored May 18, 2023
1 parent 63c7e26 commit 5e27f2c
Show file tree
Hide file tree
Showing 32 changed files with 2,328 additions and 1,288 deletions.
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

0 comments on commit 5e27f2c

Please sign in to comment.