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

added id seek clone #977

Merged
merged 7 commits into from
Mar 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/execution_plan/ops/op_node_by_id_seek.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static OpResult NodeByIdSeekInit(OpBase *opBase);
static Record NodeByIdSeekConsume(OpBase *opBase);
static Record NodeByIdSeekConsumeFromChild(OpBase *opBase);
static OpResult NodeByIdSeekReset(OpBase *opBase);
static OpBase *NodeByIdSeekClone(const ExecutionPlan *plan, const OpBase *opBase);
static void NodeByIdSeekFree(OpBase *opBase);

static inline int NodeByIdSeekToString(const OpBase *ctx, char *buf, uint buf_len) {
Expand All @@ -35,22 +36,27 @@ OpBase *NewNodeByIdSeekOp(const ExecutionPlan *plan, const QGNode *n, UnsignedRa
op->child_record = NULL;

op->minId = id_range->include_min ? id_range->min : id_range->min + 1;

// The largest possible entity ID is the same as Graph_RequiredMatrixDim.
NodeID maxId = id_range->include_max ? id_range->max : id_range->max - 1;
op->maxId = MIN(Graph_RequiredMatrixDim(op->g) - 1, maxId);
/* The largest possible entity ID is the same as Graph_RequiredMatrixDim.
* This value will be set on Init, to allow operation clone be independent
* on the current graph size.*/
op->maxId = id_range->include_max ? id_range->max : id_range->max - 1;

op->currentId = op->minId;

OpBase_Init((OpBase *)op, OPType_NODE_BY_ID_SEEK, "NodeByIdSeek", NodeByIdSeekInit,
NodeByIdSeekConsume, NodeByIdSeekReset, NodeByIdSeekToString, NULL, NodeByIdSeekFree, false, plan);
NodeByIdSeekConsume, NodeByIdSeekReset, NodeByIdSeekToString, NodeByIdSeekClone, NodeByIdSeekFree,
false, plan);

op->nodeRecIdx = OpBase_Modifies((OpBase *)op, n->alias);

return (OpBase *)op;
}

static OpResult NodeByIdSeekInit(OpBase *opBase) {
assert(opBase->type == OPType_NODE_BY_ID_SEEK);
NodeByIdSeek *op = (NodeByIdSeek *)opBase;
// The largest possible entity ID is the same as Graph_RequiredMatrixDim.
op->maxId = MIN(Graph_RequiredMatrixDim(op->g) - 1, op->maxId);
if(opBase->childCount > 0) opBase->consume = NodeByIdSeekConsumeFromChild;
return OP_OK;
}
Expand Down Expand Up @@ -130,6 +136,23 @@ static OpResult NodeByIdSeekReset(OpBase *ctx) {
return OP_OK;
}

static OpBase *NodeByIdSeekClone(const ExecutionPlan *plan, const OpBase *opBase) {
assert(opBase->type == OPType_NODE_BY_ID_SEEK);
NodeByIdSeek *op = (NodeByIdSeek *)op;
UnsignedRange range;
range.min = op->minId;
range.max = op->maxId;
/* In order to clone the range set at the original op, the range must be inclusive so the clone will set the exact range as the original.
* During the call to NewNodeByIdSeekOp with the range, the following lines are executed:
* op->minId = id_range->include_min ? id_range->min : id_range->min + 1;
* op->maxId = id_range->include_max ? id_range->max : id_range->max - 1;
* Since the range object min equals to the origin minId, and so is the max equals to the origin maxId, and the range is inclusive
* the clone will set its values to be the same as in the origin. */
range.include_min = true;
range.include_max = true;
Comment on lines +151 to +152
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why do we set include_min and include_max to true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the range is decided in the origin op, so we need to include its min and max

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you point me to where does the range is decided?

return NewNodeByIdSeekOp(plan, op->n, &range);
}

static void NodeByIdSeekFree(OpBase *opBase) {
NodeByIdSeek *op = (NodeByIdSeek *)opBase;
if(op->child_record) {
Expand Down