From 2a64931c4bc76c5e800c3fb1eb5a18dc256899c9 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 17 Oct 2008 20:27:24 +0000 Subject: [PATCH] Salvage a little bit of work from a failed patch: simplify and speed up set_rel_width(). The code had been catering for the possibility of different varnos in the relation targetlist, but this is impossible for a base relation (and if it were possible, putting all the widths in the same RelOptInfo would be wrong anyway). --- src/backend/optimizer/path/costsize.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 7bfc66cac3..fa580cf14e 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.198 2008/10/04 21:56:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.199 2008/10/17 20:27:24 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2608,24 +2608,14 @@ set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, Plan *cteplan) static void set_rel_width(PlannerInfo *root, RelOptInfo *rel) { + Oid reloid = planner_rt_fetch(rel->relid, root)->relid; int32 tuple_width = 0; ListCell *tllist; - Oid rel_reloid; - - /* - * Usually (perhaps always), all the Vars have the same reloid, so we can - * save some redundant list-searching by doing getrelid just once. - */ - if (rel->relid > 0) - rel_reloid = getrelid(rel->relid, root->parse->rtable); - else - rel_reloid = InvalidOid; /* probably can't happen */ foreach(tllist, rel->reltargetlist) { Var *var = (Var *) lfirst(tllist); int ndx; - Oid var_reloid; int32 item_width; /* For now, punt on whole-row child Vars */ @@ -2635,6 +2625,10 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel) continue; } + Assert(var->varno == rel->relid); + Assert(var->varattno >= rel->min_attr); + Assert(var->varattno <= rel->max_attr); + ndx = var->varattno - rel->min_attr; /* @@ -2646,14 +2640,9 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel) continue; } - if (var->varno == rel->relid) - var_reloid = rel_reloid; - else - var_reloid = getrelid(var->varno, root->parse->rtable); - - if (var_reloid != InvalidOid) + if (reloid != InvalidOid) { - item_width = get_attavgwidth(var_reloid, var->varattno); + item_width = get_attavgwidth(reloid, var->varattno); if (item_width > 0) { rel->attr_widths[ndx] = item_width;