Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8255d09

Browse files
tglsfdcCommitfest Bot
authored and
Commitfest Bot
committed
Minor performance improvement for SQL-language functions.
Late in the development of commit 0dca5d6, I added a step to copy the result tlist we extract from the cached final query, because I was afraid that that might not last as long as the JunkFilter that we're passing it off to. However, that turns out to cost a noticeable number of cycles, and it's really quite unnecessary because the JunkFilter will not examine that tlist after it's been created. (ExecFindJunkAttribute would use it, but we don't use that function on 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 it ought to point at.
1 parent e4b0f86 commit 8255d09

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
DestReceiver pub; /* publicly-known function pointers */
4747
Tuplestorestate *tstore; /* where to put result tuples */
48-
MemoryContext cxt; /* 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)