| 25 | } |
| 26 | |
| 27 | static OpBase *_CloneOpTree(OpBase *template_current, dict* old_to_new) { |
| 28 | ExecutionPlan *plan_segment; |
| 29 | |
| 30 | dictEntry *entry = HashTableFind(old_to_new, template_current->plan); |
| 31 | if(entry == NULL) { |
| 32 | plan_segment = _ClonePlanInternals(template_current->plan); |
| 33 | HashTableAdd(old_to_new, (void *)template_current->plan, (void *)plan_segment); |
| 34 | } else { |
| 35 | plan_segment = (ExecutionPlan *)HashTableGetVal(entry); |
| 36 | } |
| 37 | |
| 38 | // Temporarily set the thread-local AST to be the one referenced by this ExecutionPlan segment. |
| 39 | QueryCtx_SetAST(plan_segment->ast_segment); |
| 40 | |
| 41 | // Clone the current operation. |
| 42 | OpBase *clone_current = OpBase_Clone(plan_segment, template_current); |
| 43 | if(plan_segment->root == NULL) plan_segment->root = clone_current; |
| 44 | |
| 45 | for(uint i = 0; i < template_current->childCount; i++) { |
| 46 | // Recursively visit and clone the op's children. |
| 47 | OpBase *child_op = _CloneOpTree(template_current->children[i], |
| 48 | old_to_new); |
| 49 | ExecutionPlan_AddOp(clone_current, child_op); |
| 50 | } |
| 51 | |
| 52 | return clone_current; |
| 53 | } |
| 54 | |
| 55 | static ExecutionPlan *_ExecutionPlan_Clone(const ExecutionPlan *template) { |
| 56 | // create mapping from old exec-plans to the ones |
no test coverage detected