Skip to content

Commit 2a64931

Browse files
committed
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).
1 parent ab16485 commit 2a64931

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* Portions Copyright (c) 1994, Regents of the University of California
5555
*
5656
* IDENTIFICATION
57-
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.198 2008/10/04 21:56:53 tgl Exp $
57+
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.199 2008/10/17 20:27:24 tgl Exp $
5858
*
5959
*-------------------------------------------------------------------------
6060
*/
@@ -2608,24 +2608,14 @@ set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, Plan *cteplan)
26082608
static void
26092609
set_rel_width(PlannerInfo *root, RelOptInfo *rel)
26102610
{
2611+
Oid reloid = planner_rt_fetch(rel->relid, root)->relid;
26112612
int32 tuple_width = 0;
26122613
ListCell *tllist;
2613-
Oid rel_reloid;
2614-
2615-
/*
2616-
* Usually (perhaps always), all the Vars have the same reloid, so we can
2617-
* save some redundant list-searching by doing getrelid just once.
2618-
*/
2619-
if (rel->relid > 0)
2620-
rel_reloid = getrelid(rel->relid, root->parse->rtable);
2621-
else
2622-
rel_reloid = InvalidOid; /* probably can't happen */
26232614

26242615
foreach(tllist, rel->reltargetlist)
26252616
{
26262617
Var *var = (Var *) lfirst(tllist);
26272618
int ndx;
2628-
Oid var_reloid;
26292619
int32 item_width;
26302620

26312621
/* For now, punt on whole-row child Vars */
@@ -2635,6 +2625,10 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel)
26352625
continue;
26362626
}
26372627

2628+
Assert(var->varno == rel->relid);
2629+
Assert(var->varattno >= rel->min_attr);
2630+
Assert(var->varattno <= rel->max_attr);
2631+
26382632
ndx = var->varattno - rel->min_attr;
26392633

26402634
/*
@@ -2646,14 +2640,9 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel)
26462640
continue;
26472641
}
26482642

2649-
if (var->varno == rel->relid)
2650-
var_reloid = rel_reloid;
2651-
else
2652-
var_reloid = getrelid(var->varno, root->parse->rtable);
2653-
2654-
if (var_reloid != InvalidOid)
2643+
if (reloid != InvalidOid)
26552644
{
2656-
item_width = get_attavgwidth(var_reloid, var->varattno);
2645+
item_width = get_attavgwidth(reloid, var->varattno);
26572646
if (item_width > 0)
26582647
{
26592648
rel->attr_widths[ndx] = item_width;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy