Skip to content

Commit 5e27f2c

Browse files
Sophie-Xieyixinglu
andauthored
Support variable when seeking vertex id or property index in match (vesoft-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 <84560950+Sophie-Xie@users.noreply.github.com> * Resolve the conflicts --------- Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com>
1 parent 63c7e26 commit 5e27f2c

32 files changed

+2328
-1288
lines changed

src/graph/context/ast/CypherAstContext.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ struct NodeContext final : PatternContext {
250250
: PatternContext(PatternKind::kNode, q, b, g), info(i) {}
251251

252252
const NodeInfo* info;
253-
std::unordered_set<std::string>* nodeAliasesAvailable{nullptr};
253+
std::unordered_set<std::string>* aliasesAvailable{nullptr};
254254

255255
// Output fields
256256
Set ids;

src/graph/executor/logic/ArgumentExecutor.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ folly::Future<Status> ArgumentExecutor::execute() {
5353
for (auto &v : val.getList().values) {
5454
addRow(v);
5555
}
56+
} else if (val.isSet()) {
57+
for (auto &v : val.getSet().values) {
58+
addRow(v);
59+
}
5660
} else {
5761
addRow(val);
5862
}

src/graph/executor/query/IndexScanExecutor.cpp

+45-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#include "graph/executor/query/IndexScanExecutor.h"
66

77
#include "graph/service/GraphFlags.h"
8+
#include "graph/util/OptimizerUtils.h"
89

910
using nebula::storage::StorageClient;
1011
using nebula::storage::StorageRpcResponse;
1112
using nebula::storage::cpp2::LookupIndexResp;
1213

14+
using IndexQueryContextList = nebula::graph::OptimizerUtils::IndexQueryContextList;
15+
1316
namespace nebula {
1417
namespace graph {
1518

@@ -20,8 +23,49 @@ folly::Future<Status> IndexScanExecutor::execute() {
2023
folly::Future<Status> IndexScanExecutor::indexScan() {
2124
StorageClient *storageClient = qctx_->getStorageClient();
2225
auto *lookup = asNode<IndexScan>(node());
26+
auto objPool = qctx()->objPool();
27+
28+
IndexQueryContextList ictxs;
29+
if (lookup->lazyIndexHint()) {
30+
auto filterStr = lookup->queryContext().front().get_filter();
31+
Expression *filter = Expression::decode(qctx()->objPool(), filterStr);
32+
if (filter->kind() != Expression::Kind::kRelEQ && filter->kind() != Expression::Kind::kRelIn) {
33+
return Status::Error("The kind of filter expression is invalid: %s",
34+
filter->toString().c_str());
35+
}
36+
auto relFilter = static_cast<const RelationalExpression *>(filter);
37+
auto right = DCHECK_NOTNULL(relFilter->right());
38+
if (right->kind() != Expression::Kind::kLabel) {
39+
return Status::Error("The kind of expression is not label expression: %s",
40+
right->toString().c_str());
41+
}
42+
const auto &colName = static_cast<const LabelExpression *>(right)->name();
43+
const auto &result = ectx_->getResult(lookup->inputVar());
44+
std::vector<Expression *> ops;
45+
std::unordered_set<Value> unique;
46+
for (auto iter = result.iterRef(); iter->valid(); iter->next()) {
47+
const auto &val = iter->getColumn(colName);
48+
if (!unique.emplace(val).second) continue;
49+
auto constExpr = ConstantExpression::make(objPool, val);
50+
auto leftExpr = relFilter->left()->clone();
51+
auto newRelExpr = RelationalExpression::makeEQ(objPool, leftExpr, constExpr);
52+
ops.push_back(newRelExpr);
53+
}
2354

24-
const auto &ictxs = lookup->queryContext();
55+
if (ops.empty()) {
56+
return finish(ResultBuilder().value(Value(List())).iter(Iterator::Kind::kProp).build());
57+
}
58+
59+
if (ops.size() == 1u) {
60+
NG_RETURN_IF_ERROR(OptimizerUtils::createIndexQueryCtx(ops[0], qctx(), lookup, ictxs));
61+
} else {
62+
auto logExpr = LogicalExpression::makeOr(objPool);
63+
logExpr->setOperands(std::move(ops));
64+
NG_RETURN_IF_ERROR(OptimizerUtils::createIndexQueryCtx(logExpr, qctx(), lookup, ictxs));
65+
}
66+
} else {
67+
ictxs = lookup->queryContext();
68+
}
2569
auto iter = std::find_if(
2670
ictxs.begin(), ictxs.end(), [](auto &ictx) { return !ictx.index_id_ref().is_set(); });
2771
if (ictxs.empty() || iter != ictxs.end()) {

src/graph/optimizer/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
nebula_add_library(
66
optimizer_obj
77
OBJECT
8-
OptimizerUtils.cpp
98
Optimizer.cpp
109
OptGroup.cpp
1110
OptRule.cpp

0 commit comments

Comments
 (0)