* create_plan * Creates the access plan for a query by recursively processing the * desired tree of pathnodes, starting at the node 'best_path'. For * every pathnode found, we create a corresponding plan node containing * appropriate id, target list, and qualification information. * * The tlists and quals in the plan tree are still in planner format, * ie, Vars still correspond
| 377 | * Returns a Plan tree. |
| 378 | */ |
| 379 | Plan * |
| 380 | create_plan(PlannerInfo *root, Path *best_path, PlanSlice *curSlice) |
| 381 | { |
| 382 | Plan *plan; |
| 383 | |
| 384 | root->curSlice = curSlice; |
| 385 | |
| 386 | /* plan_params should not be in use in current query level */ |
| 387 | Assert(root->plan_params == NIL); |
| 388 | |
| 389 | /* Initialize this module's workspace in PlannerInfo */ |
| 390 | root->curOuterRels = NULL; |
| 391 | root->curOuterParams = NIL; |
| 392 | |
| 393 | /* Recursively process the path tree, demanding the correct tlist result */ |
| 394 | plan = create_plan_recurse(root, best_path, CP_EXACT_TLIST); |
| 395 | |
| 396 | /* |
| 397 | * 'partition_selector_candidates' is a stack, should be empty now |
| 398 | * that we're back from create_plan_recurse(). |
| 399 | */ |
| 400 | Assert(root->partition_selector_candidates == NIL); |
| 401 | |
| 402 | /* |
| 403 | * Make sure the topmost plan node's targetlist exposes the original |
| 404 | * column names and other decorative info. Targetlists generated within |
| 405 | * the planner don't bother with that stuff, but we must have it on the |
| 406 | * top-level tlist seen at execution time. However, ModifyTable plan |
| 407 | * nodes don't have a tlist matching the querytree targetlist. |
| 408 | * |
| 409 | * The ModifyTable might be under a Motion, so peek underneath it. |
| 410 | */ |
| 411 | { |
| 412 | Plan *topplan = plan; |
| 413 | |
| 414 | if (IsA(plan, Motion)) |
| 415 | topplan = plan->lefttree; |
| 416 | |
| 417 | if (!IsA(topplan, ModifyTable)) |
| 418 | apply_tlist_labeling(topplan->targetlist, root->processed_tlist); |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Attach any initPlans created in this query level to the topmost plan |
| 423 | * node. (In principle the initplans could go in any plan node at or |
| 424 | * above where they're referenced, but there seems no reason to put them |
| 425 | * any lower than the topmost node for the query level. Also, see |
| 426 | * comments for SS_finalize_plan before you try to change this.) |
| 427 | */ |
| 428 | SS_attach_initplans(root, plan); |
| 429 | |
| 430 | /* Check we successfully assigned all NestLoopParams to plan nodes */ |
| 431 | if (root->curOuterParams != NIL) |
| 432 | elog(ERROR, "failed to assign all NestLoopParams to plan nodes"); |
| 433 | |
| 434 | /* |
| 435 | * Reset plan_params to ensure param IDs used for nestloop params are not |
| 436 | * re-used later |
no test coverage detected