sp_cost.per_tuple += plan->startup_cost;
}
+ subplan->disabled_nodes = plan->disabled_nodes;
subplan->startup_cost = sp_cost.startup;
subplan->per_call_cost = sp_cost.per_tuple;
}
/*
* Compute the estimated cost of each subplan assuming num_exec
- * executions, and keep the cheapest one. In event of exact equality of
- * estimates, we prefer the later plan; this is a bit arbitrary, but in
- * current usage it biases us to break ties against fast-start subplans.
+ * executions, and keep the cheapest one. If one subplan has more
+ * disabled nodes than another, choose the one with fewer disabled nodes
+ * regardless of cost; this parallels compare_path_costs. In event of
+ * exact equality of estimates, we prefer the later plan; this is a bit
+ * arbitrary, but in current usage it biases us to break ties against
+ * fast-start subplans.
*/
Assert(asplan->subplans != NIL);
Cost curcost;
curcost = curplan->startup_cost + num_exec * curplan->per_call_cost;
- if (bestplan == NULL || curcost <= bestcost)
+ if (bestplan == NULL ||
+ curplan->disabled_nodes < bestplan->disabled_nodes ||
+ (curplan->disabled_nodes == bestplan->disabled_nodes &&
+ curcost <= bestcost))
{
bestplan = curplan;
bestcost = curcost;
List *parParam; /* indices of input Params from parent plan */
List *args; /* exprs to pass as parParam values */
/* Estimated execution costs: */
+ int disabled_nodes; /* count of disabled nodes in the plan */
Cost startup_cost; /* one-time setup cost */
Cost per_call_cost; /* cost for each subplan evaluation */
} SubPlan;