Skip to content

Commit 783cfda

Browse files
committed
refactor and fix error
1 parent c30f87c commit 783cfda

File tree

4 files changed

+29
-47
lines changed

4 files changed

+29
-47
lines changed

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

+9-30
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,21 @@ folly::Future<Status> IndexScanExecutor::indexScan() {
3838
}
3939
const auto &colName = static_cast<const LabelExpression *>(relFilter->right())->name();
4040
const auto &result = ectx_->getResult(lookup->inputVar());
41-
auto iter = result.iterRef();
42-
if (iter->empty()) {
43-
return finish(ResultBuilder().value(Value(List())).iter(Iterator::Kind::kProp).build());
44-
}
45-
46-
Set vals;
47-
if (filter->kind() == Expression::Kind::kRelIn) {
48-
if (iter->size() != 1u) {
49-
return Status::Error("IN expression could not support multi-rows index scan.");
50-
}
51-
const auto &val = iter->getColumn(colName);
52-
if (!val.isList() && !val.isSet()) {
53-
return Status::Error("The values is not list or set in expression: %s",
54-
filter->toString().c_str());
55-
}
56-
if (val.isList()) {
57-
const auto &listVals = val.getList().values;
58-
vals.values.insert(listVals.begin(), listVals.end());
59-
} else {
60-
const auto &setVals = val.getSet().values;
61-
vals.values.insert(setVals.begin(), setVals.end());
62-
}
63-
} else {
64-
vals.values.reserve(iter->size());
65-
for (; iter->valid(); iter->next()) {
66-
vals.values.emplace(iter->getColumn(colName));
67-
}
68-
}
69-
7041
std::vector<Expression *> ops;
71-
for (auto &val : vals.values) {
42+
std::unordered_set<Value> unique;
43+
for (auto iter = result.iterRef(); iter->valid(); iter->next()) {
44+
const auto &val = iter->getColumn(colName);
45+
if (!unique.emplace(val).second) continue;
7246
auto constExpr = ConstantExpression::make(objPool, val);
7347
auto leftExpr = relFilter->left()->clone();
7448
auto newRelExpr = RelationalExpression::makeEQ(objPool, leftExpr, constExpr);
7549
ops.push_back(newRelExpr);
7650
}
51+
52+
if (ops.empty()) {
53+
return finish(ResultBuilder().value(Value(List())).iter(Iterator::Kind::kProp).build());
54+
}
55+
7756
if (ops.size() == 1u) {
7857
NG_RETURN_IF_ERROR(OptimizerUtils::createIndexQueryCtx(ops[0], qctx(), lookup, ictxs));
7958
} else {

src/graph/planner/match/VariablePropIndexSeek.cpp

+15-16
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,31 @@ bool VariablePropIndexSeek::matchNode(NodeContext* nodeCtx) {
3535
if (!whereClause || !whereClause->filter) return false;
3636

3737
auto filter = whereClause->filter;
38-
std::string refVarName, propName;
38+
std::string refVarName;
3939
std::shared_ptr<IndexItem> idxItem;
4040
Expression* indexFilter = nullptr;
4141
if (filter->kind() == Expression::Kind::kLogicalAnd) {
4242
auto logExpr = static_cast<const LogicalExpression*>(filter);
4343
bool found = false;
4444
for (auto op : logExpr->operands()) {
45-
if (getIndexItem(nodeCtx, op, label, nodeInfo.alias, &refVarName, &propName, &idxItem)) {
46-
if (!nodeCtx->aliasesAvailable->count(refVarName)) {
47-
return false;
48-
}
45+
if (getIndexItem(nodeCtx, op, label, nodeInfo.alias, &refVarName, &indexFilter, &idxItem)) {
4946
// TODO(yee): Only select the first index as candidate filter expression and not support
5047
// the combined index
51-
indexFilter = TagPropertyExpression::make(nodeCtx->qctx->objPool(), label, propName);
5248
found = true;
5349
break;
5450
}
5551
}
5652
if (!found) return false;
5753
} else {
58-
if (!getIndexItem(nodeCtx, filter, label, nodeInfo.alias, &refVarName, &propName, &idxItem)) {
54+
if (!getIndexItem(
55+
nodeCtx, filter, label, nodeInfo.alias, &refVarName, &indexFilter, &idxItem)) {
5956
return false;
6057
}
61-
62-
if (!nodeCtx->aliasesAvailable->count(refVarName)) {
63-
return false;
64-
}
65-
66-
indexFilter = TagPropertyExpression::make(nodeCtx->qctx->objPool(), label, propName);
6758
}
6859

60+
if (!nodeCtx->aliasesAvailable->count(refVarName)) {
61+
return false;
62+
}
6963
nodeCtx->refVarName = refVarName;
7064

7165
nodeCtx->scanInfo.filter = DCHECK_NOTNULL(indexFilter);
@@ -105,7 +99,7 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
10599
const std::string& label,
106100
const std::string& alias,
107101
std::string* refVarName,
108-
std::string* propName,
102+
Expression** indexFilter,
109103
std::shared_ptr<IndexItem>* idxItem) {
110104
if (filter->kind() != Expression::Kind::kRelEQ && filter->kind() != Expression::Kind::kRelIn) {
111105
return false;
@@ -117,7 +111,8 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
117111
return false;
118112
}
119113

120-
if (!MatchSolver::extractTagPropName(relInExpr->left(), alias, label, propName)) {
114+
std::string propName;
115+
if (!MatchSolver::extractTagPropName(relInExpr->left(), alias, label, &propName)) {
121116
return false;
122117
}
123118
// TODO(yee): workaround for index selection
@@ -129,7 +124,7 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
129124
auto schemaId = itemPtr->get_schema_id();
130125
if (schemaId.get_tag_id() == nodeCtx->info->tids.back()) {
131126
const auto& fields = itemPtr->get_fields();
132-
if (!fields.empty() && fields.front().get_name() == *propName) {
127+
if (!fields.empty() && fields.front().get_name() == propName) {
133128
idxItemList.push_back(itemPtr);
134129
}
135130
}
@@ -140,6 +135,10 @@ bool VariablePropIndexSeek::getIndexItem(const NodeContext* nodeCtx,
140135
});
141136
*refVarName = static_cast<const LabelExpression*>(right)->name();
142137
*idxItem = idxItemList.front();
138+
auto objPool = nodeCtx->qctx->objPool();
139+
auto tagPropExpr = TagPropertyExpression::make(objPool, label, propName);
140+
*indexFilter =
141+
RelationalExpression::makeKind(objPool, filter->kind(), tagPropExpr, right->clone());
143142
return true;
144143
}
145144

src/graph/planner/match/VariablePropIndexSeek.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class VariablePropIndexSeek final : public StartVidFinder {
3535
const std::string& label,
3636
const std::string& alias,
3737
std::string* refVarName,
38-
std::string* propName,
38+
Expression** indexFilter,
3939
std::shared_ptr<meta::cpp2::IndexItem>* idxItem);
4040
};
4141

0 commit comments

Comments
 (0)