Skip to content

Commit

Permalink
Connect two path plan.
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic committed Dec 23, 2021
1 parent ff19428 commit e8a298c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 38 deletions.
84 changes: 46 additions & 38 deletions src/graph/planner/match/MatchClausePlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,44 +130,8 @@ StatusOr<SubPlan> MatchClausePlanner::transform(CypherClauseContextBase* clauseC
nodeInfos, edgeInfos, matchClauseCtx, nodeAliasesSeen, startFromEdge, startIndex, subplan));
NG_RETURN_IF_ERROR(
expand(nodeInfos, edgeInfos, matchClauseCtx, startFromEdge, startIndex, subplan));

std::unordered_set<std::string> intersectedAliases;
std::for_each(
nodeInfos.begin(), nodeInfos.end(), [&intersectedAliases, &nodeAliasesSeen](auto& info) {
if (nodeAliasesSeen.find(info.alias) != nodeAliasesSeen.end()) {
intersectedAliases.emplace(info.alias);
}
});
std::for_each(nodeInfos.begin(), nodeInfos.end(), [&nodeAliasesSeen](auto& info) {
if (!info.anonymous) {
nodeAliasesSeen.emplace(info.alias);
}
});
if (matchClausePlan.root == nullptr) {
matchClausePlan = subplan;
} else {
if (intersectedAliases.empty()) {
matchClausePlan.root =
BiCartesianProduct::make(matchClauseCtx->qctx, matchClausePlan.root, subplan.root);
} else {
// TODO: Actually a natural join would be much easy use.
auto innerJoin =
BiInnerJoin::make(matchClauseCtx->qctx, matchClausePlan.root, subplan.root);
std::vector<Expression*> hashKeys;
std::vector<Expression*> probeKeys;
auto pool = matchClauseCtx->qctx->objPool();
for (auto& alias : intersectedAliases) {
auto* args = ArgumentList::make(pool);
args->addArgument(InputPropertyExpression::make(pool, alias));
auto* expr = FunctionCallExpression::make(pool, "id", args);
hashKeys.emplace_back(expr);
probeKeys.emplace_back(expr->clone());
}
innerJoin->setHashKeys(std::move(hashKeys));
innerJoin->setProbeKeys(std::move(probeKeys));
matchClausePlan.root = innerJoin;
}
}
NG_RETURN_IF_ERROR(
connectPathPlan(nodeInfos, matchClauseCtx, subplan, nodeAliasesSeen, matchClausePlan));
}
NG_RETURN_IF_ERROR(projectColumnsBySymbols(matchClauseCtx, matchClausePlan));
NG_RETURN_IF_ERROR(appendFilterPlan(matchClauseCtx, matchClausePlan));
Expand Down Expand Up @@ -499,5 +463,49 @@ Status MatchClausePlanner::appendFilterPlan(MatchClauseContext* matchClauseCtx,
VLOG(1) << subplan;
return Status::OK();
}

Status MatchClausePlanner::connectPathPlan(const std::vector<NodeInfo>& nodeInfos,
MatchClauseContext* matchClauseCtx,
const SubPlan& subplan,
std::unordered_set<std::string>& nodeAliasesSeen,
SubPlan& matchClausePlan) {
std::unordered_set<std::string> intersectedAliases;
std::for_each(
nodeInfos.begin(), nodeInfos.end(), [&intersectedAliases, &nodeAliasesSeen](auto& info) {
if (nodeAliasesSeen.find(info.alias) != nodeAliasesSeen.end()) {
intersectedAliases.emplace(info.alias);
}
});
std::for_each(nodeInfos.begin(), nodeInfos.end(), [&nodeAliasesSeen](auto& info) {
if (!info.anonymous) {
nodeAliasesSeen.emplace(info.alias);
}
});
if (matchClausePlan.root == nullptr) {
matchClausePlan = subplan;
} else {
if (intersectedAliases.empty()) {
matchClausePlan.root =
BiCartesianProduct::make(matchClauseCtx->qctx, matchClausePlan.root, subplan.root);
} else {
// TODO: Actually a natural join would be much easy use.
auto innerJoin = BiInnerJoin::make(matchClauseCtx->qctx, matchClausePlan.root, subplan.root);
std::vector<Expression*> hashKeys;
std::vector<Expression*> probeKeys;
auto pool = matchClauseCtx->qctx->objPool();
for (auto& alias : intersectedAliases) {
auto* args = ArgumentList::make(pool);
args->addArgument(InputPropertyExpression::make(pool, alias));
auto* expr = FunctionCallExpression::make(pool, "id", args);
hashKeys.emplace_back(expr);
probeKeys.emplace_back(expr->clone());
}
innerJoin->setHashKeys(std::move(hashKeys));
innerJoin->setProbeKeys(std::move(probeKeys));
matchClausePlan.root = innerJoin;
}
}
return Status::OK();
}
} // namespace graph
} // namespace nebula
6 changes: 6 additions & 0 deletions src/graph/planner/match/MatchClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class MatchClausePlanner final : public CypherClausePlanner {

Status appendFilterPlan(MatchClauseContext* matchClauseCtx, SubPlan& subplan);

Status connectPathPlan(const std::vector<NodeInfo>& nodeInfos,
MatchClauseContext* matchClauseCtx,
const SubPlan& subplan,
std::unordered_set<std::string>& nodeAliasesSeen,
SubPlan& matchClausePlan);

private:
Expression* initialExpr_{nullptr};
};
Expand Down

0 comments on commit e8a298c

Please sign in to comment.