diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-09-16 00:42:53 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-09-16 00:43:52 -0400 |
commit | e6faf910d75027bdce7cd0f2033db4e912592bcc (patch) | |
tree | b5fdc2340cc1cdf27dd473e23a09cb2953b5053c /src/pl/plperl/plperl.c | |
parent | 09e98a3e170ecdeb25a0e1afe81bdbeeeaf21f48 (diff) | |
download | postgresql-e6faf910d75027bdce7cd0f2033db4e912592bcc.tar.gz postgresql-e6faf910d75027bdce7cd0f2033db4e912592bcc.zip |
Redesign the plancache mechanism for more flexibility and efficiency.
Rewrite plancache.c so that a "cached plan" (which is rather a misnomer
at this point) can support generation of custom, parameter-value-dependent
plans, and can make an intelligent choice between using custom plans and
the traditional generic-plan approach. The specific choice algorithm
implemented here can probably be improved in future, but this commit is
all about getting the mechanism in place, not the policy.
In addition, restructure the API to greatly reduce the amount of extraneous
data copying needed. The main compromise needed to make that possible was
to split the initial creation of a CachedPlanSource into two steps. It's
worth noting in particular that SPI_saveplan is now deprecated in favor of
SPI_keepplan, which accomplishes the same end result with zero data
copying, and no need to then spend even more cycles throwing away the
original SPIPlan. The risk of long-term memory leaks while manipulating
SPIPlans has also been greatly reduced. Most of this improvement is based
on use of the recently-added MemoryContextSetParent primitive.
Diffstat (limited to 'src/pl/plperl/plperl.c')
-rw-r--r-- | src/pl/plperl/plperl.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 8b5d4dc1915..784e137976c 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -165,7 +165,7 @@ typedef struct plperl_call_data typedef struct plperl_query_desc { char qname[24]; - void *plan; + SPIPlanPtr plan; int nargs; Oid *argtypes; FmgrInfo *arginfuncs; @@ -2951,7 +2951,7 @@ plperl_spi_query(char *query) PG_TRY(); { - void *plan; + SPIPlanPtr plan; Portal portal; /* Make sure the query is validly encoded */ @@ -3118,7 +3118,7 @@ plperl_spi_prepare(char *query, int argc, SV **argv) plperl_query_desc *qdesc; plperl_query_entry *hash_entry; bool found; - void *plan; + SPIPlanPtr plan; int i; MemoryContext oldcontext = CurrentMemoryContext; @@ -3182,13 +3182,9 @@ plperl_spi_prepare(char *query, int argc, SV **argv) * Save the plan into permanent memory (right now it's in the * SPI procCxt, which will go away at function end). ************************************************************/ - qdesc->plan = SPI_saveplan(plan); - if (qdesc->plan == NULL) - elog(ERROR, "SPI_saveplan() failed: %s", - SPI_result_code_string(SPI_result)); - - /* Release the procCxt copy to avoid within-function memory leak */ - SPI_freeplan(plan); + if (SPI_keepplan(plan)) + elog(ERROR, "SPI_keepplan() failed"); + qdesc->plan = plan; /* Commit the inner transaction, return to outer xact context */ ReleaseCurrentSubTransaction(); @@ -3516,7 +3512,7 @@ plperl_spi_query_prepared(char *query, int argc, SV **argv) void plperl_spi_freeplan(char *query) { - void *plan; + SPIPlanPtr plan; plperl_query_desc *qdesc; plperl_query_entry *hash_entry; |