|
7 | 7 | * Portions Copyright (c) 1994, Regents of the University of California
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.147 2009/03/10 22:09:26 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.148 2009/04/05 19:59:40 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -412,8 +412,8 @@ build_subplan(PlannerInfo *root, Plan *plan, List *rtable,
|
412 | 412 | int paramid;
|
413 | 413 |
|
414 | 414 | /*
|
415 |
| - * Initialize the SubPlan node. Note plan_id isn't set till further down, |
416 |
| - * likewise the cost fields. |
| 415 | + * Initialize the SubPlan node. Note plan_id, plan_name, and cost fields |
| 416 | + * are set further down. |
417 | 417 | */
|
418 | 418 | splan = makeNode(SubPlan);
|
419 | 419 | splan->subLinkType = subLinkType;
|
@@ -606,6 +606,30 @@ build_subplan(PlannerInfo *root, Plan *plan, List *rtable,
|
606 | 606 | root->glob->rewindPlanIDs = bms_add_member(root->glob->rewindPlanIDs,
|
607 | 607 | splan->plan_id);
|
608 | 608 |
|
| 609 | + /* Label the subplan for EXPLAIN purposes */ |
| 610 | + if (isInitPlan) |
| 611 | + { |
| 612 | + ListCell *lc; |
| 613 | + int offset; |
| 614 | + |
| 615 | + splan->plan_name = palloc(32 + 12 * list_length(splan->setParam)); |
| 616 | + sprintf(splan->plan_name, "InitPlan %d (returns ", splan->plan_id); |
| 617 | + offset = strlen(splan->plan_name); |
| 618 | + foreach(lc, splan->setParam) |
| 619 | + { |
| 620 | + sprintf(splan->plan_name + offset, "$%d%s", |
| 621 | + lfirst_int(lc), |
| 622 | + lnext(lc) ? "," : ""); |
| 623 | + offset += strlen(splan->plan_name + offset); |
| 624 | + } |
| 625 | + sprintf(splan->plan_name + offset, ")"); |
| 626 | + } |
| 627 | + else |
| 628 | + { |
| 629 | + splan->plan_name = palloc(32); |
| 630 | + sprintf(splan->plan_name, "SubPlan %d", splan->plan_id); |
| 631 | + } |
| 632 | + |
609 | 633 | /* Lastly, fill in the cost estimates for use later */
|
610 | 634 | cost_subplan(root, splan, plan);
|
611 | 635 |
|
@@ -875,7 +899,7 @@ SS_process_ctes(PlannerInfo *root)
|
875 | 899 | * Make a SubPlan node for it. This is just enough unlike
|
876 | 900 | * build_subplan that we can't share code.
|
877 | 901 | *
|
878 |
| - * Note plan_id isn't set till further down, likewise the cost fields. |
| 902 | + * Note plan_id, plan_name, and cost fields are set further down. |
879 | 903 | */
|
880 | 904 | splan = makeNode(SubPlan);
|
881 | 905 | splan->subLinkType = CTE_SUBLINK;
|
@@ -931,6 +955,10 @@ SS_process_ctes(PlannerInfo *root)
|
931 | 955 |
|
932 | 956 | root->cte_plan_ids = lappend_int(root->cte_plan_ids, splan->plan_id);
|
933 | 957 |
|
| 958 | + /* Label the subplan for EXPLAIN purposes */ |
| 959 | + splan->plan_name = palloc(4 + strlen(cte->ctename) + 1); |
| 960 | + sprintf(splan->plan_name, "CTE %s", cte->ctename); |
| 961 | + |
934 | 962 | /* Lastly, fill in the cost estimates for use later */
|
935 | 963 | cost_subplan(root, splan, plan);
|
936 | 964 | }
|
@@ -2134,5 +2162,10 @@ SS_make_initplan_from_plan(PlannerInfo *root, Plan *plan,
|
2134 | 2162 | prm = generate_new_param(root, resulttype, resulttypmod);
|
2135 | 2163 | node->setParam = list_make1_int(prm->paramid);
|
2136 | 2164 |
|
| 2165 | + /* Label the subplan for EXPLAIN purposes */ |
| 2166 | + node->plan_name = palloc(64); |
| 2167 | + sprintf(node->plan_name, "InitPlan %d (returns $%d)", |
| 2168 | + node->plan_id, prm->paramid); |
| 2169 | + |
2137 | 2170 | return prm;
|
2138 | 2171 | }
|
0 commit comments