aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/createplan.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-07-21 17:45:07 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-07-21 17:45:07 -0400
commit31c7c642b6419b43eff903285e3da65e3f1901d6 (patch)
treef7c172f0de2d1692289f484e642f85ed01bb40c5 /src/backend/optimizer/plan/createplan.c
parented0af3324702685cce63aed0641b4cbb45816b50 (diff)
downloadpostgresql-31c7c642b6419b43eff903285e3da65e3f1901d6.tar.gz
postgresql-31c7c642b6419b43eff903285e3da65e3f1901d6.zip
Account for SRFs in targetlists in planner rowcount estimates.
We made use of the ROWS estimate for set-returning functions used in FROM, but not for those used in SELECT targetlists; which is a bit of an oversight considering there are common usages that require the latter approach. Improve that. (I had initially thought it might be worth folding this into cost_qual_eval, but after investigation concluded that that wouldn't be very helpful, so just do it separately.) Per complaint from David Johnston. Back-patch to 9.2, but not further, for fear of destabilizing plan choices in existing releases.
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r--src/backend/optimizer/plan/createplan.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 65ad1694b07..414406bb8a1 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -30,6 +30,7 @@
#include "optimizer/placeholder.h"
#include "optimizer/plancat.h"
#include "optimizer/planmain.h"
+#include "optimizer/planner.h"
#include "optimizer/predtest.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/subselect.h"
@@ -4126,8 +4127,8 @@ make_agg(PlannerInfo *root, List *tlist, List *qual,
* anything for Aggref nodes; this is okay since they are really
* comparable to Vars.
*
- * See notes in grouping_planner about why only make_agg, make_windowagg
- * and make_group worry about tlist eval cost.
+ * See notes in add_tlist_costs_to_plan about why only make_agg,
+ * make_windowagg and make_group worry about tlist eval cost.
*/
if (qual)
{
@@ -4136,10 +4137,7 @@ make_agg(PlannerInfo *root, List *tlist, List *qual,
plan->total_cost += qual_cost.startup;
plan->total_cost += qual_cost.per_tuple * plan->plan_rows;
}
- cost_qual_eval(&qual_cost, tlist, root);
- plan->startup_cost += qual_cost.startup;
- plan->total_cost += qual_cost.startup;
- plan->total_cost += qual_cost.per_tuple * plan->plan_rows;
+ add_tlist_costs_to_plan(root, plan, tlist);
plan->qual = qual;
plan->targetlist = tlist;
@@ -4160,7 +4158,6 @@ make_windowagg(PlannerInfo *root, List *tlist,
WindowAgg *node = makeNode(WindowAgg);
Plan *plan = &node->plan;
Path windowagg_path; /* dummy for result of cost_windowagg */
- QualCost qual_cost;
node->winref = winref;
node->partNumCols = partNumCols;
@@ -4185,13 +4182,10 @@ make_windowagg(PlannerInfo *root, List *tlist,
/*
* We also need to account for the cost of evaluation of the tlist.
*
- * See notes in grouping_planner about why only make_agg, make_windowagg
- * and make_group worry about tlist eval cost.
+ * See notes in add_tlist_costs_to_plan about why only make_agg,
+ * make_windowagg and make_group worry about tlist eval cost.
*/
- cost_qual_eval(&qual_cost, tlist, root);
- plan->startup_cost += qual_cost.startup;
- plan->total_cost += qual_cost.startup;
- plan->total_cost += qual_cost.per_tuple * plan->plan_rows;
+ add_tlist_costs_to_plan(root, plan, tlist);
plan->targetlist = tlist;
plan->lefttree = lefttree;
@@ -4242,8 +4236,8 @@ make_group(PlannerInfo *root,
* lower plan level and will only be copied by the Group node. Worth
* fixing?
*
- * See notes in grouping_planner about why only make_agg, make_windowagg
- * and make_group worry about tlist eval cost.
+ * See notes in add_tlist_costs_to_plan about why only make_agg,
+ * make_windowagg and make_group worry about tlist eval cost.
*/
if (qual)
{
@@ -4252,10 +4246,7 @@ make_group(PlannerInfo *root,
plan->total_cost += qual_cost.startup;
plan->total_cost += qual_cost.per_tuple * plan->plan_rows;
}
- cost_qual_eval(&qual_cost, tlist, root);
- plan->startup_cost += qual_cost.startup;
- plan->total_cost += qual_cost.startup;
- plan->total_cost += qual_cost.per_tuple * plan->plan_rows;
+ add_tlist_costs_to_plan(root, plan, tlist);
plan->qual = qual;
plan->targetlist = tlist;