* SS_identify_outer_params - identify the Params available from outer levels * * This must be run after SS_replace_correlation_vars and SS_process_sublinks * processing is complete in a given query level as well as all of its * descendant levels (which means it's most practical to do it at the end of * processing the query level). We compute the set of paramIds that outer * levels will make
| 2512 | * plan->extParam and plan->allParam - attach params to top of the plan |
| 2513 | */ |
| 2514 | void |
| 2515 | SS_identify_outer_params(PlannerInfo *root) |
| 2516 | { |
| 2517 | Bitmapset *outer_params; |
| 2518 | PlannerInfo *proot; |
| 2519 | ListCell *l; |
| 2520 | |
| 2521 | /* |
| 2522 | * If no parameters have been assigned anywhere in the tree, we certainly |
| 2523 | * don't need to do anything here. |
| 2524 | */ |
| 2525 | if (root->glob->paramExecTypes == NIL) |
| 2526 | return; |
| 2527 | |
| 2528 | /* |
| 2529 | * Scan all query levels above this one to see which parameters are due to |
| 2530 | * be available from them, either because lower query levels have |
| 2531 | * requested them (via plan_params) or because they will be available from |
| 2532 | * initPlans of those levels. |
| 2533 | */ |
| 2534 | outer_params = NULL; |
| 2535 | for (proot = root->parent_root; proot != NULL; proot = proot->parent_root) |
| 2536 | { |
| 2537 | /* Include ordinary Var/PHV/Aggref/GroupingFunc params */ |
| 2538 | foreach(l, proot->plan_params) |
| 2539 | { |
| 2540 | PlannerParamItem *pitem = (PlannerParamItem *) lfirst(l); |
| 2541 | |
| 2542 | outer_params = bms_add_member(outer_params, pitem->paramId); |
| 2543 | } |
| 2544 | /* Include any outputs of outer-level initPlans */ |
| 2545 | foreach(l, proot->init_plans) |
| 2546 | { |
| 2547 | SubPlan *initsubplan = (SubPlan *) lfirst(l); |
| 2548 | ListCell *l2; |
| 2549 | |
| 2550 | foreach(l2, initsubplan->setParam) |
| 2551 | { |
| 2552 | outer_params = bms_add_member(outer_params, lfirst_int(l2)); |
| 2553 | } |
| 2554 | } |
| 2555 | /* Include worktable ID, if a recursive query is being planned */ |
| 2556 | if (proot->wt_param_id >= 0) |
| 2557 | outer_params = bms_add_member(outer_params, proot->wt_param_id); |
| 2558 | } |
| 2559 | root->outer_params = outer_params; |
| 2560 | } |
| 2561 | |
| 2562 | /* |
| 2563 | * SS_charge_for_initplans - account for initplans in Path costs & parallelism |
no test coverage detected