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

Commit09b07c2

Browse files
committed
Minor performance improvement for SQL-language functions.
Late in the development of commit0dca5d6, I added a step to copythe result tlist we extract from the cached final query, becauseI was afraid that that might not last as long as the JunkFilter thatwe're passing it off to. However, that turns out to cost a noticeablenumber of cycles, and it's really quite unnecessary because theJunkFilter will not examine that tlist after it's been created.(ExecFindJunkAttribute would use it, but we don't use that functionon this JunkFilter.) Hence, remove the copy step. For safety,reset the might-become-dangling jf_targetList pointer to NIL.In passing, remove DR_sqlfunction.cxt, which we don't use anymore;it's confusing because it's not entirely clear which context itought to point at.
1 parentf4ece89 commit09b07c2

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

‎src/backend/executor/functions.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ typedef struct
4545
{
4646
DestReceiverpub;/* publicly-known function pointers */
4747
Tuplestorestate*tstore;/* where to put result tuples */
48-
MemoryContextcxt;/* context containing tstore */
4948
JunkFilter*filter;/* filter to convert tuple type */
5049
}DR_sqlfunction;
5150

@@ -787,12 +786,6 @@ init_execution_state(SQLFunctionCachePtr fcache)
787786
*/
788787
resulttlist=get_sql_fn_result_tlist(plansource->query_list);
789788

790-
/*
791-
* We need to make a copy to ensure that it doesn't disappear
792-
* underneath us due to plancache invalidation.
793-
*/
794-
resulttlist=copyObject(resulttlist);
795-
796789
/*
797790
* If the result is composite, *and* we are returning the whole tuple
798791
* result, we need to insert nulls for any dropped columns. In the
@@ -807,6 +800,17 @@ init_execution_state(SQLFunctionCachePtr fcache)
807800
slot);
808801
else
809802
fcache->junkFilter=ExecInitJunkFilter(resulttlist,slot);
803+
804+
/*
805+
* The resulttlist tree belongs to the plancache and might disappear
806+
* underneath us due to plancache invalidation. While we could
807+
* forestall that by copying it, that'd just be a waste of cycles,
808+
* because the junkfilter doesn't need it anymore. (It'd only be used
809+
* by ExecFindJunkAttribute(), which we don't use here.) To ensure
810+
* there's not a dangling pointer laying about, clear the junkFilter's
811+
* pointer.
812+
*/
813+
fcache->junkFilter->jf_targetList=NIL;
810814
}
811815

812816
if (fcache->func->returnsTuple)
@@ -1245,7 +1249,6 @@ postquel_start(execution_state *es, SQLFunctionCachePtr fcache)
12451249
myState= (DR_sqlfunction*)dest;
12461250
Assert(myState->pub.mydest==DestSQLFunction);
12471251
myState->tstore=fcache->tstore;
1248-
myState->cxt=CurrentMemoryContext;
12491252
myState->filter=fcache->junkFilter;
12501253
}
12511254
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp