Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca3d14f

Browse files
committed
Tweak set_rel_width() to avoid redundant executions of getrelid().
In very large queries this accounts for a noticeable fraction ofplanning time. Per an example from Greg Stark.
1 parent8073fff commitca3d14f

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

‎src/backend/optimizer/path/costsize.c

Lines changed: 19 additions & 5 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.179 2007/03/27 23:21:09 tgl Exp $
57+
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.180 2007/04/21 02:41:13 tgl Exp $
5858
*
5959
*-------------------------------------------------------------------------
6060
*/
@@ -2357,12 +2357,22 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel)
23572357
{
23582358
int32tuple_width=0;
23592359
ListCell*tllist;
2360+
Oidrel_reloid;
2361+
2362+
/*
2363+
* Usually (perhaps always), all the Vars have the same reloid, so we can
2364+
* save some redundant list-searching by doing getrelid just once.
2365+
*/
2366+
if (rel->relid>0)
2367+
rel_reloid=getrelid(rel->relid,root->parse->rtable);
2368+
else
2369+
rel_reloid=InvalidOid;/* probably can't happen */
23602370

23612371
foreach(tllist,rel->reltargetlist)
23622372
{
23632373
Var*var= (Var*)lfirst(tllist);
23642374
intndx;
2365-
Oidrelid;
2375+
Oidvar_reloid;
23662376
int32item_width;
23672377

23682378
/* For now, punt on whole-row child Vars */
@@ -2383,10 +2393,14 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel)
23832393
continue;
23842394
}
23852395

2386-
relid=getrelid(var->varno,root->parse->rtable);
2387-
if (relid!=InvalidOid)
2396+
if (var->varno==rel->relid)
2397+
var_reloid=rel_reloid;
2398+
else
2399+
var_reloid=getrelid(var->varno,root->parse->rtable);
2400+
2401+
if (var_reloid!=InvalidOid)
23882402
{
2389-
item_width=get_attavgwidth(relid,var->varattno);
2403+
item_width=get_attavgwidth(var_reloid,var->varattno);
23902404
if (item_width>0)
23912405
{
23922406
rel->attr_widths[ndx]=item_width;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp