summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/costsize.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/path/costsize.c')
-rw-r--r--src/backend/optimizer/path/costsize.c88
1 files changed, 50 insertions, 38 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index fa580cf14e..ba33da829a 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -54,7 +54,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.199 2008/10/17 20:27:24 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.200 2008/10/21 20:42:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -69,6 +69,7 @@
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/pathnode.h"
+#include "optimizer/placeholder.h"
#include "optimizer/planmain.h"
#include "parser/parsetree.h"
#include "utils/lsyscache.h"
@@ -2610,55 +2611,66 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel)
{
Oid reloid = planner_rt_fetch(rel->relid, root)->relid;
int32 tuple_width = 0;
- ListCell *tllist;
+ ListCell *lc;
- foreach(tllist, rel->reltargetlist)
+ foreach(lc, rel->reltargetlist)
{
- Var *var = (Var *) lfirst(tllist);
- int ndx;
- int32 item_width;
+ Node *node = (Node *) lfirst(lc);
- /* For now, punt on whole-row child Vars */
- if (!IsA(var, Var))
+ if (IsA(node, Var))
{
- tuple_width += 32; /* arbitrary */
- continue;
- }
-
- Assert(var->varno == rel->relid);
- Assert(var->varattno >= rel->min_attr);
- Assert(var->varattno <= rel->max_attr);
+ Var *var = (Var *) node;
+ int ndx;
+ int32 item_width;
- ndx = var->varattno - rel->min_attr;
+ Assert(var->varno == rel->relid);
+ Assert(var->varattno >= rel->min_attr);
+ Assert(var->varattno <= rel->max_attr);
- /*
- * The width probably hasn't been cached yet, but may as well check
- */
- if (rel->attr_widths[ndx] > 0)
- {
- tuple_width += rel->attr_widths[ndx];
- continue;
- }
+ ndx = var->varattno - rel->min_attr;
- if (reloid != InvalidOid)
- {
- item_width = get_attavgwidth(reloid, var->varattno);
- if (item_width > 0)
+ /*
+ * The width probably hasn't been cached yet, but may as well check
+ */
+ if (rel->attr_widths[ndx] > 0)
{
- rel->attr_widths[ndx] = item_width;
- tuple_width += item_width;
+ tuple_width += rel->attr_widths[ndx];
continue;
}
+
+ /* Try to get column width from statistics */
+ if (reloid != InvalidOid)
+ {
+ item_width = get_attavgwidth(reloid, var->varattno);
+ if (item_width > 0)
+ {
+ rel->attr_widths[ndx] = item_width;
+ tuple_width += item_width;
+ continue;
+ }
+ }
+
+ /*
+ * Not a plain relation, or can't find statistics for it. Estimate
+ * using just the type info.
+ */
+ item_width = get_typavgwidth(var->vartype, var->vartypmod);
+ Assert(item_width > 0);
+ rel->attr_widths[ndx] = item_width;
+ tuple_width += item_width;
}
+ else if (IsA(node, PlaceHolderVar))
+ {
+ PlaceHolderVar *phv = (PlaceHolderVar *) node;
+ PlaceHolderInfo *phinfo = find_placeholder_info(root, phv);
- /*
- * Not a plain relation, or can't find statistics for it. Estimate
- * using just the type info.
- */
- item_width = get_typavgwidth(var->vartype, var->vartypmod);
- Assert(item_width > 0);
- rel->attr_widths[ndx] = item_width;
- tuple_width += item_width;
+ tuple_width += phinfo->ph_width;
+ }
+ else
+ {
+ /* For now, punt on whole-row child Vars */
+ tuple_width += 32; /* arbitrary */
+ }
}
Assert(tuple_width >= 0);
rel->width = tuple_width;