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

Commita36436e

Browse files
committed
Change fix_scan_expr() to avoid copying the input node tree in the common case
where rtoffset == 0. In that case there is no need to change Var nodes,and since filling in unset opfuncid fields is always safe, scribbling on theinput tree to that extent is not objectionable. This brings the cost of thisoperation back down to what it was in 8.2 for simple queries. Perinvestigation of performance gripe from Guillaume Smet.
1 parent92c0bf0 commita36436e

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 47 additions & 2 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.139 2007/11/15 22:25:15 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.140 2007/11/24 00:39:44 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -73,6 +73,7 @@ static Plan *set_subqueryscan_references(PlannerGlobal *glob,
7373
staticbooltrivial_subqueryscan(SubqueryScan*plan);
7474
staticNode*fix_scan_expr(PlannerGlobal*glob,Node*node,intrtoffset);
7575
staticNode*fix_scan_expr_mutator(Node*node,fix_scan_expr_context*context);
76+
staticboolfix_scan_expr_walker(Node*node,fix_scan_expr_context*context);
7677
staticvoidset_join_references(PlannerGlobal*glob,Join*join,intrtoffset);
7778
staticvoidset_inner_join_references(PlannerGlobal*glob,Plan*inner_plan,
7879
indexed_tlist*outer_itlist);
@@ -625,7 +626,23 @@ fix_scan_expr(PlannerGlobal *glob, Node *node, int rtoffset)
625626

626627
context.glob=glob;
627628
context.rtoffset=rtoffset;
628-
returnfix_scan_expr_mutator(node,&context);
629+
630+
if (rtoffset!=0)
631+
{
632+
returnfix_scan_expr_mutator(node,&context);
633+
}
634+
else
635+
{
636+
/*
637+
* If rtoffset == 0, we don't need to change any Vars, which makes
638+
* it OK to just scribble on the input node tree instead of copying
639+
* (since the only change, filling in any unset opfuncid fields,
640+
* is harmless). This saves just enough cycles to be noticeable on
641+
* trivial queries.
642+
*/
643+
(void)fix_scan_expr_walker(node,&context);
644+
returnnode;
645+
}
629646
}
630647

631648
staticNode*
@@ -687,6 +704,34 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
687704
(void*)context);
688705
}
689706

707+
staticbool
708+
fix_scan_expr_walker(Node*node,fix_scan_expr_context*context)
709+
{
710+
if (node==NULL)
711+
return false;
712+
if (IsA(node,OpExpr))
713+
set_opfuncid((OpExpr*)node);
714+
elseif (IsA(node,DistinctExpr))
715+
set_opfuncid((OpExpr*)node);/* rely on struct equivalence */
716+
elseif (IsA(node,NullIfExpr))
717+
set_opfuncid((OpExpr*)node);/* rely on struct equivalence */
718+
elseif (IsA(node,ScalarArrayOpExpr))
719+
set_sa_opfuncid((ScalarArrayOpExpr*)node);
720+
elseif (IsA(node,Const))
721+
{
722+
Const*con= (Const*)node;
723+
724+
/* Check for regclass reference */
725+
if (con->consttype==REGCLASSOID&& !con->constisnull)
726+
context->glob->relationOids=
727+
lappend_oid(context->glob->relationOids,
728+
DatumGetObjectId(con->constvalue));
729+
return false;
730+
}
731+
returnexpression_tree_walker(node,fix_scan_expr_walker,
732+
(void*)context);
733+
}
734+
690735
/*
691736
* set_join_references
692737
* Modify the target list and quals of a join node to reference its

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp