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

Comments for planner. #3895

Merged
merged 9 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/graph/planner/Planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,28 @@ struct MatchAndInstantiate {
PlannerInstantiateFunc instantiate;
};

// A planner generates plans for statements.
// For example, we have MatchPlanner that generates plan for Match statement.
// And we have GoPlanner that generates plan for Go statements. Each planner
// will be registered into the plannersMap in the PlannersRegister when the
// graphd service start up.
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
class Planner {
public:
virtual ~Planner() = default;

// Each statement might have many planners that match different situations.
// Each planner should provide two funtions:
// 1. MatchFunc that match the proper situation
// 2. PlannerInstantiateFunc that instantiate the planner
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
static auto& plannersMap() {
static std::unordered_map<Sentence::Kind, std::vector<MatchAndInstantiate>> plannersMap;
return plannersMap;
}

// Generate plans for each statement based on AsrContext.
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
static StatusOr<SubPlan> toPlan(AstContext* astCtx);

// Transform the AstContext to a plan which determined by the implementations.
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
virtual StatusOr<SubPlan> transform(AstContext* astCtx) = 0;

protected:
Expand Down
2 changes: 2 additions & 0 deletions src/graph/planner/match/ArgumentFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace nebula {
namespace graph {
// ArgumentFinder finds if a pattern use a named alias that has already been declared
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
// in former patterns.
class ArgumentFinder final : public StartVidFinder {
public:
static std::unique_ptr<ArgumentFinder> make() {
Expand Down
5 changes: 1 addition & 4 deletions src/graph/planner/match/LabelIndexSeek.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
namespace nebula {
namespace graph {

/*
* The LabelIndexSeek was designed to find if could get the starting vids by tag
* index.
*/
// The LabelIndexSeek finds if a plan could get the starting vids by tag index.
class LabelIndexSeek final : public StartVidFinder {
public:
static std::unique_ptr<LabelIndexSeek> make() {
Expand Down
10 changes: 3 additions & 7 deletions src/graph/planner/match/MatchClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

namespace nebula {
namespace graph {
/*
* The MatchClausePlanner was designed to generate plan for match clause;
*/
// The MatchClausePlanner generates plan for match clause;
class MatchClausePlanner final : public CypherClausePlanner {
public:
MatchClausePlanner() = default;
Expand Down Expand Up @@ -62,10 +60,8 @@ class MatchClausePlanner final : public CypherClausePlanner {
size_t startIndex,
SubPlan& subplan);

/*
* Project all named alias.
* TODO: Might not neccessary
*/
// Project all named alias.
// TODO: Might not neccessary
Status projectColumnsBySymbols(MatchClauseContext* matchClauseCtx, SubPlan& plan);

YieldColumn* buildVertexColumn(MatchClauseContext* matchClauseCtx,
Expand Down
1 change: 1 addition & 0 deletions src/graph/planner/match/MatchPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace nebula {
namespace graph {
// MatchPlanner generates plans for Match statement based on AstContext.
class MatchPlanner final : public Planner {
public:
static std::unique_ptr<MatchPlanner> make() {
Expand Down
4 changes: 1 addition & 3 deletions src/graph/planner/match/OrderByClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

namespace nebula {
namespace graph {
/*
* The OrderByClausePlanner was designed to generate plan for order by clause;
*/
// The OrderByClausePlanner generates plan for order by clause;
class OrderByClausePlanner final : public CypherClausePlanner {
public:
OrderByClausePlanner() = default;
Expand Down
4 changes: 1 addition & 3 deletions src/graph/planner/match/PaginationPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

namespace nebula {
namespace graph {
/*
* The PaginationPlanner was designed to generate subplan for skip/limit clause.
*/
// The PaginationPlanner generate subplan for skip/limit clause.
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
class PaginationPlanner final : public CypherClausePlanner {
public:
PaginationPlanner() = default;
Expand Down
6 changes: 2 additions & 4 deletions src/graph/planner/match/PropIndexSeek.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

namespace nebula {
namespace graph {
/*
* The PropIndexSeek was designed to find if could get starting vids by tag
* props or edge props index.
*/
// The PropIndexSeek finds if a plan could get starting vids by tag
// props or edge props index.
class PropIndexSeek final : public StartVidFinder {
public:
static std::unique_ptr<PropIndexSeek> make() {
Expand Down
4 changes: 1 addition & 3 deletions src/graph/planner/match/ReturnClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

namespace nebula {
namespace graph {
/*
* The ReturnClausePlanner was designed to generated plan for return clause.
*/
// The ReturnClausePlanner generates plan for return clause.
class ReturnClausePlanner final : public CypherClausePlanner {
public:
ReturnClausePlanner() = default;
Expand Down
5 changes: 1 addition & 4 deletions src/graph/planner/match/ScanSeek.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

namespace nebula {
namespace graph {
/*
* The ScanSeek was designed to find if could get the starting vids in
* filter.
*/
// The ScanSeek finds if a plan could get the starting vids in filter.
class ScanSeek final : public StartVidFinder {
public:
static std::unique_ptr<ScanSeek> make() {
Expand Down
5 changes: 1 addition & 4 deletions src/graph/planner/match/SegmentsConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

namespace nebula {
namespace graph {
/**
* The SegmentsConnector was designed to be a util to help connecting the
* plan segment.
*/
// The SegmentsConnector is a util to help connecting the plan segment.
class SegmentsConnector final {
public:
SegmentsConnector() = delete;
Expand Down
25 changes: 25 additions & 0 deletions src/graph/planner/match/StartVidFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ class StartVidFinder;

using StartVidFinderInstantiateFunc = std::function<std::unique_ptr<StartVidFinder>()>;

// A StartVidFinder find a generally good solution for traversing from the vids.
// Currently we have five StartVidFinders:
// 1. VertexIdSeek find if a plan could traverse from a given vid.
// MATCH(n) WHERE id(n) = value RETURN n
//
// 2. ArgumentFinder find if a plan could traverse from some vids that already
// beed traversed.
// MATCH (n)-[]-(l), (l)-[]-(m) return n,l,m
// MATCH (n)-[]-(l) MATCH (l)-[]-(m) return n,l,m
//
// 3. PropIndexSeek find if a plan could traverse from some vids that could be
// read from the property indices.
// MATCH(n:Tag{prop:value}) RETURN n
// MATCH(n:Tag) WHERE n.prop = value RETURN n
//
// 4. LabelIndexSeek find if a plan could traverse from some vids that could be
// read from the label indices.
// MATCH(n: tag) RETURN n
// MATCH(s)-[:edge]->(e) RETURN e
//
// 5. ScanSeek find if a plan could traverse from some vids by scanning.
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
class StartVidFinder {
public:
virtual ~StartVidFinder() = default;
Expand All @@ -26,8 +47,12 @@ class StartVidFinder {

bool match(PatternContext* patternCtx);

// The derived class should implement matchNode if the finder has
// ability to find vids from node pattern.
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
virtual bool matchNode(NodeContext* nodeCtx) = 0;

// The derived class should implement matchEdge if the finder has
// ability to find vids from edge pattern.
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
virtual bool matchEdge(EdgeContext* nodeCtx) = 0;

StatusOr<SubPlan> transform(PatternContext* patternCtx);
Expand Down
4 changes: 1 addition & 3 deletions src/graph/planner/match/UnwindClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

namespace nebula {
namespace graph {
/*
* The UnwindClausePlanner was designed to generate plan for unwind clause
*/
// The UnwindClausePlanner generates plan for unwind clause
class UnwindClausePlanner final : public CypherClausePlanner {
public:
UnwindClausePlanner() = default;
Expand Down
5 changes: 1 addition & 4 deletions src/graph/planner/match/VertexIdSeek.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

namespace nebula {
namespace graph {
/*
* The VertexIdSeek was designed to find if could get the starting vids in
* filter.
*/
// The VertexIdSeek find if a plan could get the starting vids in filters.
class VertexIdSeek final : public StartVidFinder {
public:
static std::unique_ptr<VertexIdSeek> make() {
Expand Down
4 changes: 1 addition & 3 deletions src/graph/planner/match/WhereClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

namespace nebula {
namespace graph {
/*
* The WhereClausePlanner was designed to generate plan for where clause.
*/
// The WhereClausePlanner generates plan for where clause.
class WhereClausePlanner final : public CypherClausePlanner {
public:
explicit WhereClausePlanner(bool needStableFilter = false)
Expand Down
4 changes: 1 addition & 3 deletions src/graph/planner/match/WithClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

namespace nebula {
namespace graph {
/*
* The WithClausePlanner was designed to generate plan for with clause.
*/
// The WithClausePlanner generates plan for with clause.
class WithClausePlanner final : public CypherClausePlanner {
public:
WithClausePlanner() = default;
Expand Down
5 changes: 1 addition & 4 deletions src/graph/planner/match/YieldClausePlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

namespace nebula {
namespace graph {
/*
* The YieldClausePlanner was designed to generate plan for yield clause in
* cypher
*/
// The YieldClausePlanner generates plan for yield clause
class YieldClausePlanner final : public CypherClausePlanner {
public:
YieldClausePlanner() = default;
Expand Down
50 changes: 19 additions & 31 deletions src/graph/planner/ngql/GoPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ Expression* GoPlanner::loopCondition(uint32_t steps, const std::string& var) {
return LogicalExpression::makeAnd(pool, step, earlyEnd);
}

/*
* extract vid and edge's prop from GN
* for joinDst & joinInput
* output colNames {srcProps, edgeProps, kVid, "JOIN_DST_VID"}
*/
// extract vid and edge's prop from GN
// for joinDst & joinInput
// output colNames {srcProps, edgeProps, kVid, "JOIN_DST_VID"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please capitalize the first character and change the verb to third person singular form.
Ref: https://google.github.io/styleguide/cppguide.html#Function_Comments

PlanNode* GoPlanner::extractSrcEdgePropsFromGN(PlanNode* dep, const std::string& input) {
auto& srcEdgePropsExpr = goCtx_->srcEdgePropsExpr;
auto* pool = goCtx_->qctx->objPool();
Expand All @@ -116,11 +114,9 @@ PlanNode* GoPlanner::extractSrcEdgePropsFromGN(PlanNode* dep, const std::string&
return project;
}

/*
* extract vid and dst from GN
* for trackStartVid
* output ColNames {srcVidColName, "TRACK_DST_VID"}
*/
// extract vid and dst from GN
// for trackStartVid
// output ColNames {srcVidColName, "TRACK_DST_VID"}
PlanNode* GoPlanner::extractSrcDstFromGN(PlanNode* dep, const std::string& input) {
auto qctx = goCtx_->qctx;
auto* pool = qctx->objPool();
Expand All @@ -138,11 +134,9 @@ PlanNode* GoPlanner::extractSrcDstFromGN(PlanNode* dep, const std::string& input
return dedup;
}

/*
* extract vid from runTime input
* for joinInput
* output ColNames {runtimeVidName, dstVidColName}
*/
// extract vid from runTime input
// for joinInput
// output ColNames {runtimeVidName, dstVidColName}
PlanNode* GoPlanner::extractVidFromRuntimeInput(PlanNode* dep) {
if (dep == nullptr) {
return dep;
Expand All @@ -166,13 +160,11 @@ PlanNode* GoPlanner::extractVidFromRuntimeInput(PlanNode* dep) {
return dedup;
}

/*
* establish a mapping between the original vId and the expanded destination vId
* during each step of the expansion in the n-step and mton-step scenario
* left: n-1 steps
* right: step n
* output ColNames {runtimeVidName, dstVidColName}
*/
// establish a mapping between the original vId and the expanded destination vId
CPWstatic marked this conversation as resolved.
Show resolved Hide resolved
// during each step of the expansion in the n-step and mton-step scenario
// left: n-1 steps
// right: step n
// output ColNames {runtimeVidName, dstVidColName}
PlanNode* GoPlanner::trackStartVid(PlanNode* left, PlanNode* right) {
auto qctx = goCtx_->qctx;
auto* pool = qctx->objPool();
Expand Down Expand Up @@ -207,10 +199,8 @@ PlanNode* GoPlanner::trackStartVid(PlanNode* left, PlanNode* right) {
return dedup;
}

/*
* output ColNames {srcProps, edgeProps, kVid, "JOIN_DST_VID", "DST_VID",
* dstProps}
*/
// output ColNames {srcProps, edgeProps, kVid, "JOIN_DST_VID", "DST_VID",
// dstProps}
PlanNode* GoPlanner::buildJoinDstPlan(PlanNode* dep) {
auto qctx = goCtx_->qctx;
auto* pool = qctx->objPool();
Expand Down Expand Up @@ -279,11 +269,9 @@ PlanNode* GoPlanner::buildJoinInputPlan(PlanNode* dep) {
return join;
}

/*
* left's colName dstVidColName join right's colName kVid
* left : n-1 steps
* right : last step
*/
// left's colName dstVidColName join right's colName kVid
// left : n-1 steps
// right : last step
PlanNode* GoPlanner::lastStepJoinInput(PlanNode* left, PlanNode* right) {
auto qctx = goCtx_->qctx;
auto* pool = qctx->objPool();
Expand Down
46 changes: 23 additions & 23 deletions src/graph/planner/ngql/PathPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,29 +469,29 @@ PlanNode* PathPlanner::buildEdgePlan(PlanNode* dep, const std::string& input) {
return getEdge;
}

/*
The Plan looks like this:
+--------+---------+
+-->+ PassThrough +<----+
| +------------------+ |
+--------+---------+ +---------+------------+
| Project(Nodes) | |Project(RelationShips)|
+--------+---------+ +---------+------------+
| |
+--------+---------+ +---------+--------+
| Unwind | | Unwind |
+--------+---------+ +---------+--------+
| |
+--------+---------+ +---------+--------+
| GetVertices | | GetEdges |
+--------+---------+ +---------+--------+
| |
+------------+---------------+
|
+--------+---------+
| DataCollect |
+--------+---------+
*/
//
// The Plan looks like this:
// +--------+---------+
// +-->+ PassThrough +<----+
// | +------------------+ |
// +--------+---------+ +---------+------------+
// | Project(Nodes) | |Project(RelationShips)|
// +--------+---------+ +---------+------------+
// | |
// +--------+---------+ +---------+--------+
// | Unwind | | Unwind |
// +--------+---------+ +---------+--------+
// | |
// +--------+---------+ +---------+--------+
// | GetVertices | | GetEdges |
// +--------+---------+ +---------+--------+
// | |
// +------------+---------------+
// |
// +--------+---------+
// | DataCollect |
// +--------+---------+
//
PlanNode* PathPlanner::buildPathProp(PlanNode* dep) {
auto qctx = pathCtx_->qctx;
auto* pt = PassThroughNode::make(qctx, dep);
Expand Down
Loading