Skip to content

Commit 57b82bf

Browse files
committed
Marginal performance hack: use a dedicated routine instead of copyObject
to copy nodes that are known to be Vars during plan reference adjustment. Saves useless memzero operation as well as the big switch in copyObject.
1 parent afaa6b9 commit 57b82bf

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/backend/optimizer/plan/setrefs.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.134 2007/04/06 22:57:20 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.135 2007/04/30 00:16:43 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -565,6 +565,22 @@ trivial_subqueryscan(SubqueryScan *plan)
565565
return true;
566566
}
567567

568+
/*
569+
* copyVar
570+
* Copy a Var node.
571+
*
572+
* fix_scan_expr and friends do this enough times that it's worth having
573+
* a bespoke routine instead of using the generic copyObject() function.
574+
*/
575+
static inline Var *
576+
copyVar(Var *var)
577+
{
578+
Var *newvar = (Var *) palloc(sizeof(Var));
579+
580+
*newvar = *var;
581+
return newvar;
582+
}
583+
568584
/*
569585
* fix_scan_expr
570586
* Do set_plan_references processing on a scan-level expression
@@ -588,7 +604,7 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
588604
return NULL;
589605
if (IsA(node, Var))
590606
{
591-
Var *var = (Var *) copyObject(node);
607+
Var *var = copyVar((Var *) node);
592608

593609
Assert(var->varlevelsup == 0);
594610
/*
@@ -1091,7 +1107,7 @@ search_indexed_tlist_for_var(Var *var, indexed_tlist *itlist,
10911107
if (vinfo->varno == varno && vinfo->varattno == varattno)
10921108
{
10931109
/* Found a match */
1094-
Var *newvar = (Var *) copyObject(var);
1110+
Var *newvar = copyVar(var);
10951111

10961112
newvar->varno = newvarno;
10971113
newvar->varattno = vinfo->resno;
@@ -1213,7 +1229,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
12131229
/* If it's for acceptable_rel, adjust and return it */
12141230
if (var->varno == context->acceptable_rel)
12151231
{
1216-
var = (Var *) copyObject(var);
1232+
var = copyVar(var);
12171233
var->varno += context->rtoffset;
12181234
var->varnoold += context->rtoffset;
12191235
return (Node *) var;

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