* create_minmaxagg_plan * * Create a Result plan for 'best_path' and (recursively) plans * for its subpaths. */
| 2824 | * for its subpaths. |
| 2825 | */ |
| 2826 | static Result * |
| 2827 | create_minmaxagg_plan(PlannerInfo *root, MinMaxAggPath *best_path) |
| 2828 | { |
| 2829 | Result *plan; |
| 2830 | List *tlist; |
| 2831 | ListCell *lc; |
| 2832 | |
| 2833 | /* Prepare an InitPlan for each aggregate's subquery. */ |
| 2834 | foreach(lc, best_path->mmaggregates) |
| 2835 | { |
| 2836 | MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc); |
| 2837 | PlannerInfo *subroot = mminfo->subroot; |
| 2838 | Query *subparse = subroot->parse; |
| 2839 | Plan *plan; |
| 2840 | |
| 2841 | mminfo->path = cdbllize_adjust_init_plan_path(subroot, mminfo->path); |
| 2842 | |
| 2843 | /* |
| 2844 | * Generate the plan for the subquery. We already have a Path, but we |
| 2845 | * have to convert it to a Plan and attach a LIMIT node above it. |
| 2846 | * Since we are entering a different planner context (subroot), |
| 2847 | * recurse to create_plan not create_plan_recurse. |
| 2848 | */ |
| 2849 | plan = create_plan(subroot, mminfo->path, root->curSlice); |
| 2850 | |
| 2851 | /* Decorate the top node of the plan with a Flow node. */ |
| 2852 | plan->flow = cdbpathtoplan_create_flow(root, mminfo->path->locus); |
| 2853 | |
| 2854 | plan = (Plan *) make_limit(plan, |
| 2855 | subparse->limitOffset, |
| 2856 | subparse->limitCount, |
| 2857 | subparse->limitOption, |
| 2858 | 0, NULL, NULL, NULL); |
| 2859 | plan->flow = plan->lefttree->flow; |
| 2860 | |
| 2861 | /* Must apply correct cost/width data to Limit node */ |
| 2862 | plan->startup_cost = mminfo->path->startup_cost; |
| 2863 | plan->total_cost = mminfo->pathcost; |
| 2864 | plan->plan_rows = 1; |
| 2865 | plan->plan_width = mminfo->path->pathtarget->width; |
| 2866 | plan->parallel_aware = false; |
| 2867 | plan->parallel_safe = mminfo->path->parallel_safe; |
| 2868 | |
| 2869 | /* Convert the plan into an InitPlan in the outer query. */ |
| 2870 | SS_make_initplan_from_plan(root, subroot, plan, root->curSlice, mminfo->param, false); |
| 2871 | } |
| 2872 | |
| 2873 | /* Generate the output plan --- basically just a Result */ |
| 2874 | tlist = build_path_tlist(root, &best_path->path); |
| 2875 | |
| 2876 | plan = make_result(tlist, (Node *) best_path->quals, NULL); |
| 2877 | |
| 2878 | copy_generic_path_info(&plan->plan, (Path *) best_path); |
| 2879 | |
| 2880 | /* |
| 2881 | * During setrefs.c, we'll need to replace references to the Agg nodes |
| 2882 | * with InitPlan output params. (We can't just do that locally in the |
| 2883 | * MinMaxAgg node, because path nodes above here may have Agg references |
no test coverage detected