| 348 | } |
| 349 | |
| 350 | ExecutionPlan *ExecutionPlan_FromTLS_AST(void) { |
| 351 | AST *ast = QueryCtx_GetAST(); |
| 352 | |
| 353 | // handle UNION if there are any |
| 354 | bool union_query = AST_ContainsClause(ast, CYPHER_AST_UNION); |
| 355 | if(union_query) return _ExecutionPlan_UnionPlans(ast); |
| 356 | |
| 357 | // execution plans are created in 1 or more segments |
| 358 | ExecutionPlan **segments = _process_segments(ast); |
| 359 | ASSERT(segments != NULL); |
| 360 | uint segment_count = array_len(segments); |
| 361 | ASSERT(segment_count > 0); |
| 362 | |
| 363 | // connect all segments into a single ExecutionPlan |
| 364 | ExecutionPlan *plan = _tie_segments(segments, segment_count); |
| 365 | |
| 366 | // the root operation is OpResults only if the query culminates in a RETURN |
| 367 | // or CALL clause |
| 368 | _implicit_result(plan); |
| 369 | |
| 370 | // clean up |
| 371 | array_free(segments); |
| 372 | |
| 373 | return plan; |
| 374 | } |
| 375 | |
| 376 | void ExecutionPlan_PreparePlan(ExecutionPlan *plan) { |
| 377 | // Plan should be prepared only once. |