|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.135 2002/12/14 00:17:55 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.136 2002/12/19 23:25:01 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -264,25 +264,38 @@ subquery_planner(Query *parse, double tuple_fraction) |
264 | 264 |
|
265 | 265 | /* |
266 | 266 | * If any subplans were generated, or if we're inside a subplan, build |
267 | | - *subPlan, extParam and locParam lists for plan nodes. |
| 267 | + *initPlan, extParam and locParam lists for plan nodes. |
268 | 268 | */ |
269 | 269 | if (PlannerPlanId!=saved_planid||PlannerQueryLevel>1) |
270 | 270 | { |
| 271 | +Costinitplan_cost=0; |
| 272 | + |
| 273 | +/* Prepare extParam/locParam data for all nodes in tree */ |
271 | 274 | (void)SS_finalize_plan(plan,parse->rtable); |
272 | 275 |
|
273 | 276 | /* |
274 | | - * At the moment, SS_finalize_plan doesn't handle initPlans and so |
275 | | - * we assign them to the topmost plan node. |
| 277 | + * SS_finalize_plan doesn't handle initPlans, so we have to manually |
| 278 | + * attach them to the topmost plan node, and add their extParams to |
| 279 | + * the topmost node's, too. |
| 280 | + * |
| 281 | + * We also add the total_cost of each initPlan to the startup cost |
| 282 | + * of the top node. This is a conservative overestimate, since in |
| 283 | + * fact each initPlan might be executed later than plan startup, or |
| 284 | + * even not at all. |
276 | 285 | */ |
277 | 286 | plan->initPlan=PlannerInitPlan; |
278 | | -/* Must add the initPlans' extParams to the topmost node's, too */ |
| 287 | + |
279 | 288 | foreach(lst,plan->initPlan) |
280 | 289 | { |
281 | | -SubPlan*subplan= (SubPlan*)lfirst(lst); |
| 290 | +SubPlan*initplan= (SubPlan*)lfirst(lst); |
282 | 291 |
|
283 | 292 | plan->extParam=set_unioni(plan->extParam, |
284 | | -subplan->plan->extParam); |
| 293 | +initplan->plan->extParam); |
| 294 | +initplan_cost+=initplan->plan->total_cost; |
285 | 295 | } |
| 296 | + |
| 297 | +plan->startup_cost+=initplan_cost; |
| 298 | +plan->total_cost+=initplan_cost; |
286 | 299 | } |
287 | 300 |
|
288 | 301 | /* Return to outer subquery context */ |
|