MCPcopy Create free account
hub / github.com/apache/cloudberry / create_plan

Function create_plan

src/backend/optimizer/plan/createplan.c:379–441  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

377 * Returns a Plan tree.
378 */
379Plan *
380create_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

Callers 7

make_subplanFunction · 0.85
SS_process_ctesFunction · 0.85
create_minmaxagg_planFunction · 0.85
create_subqueryscan_planFunction · 0.85
create_ctescan_planFunction · 0.85
standard_plannerFunction · 0.85

Calls 3

create_plan_recurseFunction · 0.85
apply_tlist_labelingFunction · 0.85
SS_attach_initplansFunction · 0.85

Tested by

no test coverage detected